-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathBuilds.tsx
More file actions
84 lines (69 loc) · 2.32 KB
/
Builds.tsx
File metadata and controls
84 lines (69 loc) · 2.32 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
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
78
79
80
81
82
83
84
import { useState } from "react";
import { useParams } from "react-router-dom";
import { useQuery } from "react-query";
import { useRecoilState } from "recoil";
import { Strip } from "@canonical/react-components";
import SectionNav from "../../components/SectionNav";
import LoggedOut from "./LoggedOut";
import RepoNotConnected from "./RepoNotConnected";
import RepoConnected from "./RepoConnected";
import {
buildLoggedInState,
buildRepoConnectedState,
githubDataState,
} from "../../state/atoms";
import { setPageTitle } from "../../utils";
function Builds(): React.JSX.Element {
const { snapId } = useParams();
const [githubData, setGithubData] = useRecoilState(githubDataState);
const [loggedIn, setLoggedIn] = useRecoilState(buildLoggedInState);
const [repoConnected, setRepoConnected] = useRecoilState(
buildRepoConnectedState,
);
const [autoTriggerBuild, setAutoTriggerBuild] = useState<boolean>(false);
const { isLoading } = useQuery({
queryKey: ["githubData"],
queryFn: async () => {
const response = await fetch(`/api/${snapId}/repo`);
if (!response.ok) {
setGithubData(null);
}
const responseData = await response.json();
const githubData = responseData.data;
setLoggedIn(githubData.github_user !== null);
setRepoConnected(githubData.github_repository !== null);
setGithubData(responseData.data);
return responseData.data;
},
retry: 0,
});
setPageTitle(`Builds for ${snapId}`);
return (
<>
<h1 className="p-heading--4" aria-live="polite">
<a href="/snaps">My snaps</a> / <a href={`/${snapId}`}>{snapId}</a> /
Builds
</h1>
<SectionNav snapName={snapId} activeTab="builds" />
{isLoading && (
<Strip shallow>
<p>
<i className="p-icon--spinner u-animation--spin"></i> Loading{" "}
{snapId} builds data
</p>
</Strip>
)}
{!isLoading && !loggedIn && <LoggedOut />}
{!isLoading && loggedIn && !repoConnected && (
<RepoNotConnected setAutoTriggerBuild={setAutoTriggerBuild} />
)}
{githubData && loggedIn && repoConnected && (
<RepoConnected
autoTriggerBuild={autoTriggerBuild}
setAutoTriggerBuild={setAutoTriggerBuild}
/>
)}
</>
);
}
export default Builds;