Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix page initialisation for using route-based info
  • Loading branch information
lowsky committed Apr 2, 2023
commit 4c40b128e78928713a6ecd6b266c35d00bc69a43
20 changes: 11 additions & 9 deletions pages/next/[userName]/[repoName].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@
import React, { use, Suspense, cache } from 'react';

import { fetchRepoBranchesWithCommitStatusesAndPullRequests, fetchUser, User } from '../../../restinpeace/github';
import { UserRepoFromUrlProvider, useUserRepo } from '../../../components/useUserRepoFromRoute';
import UserRepo from '../../../container/UserRepo';
import RichErrorBoundary from '../../../components/RichErrorBoundary';
import InternalLink from '../../../components/InternalLink';
import { Spinner } from '../../../components/Spinner';
import { RepoType } from '../../../components/Repo';
import { UserRepoFromUrlProvider, useUserRepo } from '../../../components/useUserRepoFromRoute';

function delay(timeout) {
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
}

export default function RestfulPage() {
const { userName, repoName } = useUserRepo();

if (!userName || !repoName) {
// This is not yet supported on the server-side, so we need to skip rendering:
return null;
}
export default function ReactNextDrivenPage() {
return (
<UserRepoFromUrlProvider>
<ReactNextWithUrlContext />
</UserRepoFromUrlProvider>
);
}

function ReactNextWithUrlContext() {
const { userName, repoName } = useUserRepo();
const userData: Promise<User> = fetchUserPromise(userName);
const repoData: Promise<RepoType> = fetchRepoBranches({ userName, repoName });
return (
<UserRepoFromUrlProvider>
<RichErrorBoundary>
<InternalLink href={'/restful'}>back to repos</InternalLink>
<InternalLink href={'/next'}>back to repos</InternalLink>
<Suspense fallback={<Spinner />}>
<ReactNext userData={userData} repoData={repoData} />
</Suspense>
Expand Down