Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(web): collapse the notebook list from its heading

tianma-ifcc44dcf91715
diff --git a/apps/web/src/components/NotebookPane.test.mjs b/apps/web/src/components/NotebookPane.test.mjs
index 1bb27799..b8c5503a 100644
--- a/apps/web/src/components/NotebookPane.test.mjs
+++ b/apps/web/src/components/NotebookPane.test.mjs
@@ -113,6 +113,25 @@ describe("NotebookPane tree expansion persistence", () => {
expect(treeItemSource).not.toContain("const [open, setOpen] = useState(true)");
expect(treeItemSource).not.toContain("if (hasSelectedDescendant) {");
});
+
+ test("lets the notebooks heading collapse the list without touching each branch", () => {
+ const catalogs = ["en-US", "zh-CN", "ja", "pl", "ru"].map((locale) =>
+ readFileSync(new URL(`../../../../packages/shared/src/i18n/${locale}.ts`, import.meta.url), "utf8"),
+ );
+
+ expect(source).toContain("readNotebookSectionCollapsedPreference");
+ expect(source).toContain("writeNotebookSectionCollapsedPreference(notebookSectionCollapsed)");
+ expect(source).toContain("data-notebook-section-toggle");
+ expect(source).toContain('t(notebookSectionCollapsed ? "notebookPane.expandNotebooks" : "notebookPane.collapseNotebooks")');
+ expect(source).toContain("{notebookSectionCollapsed ? null : isLoading ? (");
+ expect(source).toContain("setNotebookSectionCollapsed(false)");
+ expect(source).toContain("collapsible={!isLoading && tree.length > 0}");
+
+ for (const catalog of catalogs) {
+ expect(catalog).toContain("collapseNotebooks:");
+ expect(catalog).toContain("expandNotebooks:");
+ }
+ });
});
describe("NotebookPane client downloads", () => {
diff --git a/apps/web/src/components/NotebookPane.tsx b/apps/web/src/components/NotebookPane.tsx
index c9d4c4e9..0a80e2ef 100644
--- a/apps/web/src/components/NotebookPane.tsx
+++ b/apps/web/src/components/NotebookPane.tsx
@@ -57,8 +57,10 @@ import {
getNotebookSortOptions,
getNotebookSortComparator,
hasEdgeEverDragData,
+ readNotebookSectionCollapsedPreference,
readNotebookTreeCollapsedIdsPreference,
readNotebookSortPreference,
+ writeNotebookSectionCollapsedPreference,
writeNotebookTreeCollapsedIdsPreference,
writeNotebookSortPreference,
} from "@/lib/app-helpers";
@@ -234,12 +236,67 @@ const SidebarTrashShortcut = ({
);
};
-const SidebarSectionLabel = ({ icon, label }: { icon: ReactNode; label: string }) => (
- <div className="flex h-9 items-center gap-3 px-3 text-xs font-medium leading-none tracking-wide text-slate-500">
- <span className="flex h-4 w-4 shrink-0 items-center justify-center">{icon}</span>
- <span className="min-w-0 flex-1 truncate">{label}</span>
- </div>
-);
+const SidebarSectionLabel = ({
+ icon,
+ label,
+ collapsed = false,
+ collapsible = false,
+ onToggle,
+ toggleLabel,
+}: {
+ icon: ReactNode;
+ label: string;
+ collapsed?: boolean;
+ collapsible?: boolean;
+ onToggle?: () => void;
+ toggleLabel?: string;
+}) => {
+ const content = (
+ <>
+ <span className="flex h-4 w-4 shrink-0 items-center justify-center">{icon}</span>
+ <span className="flex min-w-0 items-center gap-1">
+ <span className="truncate">{label}</span>
+ {collapsible ? (
+ <ChevronDown
+ className={cn(
+ "h-3.5 w-3.5 shrink-0 text-slate-400 transition-transform duration-150 ease-out",
+ collapsed ? "-rotate-90" : "rotate-0",
+ )}
+ aria-hidden="true"
+ />
+ ) : null}
+ </span>
+ </>
+ );
+ const className = "flex h-9 min-w-0 flex-1 items-center gap-3 rounded-md px-3 text-left text-xs font-medium leading-none tracking-wide text-slate-500";
+
+ if (!collapsible || !onToggle || !toggleLabel) {
+ return <div className={className}>{content}</div>;
+ }
+
+ return (
+ <TooltipProvider delayDuration={0} skipDelayDuration={0}>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <button
+ className={cn(
+ className,
+ "transition-colors hover:bg-slate-50 hover:text-slate-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-400/70",
+ )}
+ type="button"
+ data-notebook-section-toggle
+ aria-expanded={!collapsed}
+ aria-label={toggleLabel}
+ onClick={onToggle}
+ >
+ {content}
+ </button>
+ </TooltipTrigger>
+ <TooltipContent side="bottom">{toggleLabel}</TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ );
+};
const SidebarCollapseButton = ({
collapsed,
@@ -564,6 +621,7 @@ export const NotebookPane = ({
const [expandSiblingsRequest, setExpandSiblingsRequest] = useState<{ parentId: string | null; token: number } | null>(null);
const [notebookSortMode, setNotebookSortMode] = useState<NotebookSortMode>(readNotebookSortPreference);
const [collapsedNotebookIds, setCollapsedNotebookIds] = useState<Set<string>>(readNotebookTreeCollapsedIdsPreference);
+ const [notebookSectionCollapsed, setNotebookSectionCollapsed] = useState(readNotebookSectionCollapsedPreference);
const handleMoveNotebook = useCallback((notebookId: string, targetNotebookId: string, position: NotebookDropPosition) => {
setNotebookSortMode("custom");
@@ -652,6 +710,19 @@ export const NotebookPane = ({
writeNotebookTreeCollapsedIdsPreference(collapsedNotebookIds);
}, [collapsedNotebookIds]);
+ useEffect(() => {
+ writeNotebookSectionCollapsedPreference(notebookSectionCollapsed);
+ }, [notebookSectionCollapsed]);
+
+ const handleCreateRootNotebook = useCallback(() => {
+ setNotebookSectionCollapsed(false);
+ onCreateNotebook(null);
+ }, [onCreateNotebook]);
+
+ const handleToggleNotebookSection = useCallback(() => {
+ setNotebookSectionCollapsed((collapsed) => !collapsed);
+ }, []);
+
const handleNotebookOpenChange = useCallback((notebookId: string, open: boolean) => {
setCollapsedNotebookIds((current) => {
if (current.has(notebookId) === !open) {
@@ -694,7 +765,7 @@ export const NotebookPane = ({
<Button size="icon" variant="ghost" title={t("notebookPane.backToList")} aria-label={t("notebookPane.backToList")} onClick={onBackToList}>
<ChevronLeft className="h-4 w-4" />
</Button>
- <Button size="icon" variant="ghost" title={t("notebookPane.newNotebook")} aria-label={t("notebookPane.newNotebook")} onClick={() => onCreateNotebook(null)}>
+ <Button size="icon" variant="ghost" title={t("notebookPane.newNotebook")} aria-label={t("notebookPane.newNotebook")} onClick={handleCreateRootNotebook}>
<Plus className="h-4 w-4" />
</Button>
</div>
@@ -803,14 +874,21 @@ export const NotebookPane = ({
</nav>
<div className="group mb-2 flex items-center justify-between gap-2">
- <SidebarSectionLabel icon={<NotebookIcon className="h-4 w-4" />} label={t("notebookPane.notebooks")} />
+ <SidebarSectionLabel
+ icon={<NotebookIcon className="h-4 w-4" />}
+ label={t("notebookPane.notebooks")}
+ collapsed={notebookSectionCollapsed}
+ collapsible={!isLoading && tree.length > 0}
+ onToggle={handleToggleNotebookSection}
+ toggleLabel={t(notebookSectionCollapsed ? "notebookPane.expandNotebooks" : "notebookPane.collapseNotebooks")}
+ />
<div className="flex items-center gap-1 opacity-100 transition-opacity duration-200 lg:opacity-0 lg:group-hover:opacity-100 lg:group-focus-within:opacity-100">
<button
className="flex h-6 w-6 items-center justify-center rounded-md text-slate-500 transition-colors duration-200 hover:bg-slate-100 hover:text-slate-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-400/70"
type="button"
title={t("notebookPane.newNotebook")}
aria-label={t("notebookPane.newNotebook")}
- onClick={() => onCreateNotebook(null)}
+ onClick={handleCreateRootNotebook}
>
<BookPlus className="h-3.5 w-3.5" />
</button>
@@ -848,7 +926,7 @@ export const NotebookPane = ({
</div>
</div>
- {isLoading ? (
+ {notebookSectionCollapsed ? null : isLoading ? (
<div className="mb-4 px-2 py-3 text-sm text-slate-500">{t("notebookPane.loading")}</div>
) : (
<div className="mb-4 space-y-1" data-notebook-tree>
diff --git a/apps/web/src/lib/app-helpers.test.mjs b/apps/web/src/lib/app-helpers.test.mjs
index 9f989f91..a99c7575 100644
--- a/apps/web/src/lib/app-helpers.test.mjs
+++ b/apps/web/src/lib/app-helpers.test.mjs
@@ -20,6 +20,7 @@ import {
MAX_MEMO_LIST_WIDTH_PX,
MIN_EDITOR_WIDTH_PX,
NOTEBOOK_SORT_STORAGE_KEY,
+ NOTEBOOK_SECTION_COLLAPSED_STORAGE_KEY,
NOTEBOOK_TREE_COLLAPSED_IDS_STORAGE_KEY,
SHORTCUT_SETTINGS_STORAGE_KEY,
getSearchShortcutScope,
@@ -37,6 +38,7 @@ import {
getNotebookSortComparator,
readEditorContentAlignmentPreference,
readNotebookSortPreference,
+ readNotebookSectionCollapsedPreference,
readNotebookTreeCollapsedIdsPreference,
readDesktopFocusModePreference,
readDesktopReadingProtectionPreference,
@@ -50,6 +52,7 @@ import {
readShortcutSettingsPreference,
writeEditorContentAlignmentPreference,
writeNotebookSortPreference,
+ writeNotebookSectionCollapsedPreference,
writeNotebookTreeCollapsedIdsPreference,
writeDesktopFocusModePreference,
writeDesktopReadingProtectionPreference,
@@ -514,6 +517,19 @@ describe("notebook tree collapsed preference", () => {
expect(readNotebookTreeCollapsedIdsPreference()).toEqual(new Set());
expect(() => writeNotebookTreeCollapsedIdsPreference(["notebook-1"])).not.toThrow();
});
+
+ test("remembers whether the notebook section itself is collapsed", () => {
+ const values = installLocalStorage();
+
+ expect(readNotebookSectionCollapsedPreference()).toBe(false);
+
+ writeNotebookSectionCollapsedPreference(true);
+ expect(values.get(NOTEBOOK_SECTION_COLLAPSED_STORAGE_KEY)).toBe("true");
+ expect(readNotebookSectionCollapsedPreference()).toBe(true);
+
+ writeNotebookSectionCollapsedPreference(false);
+ expect(readNotebookSectionCollapsedPreference()).toBe(false);
+ });
});
describe("workspace shortcut preferences", () => {
diff --git a/apps/web/src/lib/app-helpers.ts b/apps/web/src/lib/app-helpers.ts
index 12fda533..0588e499 100644
--- a/apps/web/src/lib/app-helpers.ts
+++ b/apps/web/src/lib/app-helpers.ts
@@ -157,6 +157,7 @@ export const MEMO_LIST_DENSITY_STORAGE_KEY = "edgeever.memoListDensity";
export const MEMO_LIST_WIDTH_STORAGE_KEY = "edgeever.memoListWidth";
export const NOTEBOOK_SORT_STORAGE_KEY = "edgeever.notebookSort";
export const NOTEBOOK_TREE_COLLAPSED_IDS_STORAGE_KEY = "edgeever.notebookTreeCollapsedIds:v1";
+export const NOTEBOOK_SECTION_COLLAPSED_STORAGE_KEY = "edgeever.notebookSectionCollapsed";
export const SHORTCUT_SETTINGS_STORAGE_KEY = "edgeever.shortcutSettings";
export const DEFAULT_MEMO_LIST_WIDTH_PX = 360;
export const MIN_MEMO_LIST_WIDTH_PX = 300;
@@ -553,6 +554,22 @@ export const writeNotebookTreeCollapsedIdsPreference = (notebookIds: Iterable<st
}
};
+export const readNotebookSectionCollapsedPreference = () => {
+ try {
+ return window.localStorage.getItem(NOTEBOOK_SECTION_COLLAPSED_STORAGE_KEY) === "true";
+ } catch {
+ return false;
+ }
+};
+
+export const writeNotebookSectionCollapsedPreference = (collapsed: boolean) => {
+ try {
+ window.localStorage.setItem(NOTEBOOK_SECTION_COLLAPSED_STORAGE_KEY, collapsed ? "true" : "false");
+ } catch {
+ // Local storage can be unavailable in private or restricted browser contexts.
+ }
+};
+
export const normalizeShortcutKey = (key: string) => {
if (key === " ") {
return "space";
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 7655a74e..9686e485 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -943,6 +943,8 @@ export const enUS = {
profile: "Profile",
collapseSidebar: "Collapse notebook pane",
expandSidebar: "Expand notebook pane",
+ collapseNotebooks: "Collapse notebooks",
+ expandNotebooks: "Expand notebooks",
trash: "Trash",
emptyTrash: "Empty trash",
empty: "Empty",
diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.ts
index 3ea7636f..96071edb 100644
--- a/packages/shared/src/i18n/ja.ts
+++ b/packages/shared/src/i18n/ja.ts
@@ -932,6 +932,8 @@ export const ja = {
profile: "プロフィール",
collapseSidebar: "ノートブック欄を閉じる",
expandSidebar: "ノートブック欄を開く",
+ collapseNotebooks: "ノートブックを閉じる",
+ expandNotebooks: "ノートブックを開く",
trash: "ゴミ箱",
emptyTrash: "ゴミ箱を空にする",
empty: "空にする",
diff --git a/packages/shared/src/i18n/pl.ts b/packages/shared/src/i18n/pl.ts
index 93ad67ee..65ade940 100644
--- a/packages/shared/src/i18n/pl.ts
+++ b/packages/shared/src/i18n/pl.ts
@@ -932,6 +932,8 @@ export const pl = {
profile: "Profil",
collapseSidebar: "Zwiń panel notatników",
expandSidebar: "Rozwiń panel notatników",
+ collapseNotebooks: "Zwiń notatniki",
+ expandNotebooks: "Rozwiń notatniki",
trash: "Kosz",
emptyTrash: "Opróżnij kosz",
empty: "Pusto",
diff --git a/packages/shared/src/i18n/ru.ts b/packages/shared/src/i18n/ru.ts
index 53ff70c7..c30953d0 100644
--- a/packages/shared/src/i18n/ru.ts
+++ b/packages/shared/src/i18n/ru.ts
@@ -943,6 +943,8 @@ export const ru = {
profile: "Профиль",
collapseSidebar: "Свернуть панель блокнотов",
expandSidebar: "Развернуть панель блокнотов",
+ collapseNotebooks: "Свернуть блокноты",
+ expandNotebooks: "Развернуть блокноты",
trash: "Корзина",
emptyTrash: "Очистить корзину",
empty: "Пусто",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 35d75225..c420199c 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -943,6 +943,8 @@ export const zhCN = {
profile: "个人中心",
collapseSidebar: "收起笔记本栏",
expandSidebar: "展开笔记本栏",
+ collapseNotebooks: "收起笔记本",
+ expandNotebooks: "展开笔记本",
trash: "回收站",
emptyTrash: "清空回收站",
empty: "清空",