refactor: cache is rundown aware

This commit is contained in:
Carlos Valente
2026-04-04 14:58:58 +02:00
committed by GitHub
parent 3022ec2acd
commit 8c14c330f5
7 changed files with 253 additions and 85 deletions
@@ -1,8 +1,13 @@
import { useQueryClient } from '@tanstack/react-query';
import { AuthenticationStatus, CustomFields, ProjectRundowns } from 'ontime-types';
import { AuthenticationStatus, CustomFields, ProjectRundowns, ProjectRundownsList } from 'ontime-types';
import { ImportMap } from 'ontime-utils';
import { CUSTOM_FIELDS, RUNDOWN } from '../../../../../common/api/constants';
import {
CURRENT_RUNDOWN_QUERY_KEY,
CUSTOM_FIELDS,
PROJECT_RUNDOWNS,
getRundownQueryKey,
} from '../../../../../common/api/constants';
import { patchData } from '../../../../../common/api/db';
import {
previewRundown,
@@ -81,9 +86,10 @@ export default function useGoogleSheet() {
await patchData({ rundowns, customFields });
// we are unable to optimistically set the rundown since we need
// it to be normalised
await queryClient.invalidateQueries({
queryKey: [RUNDOWN, CUSTOM_FIELDS],
});
const loadedRundownId = queryClient.getQueryData<ProjectRundownsList>(PROJECT_RUNDOWNS)?.loaded;
const rundownQueryKey = loadedRundownId ? getRundownQueryKey(loadedRundownId) : CURRENT_RUNDOWN_QUERY_KEY;
await queryClient.invalidateQueries({ queryKey: rundownQueryKey });
await queryClient.invalidateQueries({ queryKey: CUSTOM_FIELDS });
} catch (error) {
patchStepData({ pullPush: { available: true, error: maybeAxiosError(error) } });
}