Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager: improve the mobile UI

Adorian Doran4d37e8ef30df
diff --git a/apps/client/src/widgets/react/FormList.tsx b/apps/client/src/widgets/react/FormList.tsx
index 6bb0a839b6..197a4eda2d 100644
--- a/apps/client/src/widgets/react/FormList.tsx
+++ b/apps/client/src/widgets/react/FormList.tsx
@@ -224,7 +224,8 @@ function FormListContent({ children, badges, description, disabled, disabledTool
}
interface FormListHeaderOpts {
- text: string;
+ /** Usually a heading, but anything a group can be introduced by: a summary, a row of marks. */
+ text: ComponentChildren;
/** Optional element rendered right-aligned in the header (e.g. an edit action). */
action?: ComponentChildren;
}
diff --git a/apps/client/src/widgets/type_widgets/options/active_content.css b/apps/client/src/widgets/type_widgets/options/active_content.css
index 3148e41218..a220debf14 100644
--- a/apps/client/src/widgets/type_widgets/options/active_content.css
+++ b/apps/client/src/widgets/type_widgets/options/active_content.css
@@ -87,3 +87,47 @@
.active-content-view-choice button {
font-size: 0.85em;
}
+
+/*
+ * The toolbar is one row of controls that a phone has no width for: the filter alone wants most of
+ * it. Keyed on `body.mobile` rather than on the width, to agree with `collapseOnMobile` on the view
+ * choice, which is a JS check on the same thing.
+ */
+body.mobile {
+ /* The filter takes the first line, the view controls the second, so neither is crushed. The
+ label keeps the `margin-inline-start: auto` it has across the toolbar, which on the line it
+ now leads takes up that line's slack instead, holding the controls at the trailing edge. */
+ .active-content-toolbar {
+ flex-wrap: wrap;
+ }
+
+ .active-content-filter {
+ flex-basis: 100%;
+ max-width: none;
+ }
+
+ /* A row here is a line of a list rather than a setting in a card, so it keeps less from the
+ edge than a card section does: the width goes to the names, which are what is read. */
+ .active-content-list .nested-note-list {
+ --card-padding-inline: 12px;
+ }
+}
+
+/* The row's detail, moved into the item's menu where a phone has room to read it. Stacked rather
+ than run together: the location is a sentence's worth on its own. */
+.active-content-item-summary {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 0.35em;
+ white-space: normal;
+
+ .active-content-properties {
+ justify-content: flex-start;
+ }
+}
+
+/* Broken where it must be: a path is one long run, and the menu is no wider than the screen. */
+.active-content-item-location {
+ overflow-wrap: anywhere;
+}
diff --git a/apps/client/src/widgets/type_widgets/options/active_content.tsx b/apps/client/src/widgets/type_widgets/options/active_content.tsx
index 75909871c9..3823be189f 100644
--- a/apps/client/src/widgets/type_widgets/options/active_content.tsx
+++ b/apps/client/src/widgets/type_widgets/options/active_content.tsx
@@ -20,11 +20,12 @@ import attributeService from "../../../services/attributes";
import branches from "../../../services/branches";
import debounce from "../../../services/debounce";
import { t } from "../../../services/i18n";
+import treeService from "../../../services/tree";
import { isMobile } from "../../../services/utils";
import { ListView, type ListViewOptions } from "../../collections/legacy/ListOrGridView";
import { Badge } from "../../react/Badge";
import Dropdown from "../../react/Dropdown";
-import { FormListItem } from "../../react/FormList";
+import { FormListHeader, FormListItem } from "../../react/FormList";
import FormTextBox from "../../react/FormTextBox";
import FormToggle from "../../react/FormToggle";
import { useTriliumEvent, useTriliumOption } from "../../react/hooks";
@@ -42,7 +43,7 @@ const FILTER_DEBOUNCE_MS = 300;
* The item's "..." menu. The collection menu is replaced here because most of its entries act on a
* note in the context of its parent, which this list is not: these notes live all over the tree.
*/
-function ContentItemMenu({ note }: { note: FNote }) {
+function ContentItemMenu({ note, categories }: { note: FNote, categories: ContentCategory[] }) {
return (
<Dropdown
className="active-content-item-menu"
@@ -54,6 +55,10 @@ function ContentItemMenu({ note }: { note: FNote }) {
title={t("content_manager.item_menu")}
dropdownContainerClassName={isMobile() ? "mobile-bottom-menu" : undefined}
>
+ {isMobile() && (
+ <FormListHeader text={<ItemSummary note={note} categories={categories} />} />
+ )}
+
<FormListItem
icon="bx bx-link-external"
onClick={() => void appContext.tabManager.openContextWithNote(note.noteId, {
@@ -103,6 +108,31 @@ function ItemDetail({ note, category, showCategory }: {
);
}
+/**
+ * What the row has no width for on a phone: where the note lives, and what makes it active content.
+ * Shown at the head of the item's own menu, which is one tap away either way.
+ */
+function ItemSummary({ note, categories }: { note: FNote, categories: ContentCategory[] }) {
+ const [ location, setLocation ] = useState<string>();
+
+ // Resolved rather than read: a path is a chain of ids, and the titles behind them may not be
+ // loaded. Only runs once the menu is opened, its contents being built no sooner.
+ useEffect(() => {
+ const segments = note.getBestNotePath();
+ segments.pop();
+ void treeService.getNotePathTitle(segments.join("/")).then(setLocation);
+ }, [ note ]);
+
+ return (
+ <span className="active-content-item-summary">
+ {location && <span className="active-content-item-location">{location}</span>}
+ {categories.map((category) => (
+ <ItemDetail key={category.id} note={note} category={category} showCategory />
+ ))}
+ </span>
+ );
+}
+
/**
* A note's extra detail as badges — `Hourly`, `main` — one per value.
*
@@ -175,6 +205,9 @@ const LIST_OPTIONS: ListViewOptions = {
// These notes are scattered across the tree rather than being children of this page, so they are
// listed flat with their real location shown underneath, the way search results are.
searchResultsLayout: true,
+ // On a phone the row has width for the name and the switch and nothing else, so where the note
+ // lives moves into its menu (see `ItemSummary`) rather than being cut short under the title.
+ showNotePath: () => !isMobile(),
hideSubNotes: true,
// Collapsed by default: the list is meant to be scanned, and expanding reveals the note's own
// preview rather than a subtree.
@@ -239,6 +272,9 @@ export default function ActiveContent({ note }: TypeWidgetProps) {
options={VIEW_MODES}
currentValue={viewMode}
onChange={(newValue) => void setViewMode(newValue)}
+ // Two named choices are wider than the row a phone has for them, and they
+ // sit beside a filter box that needs what is left.
+ collapseOnMobile
/>
<SortOrderMenu currentValue={sortOrder} onChange={(newValue) => void setSortOrder(newValue)} />
</div>
@@ -298,7 +334,8 @@ function LocationList({ pageNote, categories, highlightedTokens }: CategoryListP
// content instead, `ListView` offering the tooltip wherever the preview is absent.
showPreview: () => false,
// Only the grouping folders state where they sit; repeating it on each item beneath
- // would undo the grouping. An item's own path is in its hover tooltip.
+ // would undo the grouping. An item's own path is in its hover tooltip, and on a
+ // phone in its menu. A folder has neither, so it keeps its path at every width.
showNotePath: (note) => !itemsByNoteId.has(note.noteId),
// Grouping folders are not active content, so they carry neither toggle nor menu —
// just how much they hold, which is the only reason they are on screen.
@@ -319,12 +356,17 @@ function LocationList({ pageNote, categories, highlightedTokens }: CategoryListP
// would otherwise say it are gone.
return item.categories.map((category) => (
<span key={category.id} className="active-content-item-strip">
- <ItemDetail note={note} category={category} showCategory />
+ {!isMobile() &&
+ <ItemDetail note={note} category={category} showCategory />}
<ContentToggle note={note} category={category} />
</span>
));
},
- renderItemMenu: (note) => itemsByNoteId.has(note.noteId) ? <ContentItemMenu note={note} /> : null
+ renderItemMenu: (note) => {
+ const item = itemsByNoteId.get(note.noteId);
+ if (!item) return null;
+ return <ContentItemMenu note={note} categories={item.categories} />;
+ }
}}
/>
);
@@ -417,11 +459,13 @@ function CategoryList({ pageNote, categories, highlightedTokens }: CategoryListP
title: t(category.titleKey),
renderItemActions: (note) => (
<>
- <ItemDetail note={note} category={category} />
+ {!isMobile() && <ItemDetail note={note} category={category} />}
<ContentToggle note={note} category={category} />
</>
),
- renderItemMenu: (note) => <ContentItemMenu note={note} />
+ renderItemMenu: (note) => (
+ <ContentItemMenu note={note} categories={[ category ]} />
+ )
}}
/>
))}