From df55b0bf8d706e79d1caefbf55a6f6349d064f97 Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Fri, 16 May 2025 20:03:06 +0200 Subject: [PATCH] refactor: change network mode defaults --- apps/client/src/common/api/rundown.ts | 16 +++++++++++++++- apps/client/src/common/hooks/useEntryAction.ts | 14 ++------------ apps/client/src/common/queryClient.ts | 11 +++++++++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/apps/client/src/common/api/rundown.ts b/apps/client/src/common/api/rundown.ts index aa7ff1c00..ef9fd8ca3 100644 --- a/apps/client/src/common/api/rundown.ts +++ b/apps/client/src/common/api/rundown.ts @@ -83,10 +83,24 @@ export async function requestEventSwap(data: SwapEntry): Promise> { +export async function requestApplyDelay(delayId: EntryId): Promise> { return axios.patch(`${rundownPath}/applydelay/${delayId}`); } +/** + * HTTP request for dissolving of a block + */ +export async function requestDissolveBlock(blockId: EntryId): Promise> { + return axios.post(`${rundownPath}/dissolve/${blockId}`); +} + +/** + * HTTP request for grouping a list of entries into a block + */ +export async function requestGroupEntries(entryIds: EntryId[]): Promise> { + return axios.post(`${rundownPath}/group`, { data: { ids: entryIds } }); +} + /** * HTTP request to delete entries */ diff --git a/apps/client/src/common/hooks/useEntryAction.ts b/apps/client/src/common/hooks/useEntryAction.ts index 22ef50a11..7b9a96e97 100644 --- a/apps/client/src/common/hooks/useEntryAction.ts +++ b/apps/client/src/common/hooks/useEntryAction.ts @@ -75,10 +75,7 @@ export const useEntryActions = () => { const _addEntryMutation = useMutation({ // TODO(v4): optimistic create entry mutationFn: postAddEntry, - onSettled: () => { - queryClient.invalidateQueries({ queryKey: RUNDOWN }); - }, - networkMode: 'always', + onSettled: () => queryClient.invalidateQueries({ queryKey: RUNDOWN }), }); /** @@ -207,7 +204,6 @@ export const useEntryActions = () => { onSettled: async () => { await queryClient.invalidateQueries({ queryKey: RUNDOWN }); }, - networkMode: 'always', }); /** @@ -372,7 +368,6 @@ export const useEntryActions = () => { onError: (_error, _newEvent, context) => { queryClient.setQueryData(RUNDOWN, context?.previousRundown); }, - networkMode: 'always', }); const batchUpdateEvents = useCallback( @@ -427,7 +422,6 @@ export const useEntryActions = () => { onSettled: () => { queryClient.invalidateQueries({ queryKey: RUNDOWN }); }, - networkMode: 'always', }); /** @@ -481,7 +475,6 @@ export const useEntryActions = () => { onSettled: () => { queryClient.invalidateQueries({ queryKey: RUNDOWN }); }, - networkMode: 'always', }); /** @@ -505,14 +498,13 @@ export const useEntryActions = () => { onSettled: () => { queryClient.invalidateQueries({ queryKey: RUNDOWN }); }, - networkMode: 'always', }); /** * Applies a given delay */ const applyDelay = useCallback( - async (delayEventId: string) => { + async (delayEventId: EntryId) => { try { await _applyDelayMutation.mutateAsync(delayEventId); } catch (error) { @@ -562,7 +554,6 @@ export const useEntryActions = () => { onSettled: () => { queryClient.invalidateQueries({ queryKey: RUNDOWN }); }, - networkMode: 'always', }); /** @@ -634,7 +625,6 @@ export const useEntryActions = () => { onSettled: () => { queryClient.invalidateQueries({ queryKey: RUNDOWN }); }, - networkMode: 'always', }); /** diff --git a/apps/client/src/common/queryClient.ts b/apps/client/src/common/queryClient.ts index 7da808d11..c391abdfb 100644 --- a/apps/client/src/common/queryClient.ts +++ b/apps/client/src/common/queryClient.ts @@ -1,9 +1,20 @@ import { QueryClient } from '@tanstack/react-query'; +import { isOntimeCloud } from '../externals'; + export const ontimeQueryClient = new QueryClient({ defaultOptions: { queries: { gcTime: 1000 * 60 * 10, // 10 min }, + mutations: { + /** + * React Query detects whether the client is online + * However, web access is not required for the clients when deployed locally + * - use 'always' for clients that may be online + * - use 'online' for clients that are connected to the cloud + */ + networkMode: isOntimeCloud ? 'online' : 'always', + }, }, });