Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager: add location view mode

Adorian Doran002b881e8693
diff --git a/apps/client/src/services/content_manager.spec.ts b/apps/client/src/services/content_manager.spec.ts
index 5094f7d6e4..b6f518d30c 100644
--- a/apps/client/src/services/content_manager.spec.ts
+++ b/apps/client/src/services/content_manager.spec.ts
@@ -5,6 +5,7 @@ import { buildNote } from "../test/easy-froca";
import attributeService from "./attributes";
import {
buildCategoryQuery,
+ buildLocationTree,
CONTENT_CATEGORIES,
type ContentCategory,
findCategoryNotes,
@@ -431,6 +432,107 @@ describe("findCategoryNotes", () => {
});
});
+describe("buildLocationTree", () => {
+ /** Shapes the tree as `title` / `title(group)` strings, so the assertions read as the rendering. */
+ function outline(nodes: ReturnType<typeof buildLocationTree>, depth = 0): string[] {
+ return nodes.flatMap((node) => [
+ `${" ".repeat(depth)}${node.note.title}${node.isGroup ? " (group)" : ""}`,
+ ...outline(node.children, depth + 1)
+ ]);
+ }
+
+ function itemsOf(...noteIds: string[]) {
+ return noteIds.map((noteId) => froca.notes[noteId]);
+ }
+
+ it("groups items sharing a parent under that parent, which carries no toggle", () => {
+ buildNote({
+ id: "root",
+ title: "root",
+ children: [ { id: "demo", title: "Demo", children: [
+ { id: "stats", title: "Statistics", children: [
+ { id: "statA", title: "Chart A" },
+ { id: "statB", title: "Chart B" }
+ ] }
+ ] } ]
+ });
+
+ expect(outline(buildLocationTree(itemsOf("statA", "statB")))).toEqual([
+ "Statistics (group)",
+ " Chart A",
+ " Chart B"
+ ]);
+ });
+
+ it("nests an item under an item that is its ancestor", () => {
+ buildNote({
+ id: "root",
+ title: "root",
+ children: [ { id: "outer", title: "Outer script", children: [
+ { id: "mid", title: "Mid", children: [ { id: "inner", title: "Inner script" } ] }
+ ] } ]
+ });
+
+ // "Mid" is a pass-through: it holds a single item-bearing path, so it is dropped.
+ expect(outline(buildLocationTree(itemsOf("outer", "inner")))).toEqual([
+ "Outer script",
+ " Inner script"
+ ]);
+ });
+
+ it("puts a grouping folder under an active ancestor when both apply", () => {
+ buildNote({
+ id: "root",
+ title: "root",
+ children: [ { id: "top", title: "Top script", children: [
+ { id: "bucket", title: "Bucket", children: [
+ { id: "one", title: "One" },
+ { id: "two", title: "Two" }
+ ] }
+ ] } ]
+ });
+
+ expect(outline(buildLocationTree(itemsOf("top", "one", "two")))).toEqual([
+ "Top script",
+ " Bucket (group)",
+ " One",
+ " Two"
+ ]);
+ });
+
+ it("leaves an unrelated item at the top level, without its ancestry", () => {
+ buildNote({
+ id: "root",
+ title: "root",
+ children: [ { id: "deep1", title: "A", children: [
+ { id: "deep2", title: "B", children: [ { id: "lonely", title: "Lonely script" } ] }
+ ] } ]
+ });
+
+ expect(outline(buildLocationTree(itemsOf("lonely")))).toEqual([ "Lonely script" ]);
+ });
+
+ it("never groups under the tree root, even when items live in separate subtrees", () => {
+ buildNote({
+ id: "root",
+ title: "root",
+ children: [
+ { id: "left", title: "Left", children: [ { id: "leftItem", title: "Left item" } ] },
+ { id: "right", title: "Right", children: [ { id: "rightItem", title: "Right item" } ] }
+ ]
+ });
+
+ expect(outline(buildLocationTree(itemsOf("leftItem", "rightItem")))).toEqual([
+ "Left item",
+ "Right item"
+ ]);
+ });
+
+ it("returns nothing for no items", () => {
+ expect(buildLocationTree([])).toEqual([]);
+ });
+});
+
describe("getDisplayedBranchId", () => {
// A note path is only resolvable if it reaches the root, so anchor the fixtures there.
function buildTree() {
diff --git a/apps/client/src/services/content_manager.ts b/apps/client/src/services/content_manager.ts
index 929bb82ecf..14912be371 100644
--- a/apps/client/src/services/content_manager.ts
+++ b/apps/client/src/services/content_manager.ts
@@ -1,5 +1,6 @@
import type FNote from "../entities/fnote";
import attributes from "./attributes";
+import froca from "./froca";
import search from "./search";
/** An attribute that makes a note part of a category. */
@@ -362,6 +363,86 @@ function toArray(value: string | string[]) {
return Array.isArray(value) ? value : [ value ];
}
+/** A node of the "by location" tree: either an item, or a folder inserted to group several. */
+export interface LocationNode {
+ note: FNote;
+ /** A folder holding several items rather than active content itself, so it carries no toggle. */
+ isGroup: boolean;
+ children: LocationNode[];
+}
+
+/**
+ * Arranges items into a tree that mirrors where the user actually keeps them, so a set of items
+ * living together — the render notes under a single "Statistics" note — reads as one feature instead
+ * of as several unrelated rows.
+ *
+ * A node earns a place in the tree when it is either an item itself, or a folder where two or more
+ * item-bearing paths diverge. Everything else is a pass-through ancestor and is dropped, which is
+ * what keeps a lone item at the top level rather than buried under its whole ancestry.
+ */
+export function buildLocationTree(items: FNote[]): LocationNode[] {
+ const itemsById = new Map(items.map((item) => [ item.noteId, item ]));
+ const childIds = new Map<string, string[]>();
+ const parented = new Set<string>();
+ const roots: string[] = [];
+
+ for (const item of items) {
+ const path = item.getBestNotePath() ?? [ item.noteId ];
+
+ if (!parented.has(path[0]) && !roots.includes(path[0])) {
+ roots.push(path[0]);
+ }
+
+ for (let i = 0; i < path.length - 1; i++) {
+ const siblings = childIds.get(path[i]) ?? [];
+
+ if (!siblings.includes(path[i + 1])) {
+ siblings.push(path[i + 1]);
+ }
+
+ childIds.set(path[i], siblings);
+ parented.add(path[i + 1]);
+ }
+ }
+
+ const holdsItem = new Map<string, boolean>();
+
+ function subtreeHoldsItem(noteId: string): boolean {
+ const known = holdsItem.get(noteId);
+ if (known !== undefined) return known;
+
+ const result = itemsById.has(noteId)
+ || (childIds.get(noteId) ?? []).some(subtreeHoldsItem);
+ holdsItem.set(noteId, result);
+
+ return result;
+ }
+
+ function isKept(noteId: string) {
+ // The tree root is never a grouping node: it would only ever say "everything lives in the
+ // vault", and would swallow the whole tree under one useless heading.
+ if (noteId === "root") return false;
+ if (itemsById.has(noteId)) return true;
+
+ return (childIds.get(noteId) ?? []).filter(subtreeHoldsItem).length >= 2;
+ }
+
+ function build(noteId: string): LocationNode[] {
+ const collected = (childIds.get(noteId) ?? []).flatMap(build);
+
+ if (!isKept(noteId)) return collected;
+
+ const note = itemsById.get(noteId) ?? froca.getNoteFromCache(noteId);
+ // A grouping folder that is not in the cache cannot be labelled, so its children take its
+ // place rather than disappearing with it.
+ if (!note) return collected;
+
+ return [ { note, isGroup: !itemsById.has(noteId), children: collected } ];
+ }
+
+ return roots.filter((noteId) => !parented.has(noteId)).flatMap(build);
+}
+
/**
* The branch for the placement shown on the note's row, or `undefined` if there isn't a deletable one.
*
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 1a1b57defc..79ec8b2310 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2650,6 +2650,9 @@
"share_js": "JavaScript",
"share_html": "HTML",
"share_template": "Template",
+ "view_mode": "View:",
+ "view_by_category": "By category",
+ "view_by_location": "By location",
"sort_order": "Sort by:",
"sort_by_title": "Title",
"sort_by_date_created": "Creation date",
diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
index 837029297c..2744a116ad 100644
--- a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
+++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
@@ -38,6 +38,16 @@ export interface ListViewOptions {
searchResultsLayout?: boolean;
/** Omits the nested subnote tree, leaving only each note's own content preview. */
hideSubNotes?: boolean;
+ /**
+ * Supplies a row's nested notes, replacing its real child notes. Lets a caller present its own
+ * hierarchy — grouping scattered notes by where they live — through the same nesting UI.
+ */
+ resolveChildren?: (note: FNote) => FNote[];
+ /**
+ * Decides per row whether its content preview is rendered; previews show for every row by
+ * default. Useful when a caller inserts rows of its own, whose content is not the point.
+ */
+ showPreview?: (note: FNote) => boolean;
/** Overrides how many levels start expanded, otherwise read from the parent's `#expanded`. */
expandDepth?: number;
/** Overrides the number of notes per page, otherwise read from the parent's `#pageSize`. */
@@ -67,6 +77,8 @@ export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens,
currentLevel={1} includeArchived={includeArchived}
searchResultsLayout={searchResultsLayout}
hideSubNotes={listOptions?.hideSubNotes}
+ resolveChildren={listOptions?.resolveChildren}
+ showPreview={listOptions?.showPreview}
renderItemActions={listOptions?.renderItemActions}
renderItemMenu={listOptions?.renderItemMenu}
showTextRepresentation={showTextRepresentation} />
@@ -124,7 +136,7 @@ function NoteList(props: NoteListProps) {
</div>
}
-function ListNoteCard({ note, parentNote, highlightedTokens, currentLevel, expandDepth, includeArchived, showTextRepresentation, searchResultsLayout, hideSubNotes, renderItemActions, renderItemMenu }: {
+function ListNoteCard({ note, parentNote, highlightedTokens, currentLevel, expandDepth, includeArchived, showTextRepresentation, searchResultsLayout, hideSubNotes, resolveChildren, showPreview, renderItemActions, renderItemMenu }: {
note: FNote,
parentNote: FNote,
currentLevel: number,
@@ -132,7 +144,7 @@ function ListNoteCard({ note, parentNote, highlightedTokens, currentLevel, expan
highlightedTokens: string[] | null | undefined;
includeArchived: boolean;
showTextRepresentation?: boolean;
-} & Pick<ListViewOptions, "searchResultsLayout" | "hideSubNotes" | "renderItemActions" | "renderItemMenu">) {
+} & Pick<ListViewOptions, "searchResultsLayout" | "hideSubNotes" | "resolveChildren" | "showPreview" | "renderItemActions" | "renderItemMenu">) {
const [ isExpanded, setExpanded ] = useState(currentLevel <= expandDepth);
const notePath = getNotePath(parentNote, note, searchResultsLayout);
@@ -143,13 +155,15 @@ function ListNoteCard({ note, parentNote, highlightedTokens, currentLevel, expan
let subSections: JSX.Element | undefined = undefined;
if (isExpanded) {
subSections = <>
- <CardSection className="note-content-preview">
- <NoteContent note={note}
- highlightedTokens={highlightedTokens}
- noChildrenList
- includeArchivedNotes={includeArchived}
- showTextRepresentation={showTextRepresentation} />
- </CardSection>
+ {(showPreview?.(note) ?? true) && (
+ <CardSection className="note-content-preview">
+ <NoteContent note={note}
+ highlightedTokens={highlightedTokens}
+ noChildrenList
+ includeArchivedNotes={includeArchived}
+ showTextRepresentation={showTextRepresentation} />
+ </CardSection>
+ )}
{!hideSubNotes && (
<NoteChildren
@@ -159,6 +173,8 @@ function ListNoteCard({ note, parentNote, highlightedTokens, currentLevel, expan
currentLevel={currentLevel}
expandDepth={expandDepth}
searchResultsLayout={searchResultsLayout}
+ resolveChildren={resolveChildren}
+ showPreview={showPreview}
renderItemActions={renderItemActions}
renderItemMenu={renderItemMenu}
includeArchived={includeArchived}
@@ -330,19 +346,24 @@ export function NoteContent({ note, trim, noChildrenList, highlightedTokens, inc
return <div ref={contentRef} className={clsx("note-book-content", `type-${noteType}`, {"note-book-content-ready": ready})} />;
}
-function NoteChildren({ note, parentNote, highlightedTokens, currentLevel, expandDepth, includeArchived, searchResultsLayout, renderItemActions, renderItemMenu }: {
+function NoteChildren({ note, parentNote, highlightedTokens, currentLevel, expandDepth, includeArchived, searchResultsLayout, resolveChildren, showPreview, renderItemActions, renderItemMenu }: {
note: FNote,
parentNote: FNote,
currentLevel: number,
expandDepth: number,
highlightedTokens: string[] | null | undefined
includeArchived: boolean;
-} & Pick<ListViewOptions, "searchResultsLayout" | "renderItemActions" | "renderItemMenu">) {
+} & Pick<ListViewOptions, "searchResultsLayout" | "resolveChildren" | "showPreview" | "renderItemActions" | "renderItemMenu">) {
const [ childNotes, setChildNotes ] = useState<FNote[]>();
useEffect(() => {
+ if (resolveChildren) {
+ setChildNotes(resolveChildren(note));
+ return;
+ }
+
filterChildNotes(note, includeArchived).then(setChildNotes);
- }, [ note, includeArchived ]);
+ }, [ note, includeArchived, resolveChildren ]);
return childNotes?.map(childNote => <ListNoteCard
key={childNote.noteId}
@@ -352,6 +373,8 @@ function NoteChildren({ note, parentNote, highlightedTokens, currentLevel, expan
currentLevel={currentLevel + 1} expandDepth={expandDepth}
includeArchived={includeArchived}
searchResultsLayout={searchResultsLayout}
+ resolveChildren={resolveChildren}
+ showPreview={showPreview}
renderItemActions={renderItemActions}
renderItemMenu={renderItemMenu}
/>);
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.tsx b/apps/client/src/widgets/type_widgets/options/content_manager.tsx
index 87aa119193..89f0924531 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager.tsx
@@ -9,12 +9,14 @@ import type FNote from "../../../entities/fnote";
import contextMenu, { type MenuItem } from "../../../menus/context_menu";
import branches from "../../../services/branches";
import {
+ buildLocationTree,
CONTENT_CATEGORIES,
type ContentCategory,
type ContentSortOrder,
findCategoryNotes,
getDisplayedBranchId,
isCategoryEnabled,
+ type LocationNode,
resolveProperties,
setCategoryEnabled
} from "../../../services/content_manager";
@@ -117,11 +119,22 @@ function ContentProperties({ note, category }: { note: FNote, category: ContentC
);
}
-function ContentToggle({ note, category }: { note: FNote, category: ContentCategory }) {
- const [ enabled, setEnabled ] = useState(() => isCategoryEnabled(note, category));
+/**
+ * @param categories every category this row stands for — normally one, but the location view merges
+ * the categories, and a note can be active content in more than one way.
+ */
+function ContentToggle({ note, categories }: { note: FNote, categories: ContentCategory[] }) {
+ // Keyed on the ids rather than on `categories`, which is a fresh array on every render.
+ const categoryKey = categories.map(({ id }) => id).join(",");
+ const isEnabled = useCallback(
+ () => categories.some((category) => isCategoryEnabled(note, category)),
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- `categoryKey` stands in for `categories`
+ [ note, categoryKey ]
+ );
+ const [ enabled, setEnabled ] = useState(isEnabled);
// Re-sync when the row is reused for another note, or the state changed elsewhere.
- useEffect(() => setEnabled(isCategoryEnabled(note, category)), [ note, category ]);
+ useEffect(() => setEnabled(isEnabled()), [ isEnabled ]);
return (
<FormToggle
@@ -132,7 +145,7 @@ function ContentToggle({ note, category }: { note: FNote, category: ContentCateg
onChange={(willEnable) => {
// Applied straight away so the switch responds before the lists are rebuilt.
setEnabled(willEnable);
- void setCategoryEnabled(note, category, willEnable);
+ void Promise.all(categories.map((category) => setCategoryEnabled(note, category, willEnable)));
}}
/>
);
@@ -151,6 +164,7 @@ const LIST_OPTIONS: ListViewOptions = {
export default function ContentManagerSettings({ note }: TypeWidgetProps) {
const [ sortOrder, setSortOrder ] = useTriliumOption("contentManagerSortOrder");
+ const [ viewMode, setViewMode ] = useTriliumOption("contentManagerViewMode");
const [ typedFilter, setTypedFilter ] = useState("");
const [ appliedFilter, setAppliedFilter ] = useState("");
const categories = useCategoryNotes(sortOrder as ContentSortOrder, appliedFilter);
@@ -199,26 +213,123 @@ export default function ContentManagerSettings({ note }: TypeWidgetProps) {
onClick={clearFilter}
/>
</div>
+ <span className="content-manager-toolbar-label">{t("content_manager.view_mode")}</span>
+ <SegmentedChoice
+ options={VIEW_MODES}
+ currentValue={viewMode}
+ onChange={(newValue) => void setViewMode(newValue)}
+ />
<span className="content-manager-toolbar-label">{t("content_manager.sort_order")}</span>
- <SortOrderSelect currentValue={sortOrder} onChange={(newValue) => void setSortOrder(newValue)} />
+ <SegmentedChoice
+ options={SORT_ORDERS}
+ currentValue={sortOrder}
+ onChange={(newValue) => void setSortOrder(newValue)}
+ />
</div>
} />
<div className="content-manager-list">
- <CategoryList pageNote={note} categories={categories} highlightedTokens={highlightedTokens} />
+ <ContentList
+ pageNote={note}
+ categories={categories}
+ highlightedTokens={highlightedTokens}
+ viewMode={viewMode}
+ />
</div>
</>
);
}
-function CategoryList({ pageNote, categories, highlightedTokens }: {
+/**
+ * The same items arranged by where they live rather than by what they are, so a set of items kept
+ * together — several render notes under one "Statistics" note — reads as a single feature.
+ */
+function LocationList({ pageNote, categories, highlightedTokens }: CategoryListProps) {
+ const { rootIds, childrenByNoteId, itemsByNoteId } = useMemo(() => buildLocationView(categories), [ categories ]);
+
+ // Stable identity: `NoteChildren` re-fetches whenever the resolver changes.
+ const resolveChildren = useCallback(
+ (note: FNote) => childrenByNoteId.get(note.noteId) ?? [],
+ [ childrenByNoteId ]
+ );
+
+ if (!rootIds.length) return null;
+
+ return (
+ <ListView
+ note={pageNote}
+ notePath={pageNote.noteId}
+ noteIds={rootIds}
+ highlightedTokens={highlightedTokens}
+ viewConfig={undefined}
+ saveConfig={NOOP}
+ media="screen"
+ onReady={NOOP}
+ listOptions={{
+ ...LIST_OPTIONS,
+ // The tree is the point, so nesting is on and every level starts open.
+ hideSubNotes: false,
+ expandDepth: Number.MAX_SAFE_INTEGER,
+ resolveChildren,
+ // Grouping folders exist to hold items; their own content is not what is being shown.
+ showPreview: (note) => itemsByNoteId.has(note.noteId),
+ // Grouping folders are not active content, so they carry neither toggle nor menu.
+ renderItemActions: (note) => {
+ const item = itemsByNoteId.get(note.noteId);
+ if (!item) return null;
+
+ return (
+ <>
+ <ContentProperties note={note} category={item.categories[0]} />
+ <ContentToggle note={note} categories={item.categories} />
+ </>
+ );
+ },
+ renderItemMenu: (note) => itemsByNoteId.has(note.noteId) ? <ContentItemMenu note={note} /> : null
+ }}
+ />
+ );
+}
+
+/** Flattens the location tree into the shape `ListView` consumes: roots, children, and item lookup. */
+function buildLocationView(categories: CategoryNotes[]) {
+ const itemsByNoteId = new Map<string, { note: FNote, categories: ContentCategory[] }>();
+
+ for (const { category, notes } of categories) {
+ for (const note of notes) {
+ const item = itemsByNoteId.get(note.noteId) ?? { note, categories: [] };
+ item.categories.push(category);
+ itemsByNoteId.set(note.noteId, item);
+ }
+ }
+
+ const tree = buildLocationTree([ ...itemsByNoteId.values() ].map(({ note }) => note));
+ const childrenByNoteId = new Map<string, FNote[]>();
+
+ function record(node: LocationNode) {
+ childrenByNoteId.set(node.note.noteId, node.children.map(({ note }) => note));
+ node.children.forEach(record);
+ }
+
+ tree.forEach(record);
+
+ return { rootIds: tree.map(({ note }) => note.noteId), childrenByNoteId, itemsByNoteId };
+}
+
+interface CategoryListProps {
+ pageNote: FNote;
+ categories: CategoryNotes[];
+ highlightedTokens: string[] | null;
+}
+
+/** Handles the states both views share, then hands the results to the chosen one. */
+function ContentList({ pageNote, categories, highlightedTokens, viewMode }: {
pageNote: FNote,
categories: CategoryNotes[] | null,
/** The filter text, so matches stand out in each row's title and path. `null` when not filtering. */
- highlightedTokens: string[] | null
+ highlightedTokens: string[] | null,
+ viewMode: string
}) {
- const isFiltered = !!highlightedTokens;
-
if (!categories) {
return <p className="content-manager-loading">{t("content_manager.loading")}</p>;
}
@@ -228,7 +339,7 @@ function CategoryList({ pageNote, categories, highlightedTokens }: {
if (!populated.length) {
// An empty result means something different while filtering: content may well exist, just
// none of it matching, so the "nothing here yet" hint would be misleading.
- return isFiltered
+ return highlightedTokens
? <NoItems icon="bx bx-search" text={t("content_manager.no_matches")} />
: (
<NoItems icon="bx bx-package" text={t("content_manager.no_items")}>
@@ -237,9 +348,15 @@ function CategoryList({ pageNote, categories, highlightedTokens }: {
);
}
+ const List = viewMode === "location" ? LocationList : CategoryList;
+
+ return <List pageNote={pageNote} categories={populated} highlightedTokens={highlightedTokens} />;
+}
+
+function CategoryList({ pageNote, categories, highlightedTokens }: CategoryListProps) {
return (
<>
- {populated.map(({ category, notes }) => (
+ {categories.map(({ category, notes }) => (
<ListView
key={category.id}
note={pageNote}
@@ -256,7 +373,7 @@ function CategoryList({ pageNote, categories, highlightedTokens }: {
renderItemActions: (note) => (
<>
<ContentProperties note={note} category={category} />
- <ContentToggle note={note} category={category} />
+ <ContentToggle note={note} categories={[ category ]} />
</>
),
renderItemMenu: (note) => <ContentItemMenu note={note} />
@@ -267,10 +384,14 @@ function CategoryList({ pageNote, categories, highlightedTokens }: {
);
}
-function SortOrderSelect({ currentValue, onChange }: { currentValue: string, onChange: (newValue: string) => void }) {
+function SegmentedChoice({ options, currentValue, onChange }: {
+ options: { value: string, label: string }[];
+ currentValue: string;
+ onChange: (newValue: string) => void;
+}) {
return (
<ButtonGroup size="sm">
- {SORT_ORDERS.map(({ value, label }) => (
+ {options.map(({ value, label }) => (
<Button
key={value}
text={label}
@@ -288,6 +409,11 @@ const SORT_ORDERS: { value: ContentSortOrder, label: string }[] = [
{ value: "dateCreated", label: t("content_manager.sort_by_date_created") }
];
+const VIEW_MODES = [
+ { value: "category", label: t("content_manager.view_by_category") },
+ { value: "location", label: t("content_manager.view_by_location") }
+];
+
interface CategoryNotes {
category: ContentCategory;
notes: FNote[];
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index 526888dc7c..043e9702a4 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -69,6 +69,7 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
spellCheckLanguageCode: string;
codeNotesMimeTypes: string;
contentManagerSortOrder: string;
+ contentManagerViewMode: string;
headingStyle: string;
highlightsList: string;
customSearchEngineName: string;
diff --git a/packages/trilium-core/src/routes/api/options.ts b/packages/trilium-core/src/routes/api/options.ts
index bbf5c44102..ecb575e1e8 100644
--- a/packages/trilium-core/src/routes/api/options.ts
+++ b/packages/trilium-core/src/routes/api/options.ts
@@ -62,6 +62,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"codeLineWrapEnabled",
"codeNotesMimeTypes",
"contentManagerSortOrder",
+ "contentManagerViewMode",
"spellCheckEnabled",
"spellCheckLanguageCode",
"imageMaxWidthHeight",
diff --git a/packages/trilium-core/src/services/options_init.ts b/packages/trilium-core/src/services/options_init.ts
index 2e246f9259..0634c957e7 100644
--- a/packages/trilium-core/src/services/options_init.ts
+++ b/packages/trilium-core/src/services/options_init.ts
@@ -176,6 +176,7 @@ const defaultOptions: DefaultOption[] = [
isSynced: true
},
{ name: "contentManagerSortOrder", value: "title", isSynced: true },
+ { name: "contentManagerViewMode", value: "category", isSynced: true },
{ name: "leftPaneWidth", value: "25", isSynced: false },
{ name: "leftPaneVisible", value: "true", isSynced: false },
{ name: "rightPaneWidth", value: "25", isSynced: false },