-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithubRepositoryLink.tsx
More file actions
25 lines (21 loc) · 1.04 KB
/
GithubRepositoryLink.tsx
File metadata and controls
25 lines (21 loc) · 1.04 KB
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
import { useContext, useEffect, useState } from "react";
import { GithubPermalinkContext } from "../config/GithubPermalinkContext";
import { GithubRepositoryLinkDataResponse } from "../config/GithubPermalinkContext";
import { GithubRepositoryLinkBase, GithubRepositoryLinkBaseProps } from "./GithubRepositoryLinkBase";
export type GithubRepositoryLinkProps = Omit<GithubRepositoryLinkBaseProps, "data"> & {
repositoryLink: string;
};
export function GithubRepositoryLink(props: GithubRepositoryLinkProps) {
const { getRepositoryFn, githubToken, onError } = useContext(GithubPermalinkContext);
const [data, setData] = useState<GithubRepositoryLinkDataResponse>({ status: "other-error" });
const { repositoryLink } = props;
useEffect(() => {
getRepositoryFn(repositoryLink, githubToken, onError).then((v) => {
setData(v);
}).catch((err) => {
onError?.(err);
setData({ status: "other-error" });
});
}, [repositoryLink, getRepositoryFn, githubToken, onError]);
return <GithubRepositoryLinkBase {...props} data={data} />;
}