Skip to content

Commit

Permalink
Try rediriving the tsPageUrl from the router
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansick committed Mar 28, 2024
1 parent 901459c commit a917276
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a917276

Please sign in to comment.