From cd2e6d152b2ed30ffb3d43d6d71534614d80b1c5 Mon Sep 17 00:00:00 2001 From: sahil Date: Fri, 20 Mar 2026 11:34:01 +0500 Subject: [PATCH] mobile: add close button in editor all tab bottom sheet #6059 Signed-off-by: Sahil Aslam --- .../components/sheets/editor-tabs/index.tsx | 30 ++++++++++++------- .../screens/editor/tiptap/use-tab-store.ts | 24 +++++++++++++-- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/apps/mobile/app/components/sheets/editor-tabs/index.tsx b/apps/mobile/app/components/sheets/editor-tabs/index.tsx index f16e05dc3..26f13b002 100644 --- a/apps/mobile/app/components/sheets/editor-tabs/index.tsx +++ b/apps/mobile/app/components/sheets/editor-tabs/index.tsx @@ -33,11 +33,11 @@ import { editorController } from "../../../screens/editor/tiptap/utils"; import { eSendEvent, presentSheet } from "../../../services/event-manager"; import { eUnlockNote } from "../../../utils/events"; import { AppFontSize } from "../../../utils/size"; +import { DefaultAppStyles } from "../../../utils/styles"; import { IconButton } from "../../ui/icon-button"; import { Pressable } from "../../ui/pressable"; import Heading from "../../ui/typography/heading"; import Paragraph from "../../ui/typography/paragraph"; -import { DefaultAppStyles } from "../../../utils/styles"; const TabItemComponent = (props: { tab: TabItem; @@ -225,14 +225,24 @@ export default function EditorTabs({ }} > {strings.tabs()} - { - useTabStore.getState().newTab(); - close?.(); - }} - name="plus" - color={colors.primary.accent} - /> + + { + useTabStore.getState().clearTabs(); + close?.(); + }} + name="close" + color={colors.primary.icon} + /> + { + useTabStore.getState().newTab(); + close?.(); + }} + name="plus" + color={colors.primary.accent} + /> + { presentSheet({ component: (ref, close, update) => }); -}; +}; \ No newline at end of file diff --git a/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts b/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts index bb18dca5b..25783af83 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts @@ -187,6 +187,7 @@ export type TabStore = { focusEmptyTab: () => void; getCurrentNoteId: () => string | undefined; getTab: (tabId: string) => TabItem | undefined; + clearTabs: () => void; newTabSession: ( id: string, options?: Omit, "id"> @@ -255,7 +256,7 @@ export const useTabStore = create( const sessionId = oldSessionId && - tabSessionHistory.currentSessionId(tabId) === oldSessionId + tabSessionHistory.currentSessionId(tabId) === oldSessionId ? oldSessionId : tabSessionHistory.add(tabId, oldSessionId); @@ -386,7 +387,7 @@ export const useTabStore = create( focusPreviewTab: ( noteId: string, options: Omit, "id" | "noteId"> - ) => {}, + ) => { }, removeTab: (id: string) => { const index = get().tabs.findIndex((t) => t.id === id); @@ -482,6 +483,25 @@ export const useTabStore = create( }, getTab: (tabId) => { return get().tabs.find((t) => t.id === tabId); + }, + clearTabs: () => { + const tabs = get().tabs; + tabs.forEach((tab) => { + const tabSessions = tabSessionHistory.getTabHistory(tab.id); + tabSessions.back.forEach((id) => TabSessionStorage.remove(id)); + tabSessions.forward.forEach((id) => TabSessionStorage.remove(id)); + tabSessionHistory.clearStackForTab(tab.id); + }); + + const id = getId(); + set({ + tabs: [{ id: id }], + currentTab: id + }); + history.history = [id]; + get().newTabSession(id); + get().focusTab(id); + syncTabs(); } }), {