Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: pinned tab fixes (#7692)

01zulfid27595cfd986
diff --git a/apps/web/__e2e__/tabs.test.ts b/apps/web/__e2e__/tabs.test.ts
index fbf2a6765..29325abc4 100644
--- a/apps/web/__e2e__/tabs.test.ts
+++ b/apps/web/__e2e__/tabs.test.ts
@@ -379,5 +379,54 @@ test("notes open in multiple tabs should sync title when title is changed", asyn
expect(await notes.editor.getTitle()).toBe("Todo - Today");
});
+test("when active tab is pinned, opening other notes should open existing note tab if present", async ({
+ page
+}) => {
+ const app = new AppModel(page);
+ await app.goto();
+ const notes = await app.goToNotes();
+ const note1 = await notes.createNote({
+ title: "Note 1"
+ });
+ const note2 = await notes.createNote({
+ title: "Note 2"
+ });
+ let tabs = await notes.editor.getTabs();
+ await tabs[0].contextMenu.pin();
+
+ await note1?.click();
+ await notes.editor.waitForLoading();
+ await note2?.click();
+ await notes.editor.waitForLoading();
+ await note1?.click();
+ await notes.editor.waitForLoading();
+
+ tabs = await notes.editor.getTabs();
+ expect(tabs.length).toBe(2);
+ await expect(tabs[1].locator).toHaveClass(/active/);
+ await expect(tabs[1].titleElement).toHaveText("Note 1");
+ await expect(tabs[0].titleElement).toHaveText("Note 2");
+});
+
+test("activating pinned tab after page reload should not open a duplicate tab", async ({
+ page
+}) => {
+ const app = new AppModel(page);
+ await app.goto();
+ const notes = await app.goToNotes();
+ await notes.createNote({
+ title: "Note 1"
+ });
+ let tabs = await notes.editor.getTabs();
+ await tabs[0].contextMenu.pin();
+
+ await page.reload();
+ await notes.waitForList();
+
+ tabs = await notes.editor.getTabs();
+ expect(tabs.length).toBe(1);
+ await expect(tabs[0].locator).toHaveClass(/active/);
+});
+
test.skip("TODO: open a locked note, switch to another note and navigate back", () => {});
test.skip("TODO: open a locked note, switch to another note, unlock the note and navigate back", () => {});
diff --git a/apps/web/src/components/note/index.tsx b/apps/web/src/components/note/index.tsx
index b6a6eeef6..759f52cbe 100644
--- a/apps/web/src/components/note/index.tsx
+++ b/apps/web/src/components/note/index.tsx
@@ -144,7 +144,9 @@ function Note(props: NoteProps) {
}}
context={{ color, locked }}
menuItems={noteMenuItems}
- onClick={() => useEditorStore.getState().openSession(note)}
+ onClick={() =>
+ useEditorStore.getState().openSession(note, { considerPinnedTab: true })
+ }
onMiddleClick={() =>
useEditorStore.getState().openSession(note, { openInNewTab: true })
}
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index cc261a093..284cfcd49 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -659,6 +659,10 @@ class EditorStore extends BaseStore<EditorStore> {
activeBlockId?: string;
silent?: boolean;
openInNewTab?: boolean;
+ /**
+ * Should be true if we want to open a new tab when the active tab is pinned
+ */
+ considerPinnedTab?: boolean;
} = {}
): Promise<void> => {
const {
@@ -675,9 +679,12 @@ class EditorStore extends BaseStore<EditorStore> {
const noteId = typeof noteOrId === "string" ? noteOrId : noteOrId.id;
const oldTabForNote = options.force ? null : getTabsForNote(noteId).at(0);
const activeTab = getActiveTab();
+ const isReactivatingTab =
+ options.force && getTabsForNote(noteId).some((t) => t.id === activeTabId);
const tabId =
// if a tab is pinned then always open a new tab.
- options.openInNewTab || activeTab?.pinned
+ options.openInNewTab ||
+ (activeTab?.pinned && !oldTabForNote && !isReactivatingTab)
? addTab(getId())
: oldTabForNote?.id || activeTabId || addTab(getId());