fixup! refactor: useSuspenseQuery for project list

This commit is contained in:
alex-arc
2026-07-14 13:34:18 +02:00
parent ffd81d2c07
commit f6e7f3d57a
2 changed files with 4 additions and 43 deletions
+2 -1
View File
@@ -25,6 +25,7 @@ import {
VIEW_SETTINGS,
getRundownQueryKey,
PROJECT_RUNDOWNS,
PROJECT_LIST,
} from '../api/constants';
import { invalidateAllCaches } from '../api/utils';
import { ontimeQueryClient } from '../queryClient';
@@ -217,7 +218,7 @@ export const connectSocket = () => {
ontimeQueryClient.invalidateQueries({ queryKey: PROJECT_RUNDOWNS });
break;
case RefetchKey.ProjectFiles:
ontimeQueryClient.invalidateQueries({ queryKey: PROJECT_RUNDOWNS });
ontimeQueryClient.invalidateQueries({ queryKey: PROJECT_LIST });
break;
default: {
target satisfies never;
@@ -73,9 +73,6 @@ export async function getCurrentProject(): Promise<{ filename: string; pathToFil
// we know the project is loaded since we force initialisation above
const pathToFile = getPathToProject(currentProjectState.currentProjectName as string);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return { filename: currentProjectState.currentProjectName as string, pathToFile };
}
@@ -120,9 +117,6 @@ async function loadProject(projectData: DatabaseModel, fileName: string, rundown
*/
export async function loadDemoProject(): Promise<string> {
populateOntimeLogo();
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return createProject(config.demoProject, demoDb);
}
@@ -132,9 +126,6 @@ export async function loadDemoProject(): Promise<string> {
*/
async function loadNewProject(): Promise<string> {
const emptyProject = makeNewProject();
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return createProject(config.newProject, emptyProject);
}
@@ -155,9 +146,6 @@ async function handleCorruptedFile(filePath: string, fileName: string): Promise<
// and make a new file with the recovered data
const newPath = appendToName(filePath, '(recovered)');
await dockerSafeRename(filePath, newPath);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return getFileNameFromPath(newPath);
}
@@ -178,9 +166,6 @@ async function handleMigratedFile(filePath: string, fileName: string): Promise<s
// and make a new file with the migrated data
const newPath = appendToName(filePath, '(migrated)');
await dockerSafeRename(filePath, newPath);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return getFileNameFromPath(newPath);
}
@@ -219,9 +204,6 @@ export async function initialiseProject(): Promise<string> {
}
}
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return loadNewProject();
}
@@ -253,10 +235,6 @@ export async function loadProjectFile(
}
const projectName = await loadProject(result.data, parsedFileName, options?.rundownId);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return projectName;
}
@@ -267,9 +245,6 @@ export async function getProjectList(): Promise<ProjectFileListResponse> {
const files = await getProjectFiles();
const lastLoaded = await getLastLoaded();
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return {
files,
lastLoadedProject: lastLoaded?.projectName ? removeFileExtension(lastLoaded?.projectName) : '',
@@ -324,10 +299,6 @@ export async function renameProjectFile(originalFile: string, newFilename: strin
const projectData = parseDatabaseModel(fileData);
const newFileName = await loadProject(projectData.data, newFilename);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return newFileName;
}
@@ -345,10 +316,6 @@ export async function renameProjectFile(originalFile: string, newFilename: strin
export async function createProject(fileName: string, initialData: DatabaseModel): Promise<string> {
const fileNameWithExtension = generateUniqueFileName(publicDir.projectsDir, ensureJsonExtension(fileName));
await loadProject(initialData, fileNameWithExtension);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return fileNameWithExtension;
}
@@ -360,10 +327,6 @@ export async function createProject(fileName: string, initialData: DatabaseModel
export async function createProjectWithPatch(fileName: string, initialData: Partial<DatabaseModel>): Promise<string> {
const newProject = makeNewProject();
const sanitisedData = safeMerge(newProject, initialData);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return createProject(fileName, sanitisedData);
}
@@ -380,10 +343,10 @@ export async function deleteProjectFile(filename: string) {
throw new Error('Project file not found');
}
await deleteFile(projectFilePath);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
await deleteFile(projectFilePath);
}
/**
@@ -426,10 +389,7 @@ export async function patchCurrentProject(data: Partial<DatabaseModel>) {
}
}
const updatedData = await getDataProvider().getData();
const updatedData = getDataProvider().getData();
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return updatedData;
}