-
Notifications
You must be signed in to change notification settings - Fork 0
/
TheOwnerProfile.tsx
77 lines (75 loc) · 2.36 KB
/
TheOwnerProfile.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* eslint-disable no-underscore-dangle */
import {
useGetRepositoryOwnerWithPinnedItemsQuery,
useGetRepositoryOwnerWithRepositoriesQuery,
useGetProfileReadmeQuery,
Blob,
} from "../../libs/graphql";
import { isUser, isOrganization } from "../../utils/type-guards";
import AppUserProfile from "../AppUserProfile/AppUserProfile";
import AppOrganizationProfile from "../AppOrganizationProfile/AppOrganizationProfile";
export type TheOwnerProfileProps = {
owner: string;
tab: "default" | "repositories";
skipProfileReadme: boolean;
};
export default function TheOwnerProfile({
owner,
tab,
skipProfileReadme,
}: TheOwnerProfileProps): JSX.Element {
const repositoryOwnerDefaultModeResult = useGetRepositoryOwnerWithPinnedItemsQuery(
{
variables: { owner },
skip: tab === "repositories",
}
);
const repositoryOwnerRepositoriesModeResult = useGetRepositoryOwnerWithRepositoriesQuery(
{
variables: { owner },
skip: tab === "default",
}
);
const profileReadmeResult = useGetProfileReadmeQuery({
variables: { owner },
// skip this request for the default tab anyway - or if the getServerSideProps found out there wasn't any profile
skip: tab === "repositories" || skipProfileReadme,
});
return (
<>
<h2>TheOwnerProfile</h2>
{tab === "repositories" &&
isUser(
repositoryOwnerRepositoriesModeResult?.data?.repositoryOwner
) && (
<AppUserProfile
user={repositoryOwnerRepositoriesModeResult?.data?.repositoryOwner}
profileReadme={
(profileReadmeResult?.data?.profileReadme?.object as Blob)?.text
}
mode={tab}
/>
)}
{tab === "default" &&
isUser(repositoryOwnerDefaultModeResult?.data?.repositoryOwner) && (
<AppUserProfile
user={repositoryOwnerDefaultModeResult?.data?.repositoryOwner}
profileReadme={
(profileReadmeResult?.data?.profileReadme?.object as Blob)?.text
}
mode={tab}
/>
)}
{tab === "default" &&
isOrganization(
repositoryOwnerDefaultModeResult?.data?.repositoryOwner
) && (
<AppOrganizationProfile
organization={
repositoryOwnerDefaultModeResult?.data?.repositoryOwner
}
/>
)}
</>
);
}