diff --git a/apps/client/src/common/hooks/useEntryAction.ts b/apps/client/src/common/hooks/useEntryAction.ts index 2f002f952..20346e681 100644 --- a/apps/client/src/common/hooks/useEntryAction.ts +++ b/apps/client/src/common/hooks/useEntryAction.ts @@ -371,19 +371,6 @@ function useEntryActionsForRundown(scopedRundownId: string | undefined) { [getCurrentRundownData, updateEntryMutation], ); - const matchGroupDuration = useCallback(async (eventId: EntryId, groupId: EntryId) => { - const rundown = queryClient.getQueryData(RUNDOWN); - if (!rundown) return; - const group = rundown.entries[groupId]; - if (!group || !isOntimeGroup(group) || group.targetDuration === null) return; - const event = rundown.entries[eventId]; - if (!event || !isOntimeEvent(event)) return; - const durationDiff = group.targetDuration - group.duration; - const newDuration = event.duration + durationDiff; - if (newDuration < 0) return; - updateTimer(eventId, 'duration', String(newDuration / MILLIS_PER_SECOND) + 's', false); - }, []); - /** * Updates time of existing event * @param eventId {EntryId} - id of the event @@ -479,7 +466,28 @@ function useEntryActionsForRundown(scopedRundownId: string | undefined) { return previousEnd; } }, - [getCurrentRundownData, updateEntryMutation, queryClient], + [getCurrentRundownData, updateEntryMutation, queryClient, resolveCurrentRundownQueryKey], + ); + + /** + * Updates time of existing event so it satisfies the group target duration + * @param eventId {EntryId} - id of the event + * @param groupId {EntryId} - id of the enclosing group + */ + const matchGroupDuration = useCallback( + async (eventId: EntryId, groupId: EntryId) => { + const rundown = queryClient.getQueryData(resolveCurrentRundownQueryKey()); + if (!rundown) return; + const group = rundown.entries[groupId]; + if (!group || !isOntimeGroup(group) || group.targetDuration === null) return; + const event = rundown.entries[eventId]; + if (!event || !isOntimeEvent(event)) return; + const durationDiff = group.targetDuration - group.duration; + const newDuration = event.duration + durationDiff; + if (newDuration < 0) return; + updateTimer(eventId, 'duration', String(newDuration / MILLIS_PER_SECOND) + 's', false); + }, + [queryClient, updateTimer, resolveCurrentRundownQueryKey], ); /**