Skip to content

refactor: poll for git auth updates when creating a workspace #9804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 26, 2023
Prev Previous commit
Next Next commit
quit polling when authenticated
  • Loading branch information
aslilac committed Sep 22, 2023
commit cd75e5c0aabd5e2eed2a4969b96de95bc1e5114c
35 changes: 21 additions & 14 deletions site/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,27 @@ const CreateWorkspacePage: FC = () => {
const [gitAuthPollingState, setGitAuthPollingState] =
useState<GitAuthPollingState>("idle");

const startPollingGitAuth = useCallback(() => {
setGitAuthPollingState("polling");
}, []);

const { data: gitAuth, error } = useQuery(
versionId
? {
...templateVersionGitAuth(versionId),
refetchInterval: gitAuthPollingState === "polling" ? 1000 : false,
}
: { enabled: false },
);

const allSignedIn = gitAuth?.every((it) => it.authenticated);

useEffect(() => {
if (allSignedIn) {
setGitAuthPollingState("idle");
return;
}

if (gitAuthPollingState !== "polling") {
return;
}
Expand All @@ -74,20 +94,7 @@ const CreateWorkspacePage: FC = () => {
return () => {
clearTimeout(quitPolling);
};
}, [gitAuthPollingState]);

const startPollingGitAuth = useCallback(() => {
setGitAuthPollingState("polling");
}, []);

const { data: gitAuth, error } = useQuery(
versionId
? {
...templateVersionGitAuth(versionId),
refetchInterval: gitAuthPollingState === "polling" ? 1000 : false,
}
: { enabled: false },
);
}, [gitAuthPollingState, allSignedIn]);

return (
<>
Expand Down