diff --git a/frontend/src/components/CreateProjectModal.tsx b/frontend/src/components/CreateProjectModal.tsx index 49eae1c..9a09db2 100644 --- a/frontend/src/components/CreateProjectModal.tsx +++ b/frontend/src/components/CreateProjectModal.tsx @@ -20,8 +20,11 @@ export default function CreateProjectModal({ onClose }: Props): JSX.Element { mutationFn: (body: { name: string; path: string; repo_url: string | null }) => api.post('/api/projects', body), onSuccess: (project) => { - qc.invalidateQueries({ queryKey: ['projects'] }); + qc.setQueryData(['projects'], (prev) => + prev ? [...prev, project] : [project], + ); setCurrent(project.id); + qc.invalidateQueries({ queryKey: ['projects'] }); onClose(); }, }); diff --git a/frontend/src/hooks/useProjects.ts b/frontend/src/hooks/useProjects.ts index 5585b4b..a841719 100644 --- a/frontend/src/hooks/useProjects.ts +++ b/frontend/src/hooks/useProjects.ts @@ -16,7 +16,7 @@ export function useProjects() { useEffect(() => { const list = query.data; if (!list || list.length === 0) return; - if (!currentId || !list.some((p) => p.id === currentId)) { + if (currentId == null) { setCurrent(list[0].id); } }, [query.data, currentId, setCurrent]);