Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 6x 6x 6x 6x 6x 6x 2x 2x 2x 2x 2x 2x 2x 2x 6x 6x | import { useState } from "react";
import { useParams } from "react-router-dom";
import { useQuery } from "react-query";
import { useAtom } from "jotai";
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/buildsState";
import { setPageTitle } from "../../utils";
function Builds(): React.JSX.Element {
const { snapId } = useParams();
const [githubData, setGithubData] = useAtom(githubDataState);
const [loggedIn, setLoggedIn] = useAtom(buildLoggedInState);
const [repoConnected, setRepoConnected] = useAtom(buildRepoConnectedState);
const [autoTriggerBuild, setAutoTriggerBuild] = useState<boolean>(false);
const { isLoading } = useQuery({
queryKey: ["githubData", snapId],
queryFn: async () => {
const response = await fetch(`/api/${snapId}/repo`);
Iif (!response.ok) {
setGithubData(null);
}
const responseData = await response.json();
const githubData = responseData.data;
setLoggedIn(githubData && githubData.github_user !== null);
setRepoConnected(githubData && 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;
|