From dd0dcfc2a2aeb9aef2a014b5367c0d7a4d70d4cc Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Sat, 16 Mar 2024 09:40:35 +0100 Subject: [PATCH] fix: reset focus when deleting selected --- .../client/src/features/rundown/RundownEntry.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/client/src/features/rundown/RundownEntry.tsx b/apps/client/src/features/rundown/RundownEntry.tsx index 9babf3d49..0c58caa0d 100644 --- a/apps/client/src/features/rundown/RundownEntry.tsx +++ b/apps/client/src/features/rundown/RundownEntry.tsx @@ -46,22 +46,24 @@ export default function RundownEntry(props: RundownEntryProps) { } = props; const { emitError } = useEmitLog(); const { addEvent, updateEvent, batchUpdateEvents, deleteEvent, swapEvents } = useEventAction(); - const { cursor } = useAppMode(); + const cursor = useAppMode((state) => state.cursor); + const setCursor = useAppMode((state) => state.setCursor); const { selectedEvents, clearSelectedEvents } = useEventSelection(); + const eventSettings = useEditorSettings((state) => state.eventSettings); + const defaultPublic = eventSettings.defaultPublic; + const startTimeIsLastEnd = eventSettings.startTimeIsLastEnd; + const removeOpenEvent = useCallback(() => { if (selectedEvents.has(data.id)) { clearSelectedEvents(); } + // clear cursor if we are deleting the event that is currently selected if (cursor === data.id) { - // setCursor(null); + setCursor(null); } - }, [cursor, data.id, selectedEvents, clearSelectedEvents]); - - const eventSettings = useEditorSettings((state) => state.eventSettings); - const defaultPublic = eventSettings.defaultPublic; - const startTimeIsLastEnd = eventSettings.startTimeIsLastEnd; + }, [clearSelectedEvents, cursor, data.id, selectedEvents, setCursor]); // Create / delete new events type FieldValue = {