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, VIEW_SETTINGS,
getRundownQueryKey, getRundownQueryKey,
PROJECT_RUNDOWNS, PROJECT_RUNDOWNS,
PROJECT_LIST,
} from '../api/constants'; } from '../api/constants';
import { invalidateAllCaches } from '../api/utils'; import { invalidateAllCaches } from '../api/utils';
import { ontimeQueryClient } from '../queryClient'; import { ontimeQueryClient } from '../queryClient';
@@ -217,7 +218,7 @@ export const connectSocket = () => {
ontimeQueryClient.invalidateQueries({ queryKey: PROJECT_RUNDOWNS }); ontimeQueryClient.invalidateQueries({ queryKey: PROJECT_RUNDOWNS });
break; break;
case RefetchKey.ProjectFiles: case RefetchKey.ProjectFiles:
ontimeQueryClient.invalidateQueries({ queryKey: PROJECT_RUNDOWNS }); ontimeQueryClient.invalidateQueries({ queryKey: PROJECT_LIST });
break; break;
default: { default: {
target satisfies never; 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 // we know the project is loaded since we force initialisation above
const pathToFile = getPathToProject(currentProjectState.currentProjectName as string); const pathToFile = getPathToProject(currentProjectState.currentProjectName as string);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return { filename: currentProjectState.currentProjectName as string, pathToFile }; 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> { export async function loadDemoProject(): Promise<string> {
populateOntimeLogo(); populateOntimeLogo();
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return createProject(config.demoProject, demoDb); return createProject(config.demoProject, demoDb);
} }
@@ -132,9 +126,6 @@ export async function loadDemoProject(): Promise<string> {
*/ */
async function loadNewProject(): Promise<string> { async function loadNewProject(): Promise<string> {
const emptyProject = makeNewProject(); const emptyProject = makeNewProject();
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return createProject(config.newProject, emptyProject); 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 // and make a new file with the recovered data
const newPath = appendToName(filePath, '(recovered)'); const newPath = appendToName(filePath, '(recovered)');
await dockerSafeRename(filePath, newPath); await dockerSafeRename(filePath, newPath);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return getFileNameFromPath(newPath); 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 // and make a new file with the migrated data
const newPath = appendToName(filePath, '(migrated)'); const newPath = appendToName(filePath, '(migrated)');
await dockerSafeRename(filePath, newPath); await dockerSafeRename(filePath, newPath);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return getFileNameFromPath(newPath); return getFileNameFromPath(newPath);
} }
@@ -219,9 +204,6 @@ export async function initialiseProject(): Promise<string> {
} }
} }
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return loadNewProject(); return loadNewProject();
} }
@@ -253,10 +235,6 @@ export async function loadProjectFile(
} }
const projectName = await loadProject(result.data, parsedFileName, options?.rundownId); const projectName = await loadProject(result.data, parsedFileName, options?.rundownId);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return projectName; return projectName;
} }
@@ -267,9 +245,6 @@ export async function getProjectList(): Promise<ProjectFileListResponse> {
const files = await getProjectFiles(); const files = await getProjectFiles();
const lastLoaded = await getLastLoaded(); const lastLoaded = await getLastLoaded();
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return { return {
files, files,
lastLoadedProject: lastLoaded?.projectName ? removeFileExtension(lastLoaded?.projectName) : '', lastLoadedProject: lastLoaded?.projectName ? removeFileExtension(lastLoaded?.projectName) : '',
@@ -324,10 +299,6 @@ export async function renameProjectFile(originalFile: string, newFilename: strin
const projectData = parseDatabaseModel(fileData); const projectData = parseDatabaseModel(fileData);
const newFileName = await loadProject(projectData.data, newFilename); const newFileName = await loadProject(projectData.data, newFilename);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return newFileName; return newFileName;
} }
@@ -345,10 +316,6 @@ export async function renameProjectFile(originalFile: string, newFilename: strin
export async function createProject(fileName: string, initialData: DatabaseModel): Promise<string> { export async function createProject(fileName: string, initialData: DatabaseModel): Promise<string> {
const fileNameWithExtension = generateUniqueFileName(publicDir.projectsDir, ensureJsonExtension(fileName)); const fileNameWithExtension = generateUniqueFileName(publicDir.projectsDir, ensureJsonExtension(fileName));
await loadProject(initialData, fileNameWithExtension); await loadProject(initialData, fileNameWithExtension);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return fileNameWithExtension; 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> { export async function createProjectWithPatch(fileName: string, initialData: Partial<DatabaseModel>): Promise<string> {
const newProject = makeNewProject(); const newProject = makeNewProject();
const sanitisedData = safeMerge(newProject, initialData); const sanitisedData = safeMerge(newProject, initialData);
setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles);
});
return createProject(fileName, sanitisedData); return createProject(fileName, sanitisedData);
} }
@@ -380,10 +343,10 @@ export async function deleteProjectFile(filename: string) {
throw new Error('Project file not found'); throw new Error('Project file not found');
} }
await deleteFile(projectFilePath);
setImmediate(() => { setImmediate(() => {
sendRefetch(RefetchKey.ProjectFiles); 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; return updatedData;
} }