* hasrun

* better comment (filipe)
This commit is contained in:
Jack Kavanagh
2023-08-18 14:53:24 +02:00
committed by GitHub
parent b9cf954b05
commit bec4e8224f

View File

@@ -76,15 +76,20 @@ export interface RootLoaderData {
organizations: Organization[];
settings: Settings;
}
// NOTE: when getVCS is rewritten to be less spaghetti
// this can be removed, and get team should only run once,
// at app start and whenever the user logs in
// This "workaround" will not work if a user logs out and back in again
let hasRun = false;
export const loader: LoaderFunction = async (): Promise<RootLoaderData> => {
// Load all projects
try {
const vcs = getVCS();
if (vcs && isLoggedIn()) {
if (vcs && isLoggedIn() && !hasRun) {
const teams = await vcs.teams();
const projects = await Promise.all(teams.map(initializeProjectFromTeam));
await database.batchModifyDocs({ upsert: projects });
hasRun = true;
}
} catch {
console.log('Failed to load projects');