Skip to content

Commit

Permalink
Safeguard against multi project with same id opening
Browse files Browse the repository at this point in the history
  • Loading branch information
abrenneke committed Nov 14, 2023
1 parent ccff44b commit 2f0a405
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/app/src/hooks/useLoadProjectWithFileBrowser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSetRecoilState } from 'recoil';
import { loadedProjectState, projectState } from '../state/savedGraphs.js';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { loadedProjectState, openedProjectsState, projectState } from '../state/savedGraphs.js';
import { emptyNodeGraph, getError } from '@ironclad/rivet-core';
import { graphState } from '../state/graph.js';
import { ioProvider } from '../utils/globals.js';
Expand All @@ -15,12 +15,22 @@ export function useLoadProjectWithFileBrowser() {
const setTrivetState = useSetRecoilState(trivetState);
const setStaticData = useSetStaticData();
const setNavigationStack = useSetRecoilState(graphNavigationStackState);
const openedProjects = useRecoilValue(openedProjectsState);

return async () => {
try {
await ioProvider.loadProjectData(({ project, testData, path }) => {
const { data, ...projectData } = project;

if (
Object.values(openedProjects).some((p) => p.fsPath !== path && p.project.metadata.id === project.metadata.id)
) {
toast.error(
`A project with the ID ${project.metadata.id} is already open. Please close that project first to open this one.`,
);
return;
}

setProject(projectData);
setNavigationStack({ stack: [], index: undefined });

Expand Down

0 comments on commit 2f0a405

Please sign in to comment.