Skip to content

Build your personal knowledge base with Trilium Notes

feat(mobile/tab_switcher): button to close tab

Elian Doran48db6e175629
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index d7d91b2443..74ba61d284 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2271,5 +2271,8 @@
},
"platform_indicator": {
"available_on": "Available on {{platform}}"
+ },
+ "mobile_tab_switcher": {
+ "close_tab": "Close tab"
}
}
diff --git a/apps/client/src/widgets/mobile_widgets/TabSwitcher.css b/apps/client/src/widgets/mobile_widgets/TabSwitcher.css
index f4fc31f3c7..cc48541376 100644
--- a/apps/client/src/widgets/mobile_widgets/TabSwitcher.css
+++ b/apps/client/src/widgets/mobile_widgets/TabSwitcher.css
@@ -46,6 +46,11 @@
text-overflow: ellipsis;
text-wrap: nowrap;
font-size: 0.9em;
+ flex-grow: 1;
+ }
+
+ .icon-action {
+ flex-shrink: 0;
}
}
diff --git a/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx b/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx
index e9efacecbe..86079fa840 100644
--- a/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx
+++ b/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx
@@ -2,7 +2,7 @@ import "./TabSwitcher.css";
import clsx from "clsx";
import { createPortal } from "preact/compat";
-import { MutableRef, useCallback, useEffect, useRef, useState } from "preact/hooks";
+import { useCallback, useEffect, useRef, useState } from "preact/hooks";
import appContext from "../../components/app_context";
import NoteContext from "../../components/note_context";
@@ -11,7 +11,8 @@ import froca from "../../services/froca";
import { t } from "../../services/i18n";
import { NoteContent } from "../collections/legacy/ListOrGridView";
import { LaunchBarActionButton } from "../launch_bar/launch_bar_widgets";
-import { useActiveNoteContext, useNoteIcon, useTriliumEvent } from "../react/hooks";
+import ActionButton from "../react/ActionButton";
+import { useActiveNoteContext, useNoteIcon, useTriliumEvents } from "../react/hooks";
import Icon from "../react/Icon";
import Modal from "../react/Modal";
@@ -115,6 +116,15 @@ function Tab({ noteContext, containerRef, selectTab, activeNtxId }: {
<header className={colorClass}>
<Icon icon={iconClass} />
<span className="title">{noteContext.note?.title ?? t("tab_row.new_tab")}</span>
+ <ActionButton
+ icon="bx bx-x"
+ text={t("tab_row.close_tab")}
+ onClick={(e) => {
+ // We are closing a tab, so we need to prevent propagation for click (activate tab).
+ e.stopPropagation();
+ appContext.tabManager.removeNoteContext(noteContext.ntxId);
+ }}
+ />
</header>
<div className={clsx("tab-preview", `type-${note?.type ?? "empty"}`)}>
{note && <NoteContent
@@ -148,12 +158,8 @@ function getWorkspaceTabBackgroundColorHue(noteContext: NoteContext) {
function useMainNoteContexts() {
const [ noteContexts, setNoteContexts ] = useState(appContext.tabManager.getMainNoteContexts());
- useTriliumEvent("newNoteContextCreated", ({ noteContext }) => {
- if (noteContext.mainNtxId) return;
- setNoteContexts([
- ...noteContexts,
- noteContext
- ]);
+ useTriliumEvents([ "newNoteContextCreated", "noteContextRemoved" ] , () => {
+ setNoteContexts(appContext.tabManager.getMainNoteContexts());
});
return noteContexts;