From a91727627099285af2fbb3d5483f8c1bf771042c Mon Sep 17 00:00:00 2001 From: Jonathan Sick Date: Thu, 28 Mar 2024 16:33:12 -0400 Subject: [PATCH] Try rediriving the tsPageUrl from the router --- .../TimesSquareGitHubPagePanel.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/squareone/src/components/TimesSquareGitHubPagePanel/TimesSquareGitHubPagePanel.js b/apps/squareone/src/components/TimesSquareGitHubPagePanel/TimesSquareGitHubPagePanel.js index 15af07d6..2ca47314 100644 --- a/apps/squareone/src/components/TimesSquareGitHubPagePanel/TimesSquareGitHubPagePanel.js +++ b/apps/squareone/src/components/TimesSquareGitHubPagePanel/TimesSquareGitHubPagePanel.js @@ -20,7 +20,28 @@ import TimesSquareUrlParametersContext from '../TimesSquareUrlParametersProvider export default function TimesSquareGitHubPagePanel({}) { const { publicRuntimeConfig } = getConfig(); const router = useRouter(); - const { tsPageUrl } = React.useContext(TimesSquareUrlParametersContext); + // const { tsPageUrl } = React.useContext(TimesSquareUrlParametersContext); + const { timesSquareUrl } = publicRuntimeConfig; + + // Get components out of the URL path. Only /github-pr/ pages have owner, + // repo, and commit components in the path. In /github/ pages the owner + // and repo are part of tsSlug. + const { tsSlug, owner = null, repo = null, commit = null } = router.query; + console.log('tsSlug: ', tsSlug); + + // Since the page's path is a [...tsSlug], we need to join the parts of the + // path to get the full slug. This combines the owner, repo, directory, and + // notebook name for regular /github/ pages, or just the directory and + // notebook name for /github-pr/ pages. + const githubSlug = tsSlug ? tsSlug.join('/') : null; + + // Construct the URL for the Times Square API endpoint that gives information + // about the page. GitHub PR pages (github-pr) have different API URLs than + // regular GitHub pages. + const tsPageUrl = router.pathname.startsWith('/times-square/github-pr') + ? `${timesSquareUrl}/v1/github-pr/${owner}/${repo}/${commit}/${githubSlug}` + : `${timesSquareUrl}/v1/github/${githubSlug}`; + const pageData = useTimesSquarePage(tsPageUrl); if (pageData.loading) {