From 637cf914eec10afbd5e8dc0367ff5027cf8ad819 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Tue, 21 Jul 2026 10:25:12 +0500 Subject: [PATCH] mobile: fix app gets stuck after deleting history item on iOS --- .../app/components/note-history/index.tsx | 67 +++++++++++-------- .../app/components/note-history/preview.tsx | 8 ++- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/apps/mobile/app/components/note-history/index.tsx b/apps/mobile/app/components/note-history/index.tsx index 92a3c7c55..c7a9bedf1 100644 --- a/apps/mobile/app/components/note-history/index.tsx +++ b/apps/mobile/app/components/note-history/index.tsx @@ -45,11 +45,13 @@ import { Dialog } from "../dialog"; const HistoryItem = ({ index, items, - note + note, + refresh }: { index: number; items?: VirtualizedGrouping; note: Note; + refresh: () => void; }) => { const [item] = useDBItem(index, "noteHistory", items); const { colors } = useThemeColors(); @@ -60,8 +62,9 @@ const HistoryItem = ({ const _start_time = getFormattedDate(start, "time"); const _end_time = getFormattedDate(end + 60000, "time"); - return `${_start_date} ${_start_time} - ${_end_date === _start_date ? " " : _end_date + " " - }${_end_time}`; + return `${_start_date} ${_start_time} - ${ + _end_date === _start_date ? " " : _end_date + " " + }${_end_time}`; }; const preview = useCallback( @@ -76,12 +79,13 @@ const HistoryItem = ({ }} content={content} note={note} + update={refresh} /> ), context: "note_history" }); }, - [note] + [note, refresh] ); return ( @@ -123,7 +127,7 @@ export default function NoteHistory({ const [_loading, setLoading] = useState(true); const { colors } = useThemeColors(); - useEffect(() => { + const refresh = useCallback(() => { db.noteHistory .get(note.id) .sorted({ @@ -139,11 +143,20 @@ export default function NoteHistory({ }); }, [note.id]); + useEffect(() => { + refresh(); + }, [refresh]); + const renderItem = useCallback( ({ index }: { index: number }) => ( - + ), - [history, note] + [history, note, refresh] ); return ( @@ -156,27 +169,27 @@ export default function NoteHistory({ button={ history?.placeholders.length ? { - title: strings.clearHistory(), - type: "secondary", - onPress: () => { - presentDialog({ - title: strings.clearHistory(), - paragraph: strings.clearHistoryConfirmation(), - positiveText: strings.clear(), - negativeText: strings.cancel(), - positiveType: "errorShade", - context: "local", - positivePress: async () => { - await db.noteHistory.clearSessions(note.id); - fwdRef.current?.hide(); - ToastManager.show({ - heading: strings.historyCleared(), - type: "success" - }); - } - }); + title: strings.clearHistory(), + type: "secondary", + onPress: () => { + presentDialog({ + title: strings.clearHistory(), + paragraph: strings.clearHistoryConfirmation(), + positiveText: strings.clear(), + negativeText: strings.cancel(), + positiveType: "errorShade", + context: "local", + positivePress: async () => { + await db.noteHistory.clearSessions(note.id); + fwdRef.current?.hide(); + ToastManager.show({ + heading: strings.historyCleared(), + type: "success" + }); + } + }); + } } - } : undefined } /> diff --git a/apps/mobile/app/components/note-history/preview.tsx b/apps/mobile/app/components/note-history/preview.tsx index 59f70a029..51911c421 100644 --- a/apps/mobile/app/components/note-history/preview.tsx +++ b/apps/mobile/app/components/note-history/preview.tsx @@ -53,7 +53,8 @@ import { export default function NotePreview({ session, content, - note + note, + update }: { session?: HistorySession & { session: string }; content: @@ -64,6 +65,7 @@ export default function NotePreview({ > | undefined; note: TrashOrItem; + update?: () => void; }) { const { colors } = useThemeColors(); const [locked, setLocked] = useState(false); @@ -120,19 +122,21 @@ export default function NotePreview({ positivePress: async () => { if (isSession) { await db.noteHistory.remove(session.id); + update?.(); eSendEvent(eCloseSheet, "note_history"); Navigation.queueRoutesForUpdate(); } else if (note.type === "trash") { await db.trash.delete(note.id); useTrashStore.getState().refresh(); useSelectionStore.getState().setSelectionMode(); + eSendEvent(eCloseSheet); } ToastManager.show({ heading: isSession ? strings.versionDeleted() : strings.noteDeleted(), type: "success" }); - eSendEvent(eCloseSheet); + return true; }, positiveType: "error" });