Skip to content

Build your personal knowledge base with Trilium Notes

client/options: enable search for mobile UI

Adorian Doran03621a0ba38a
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.css b/apps/client/src/widgets/dialogs/OptionsDialog.css
index 957f2bc7b8..5bed021526 100644
--- a/apps/client/src/widgets/dialogs/OptionsDialog.css
+++ b/apps/client/src/widgets/dialogs/OptionsDialog.css
@@ -82,6 +82,21 @@ body.mobile .modal.options-dialog:not(.mobile-master-detail) > .modal-dialog {
body.mobile .modal.options-dialog.mobile-master-detail {
.options-mobile-nav {
padding: 8px 25px;
+
+ /* The list is the pane's own content here, not a menu standing over something else. */
+ .dropdown-menu.static {
+ padding-block: 0;
+ }
+ }
+
+ /* Left to scroll away with the list beneath it, as a phone's search fields do. */
+ .settings-search {
+ margin-bottom: 12px;
+ }
+
+ /* The pane already holds the results clear of its edges, so the page inside adds nothing. */
+ .options-mobile-results .options-search {
+ padding-inline: 0;
}
.note-detail {
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
index 06873706f0..7dbf0bba80 100644
--- a/apps/client/src/widgets/dialogs/OptionsDialog.tsx
+++ b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
@@ -16,7 +16,7 @@ import Modal from "../react/Modal";
import { NoteContextContext, ParentComponent } from "../react/react_utils";
import SettingsNavigation from "../type_widgets/options/components/SettingsNavigation";
import SettingsSearch from "../type_widgets/options/components/SettingsSearch";
-import OptionsSearchPage from "../type_widgets/options/search_page";
+import OptionsSearchPage, { hasSearchTerms } from "../type_widgets/options/search_page";
/** The settings page shown when no specific section was requested and none was viewed yet this session. */
const DEFAULT_SECTION = "_optionsAppearance";
@@ -44,6 +44,9 @@ export default function OptionsDialog() {
const modalRef = useRef<HTMLDivElement>(null);
const isMobile = utils.isMobile();
const { isMasterDetail, mobileView, switchMobileView, resetMobileView } = useMobileMasterDetail(modalRef);
+ // On a phone the results take the place of the list of pages, which is where the field sits, so
+ // they wait for a search to have begun rather than for the field to have been tapped.
+ const showsMobileResults = searching && hasSearchTerms(searchQuery);
useTriliumEvent("showOptions", async ({ section }) => {
const noteContext = new NoteContext("_options-dialog");
@@ -118,10 +121,26 @@ export default function OptionsDialog() {
>
{isMasterDetail && (
<MasterPane className="options-mobile-nav">
- <MobileSettingsList onSelect={(noteId) => {
- void noteContext.setNote(noteId, { keepActiveDialog: true });
- switchMobileView("page");
- }} />
+ <SettingsSearch
+ query={searchQuery}
+ onChange={setSearchQuery}
+ onFocus={() => setSearching(true)}
+ />
+
+ {/* The results stand in the list's place once there is something to look
+ for, and the list comes back as soon as the field is emptied. Below that
+ they are mounted out of sight, so the first search is as quick as the
+ rest and the way out of the search is never anything but the field. */}
+ <div className="options-mobile-results" hidden={!showsMobileResults}>
+ {searching && <OptionsSearchPage query={searchQuery} />}
+ </div>
+
+ {!showsMobileResults && (
+ <MobileSettingsList onSelect={(noteId) => {
+ void noteContext.setNote(noteId, { keepActiveDialog: true });
+ switchMobileView("page");
+ }} />
+ )}
</MasterPane>
)}
<SettingsScrollReset modalRef={modalRef} searching={searching} />
diff --git a/apps/client/src/widgets/type_widgets/options/search_page.css b/apps/client/src/widgets/type_widgets/options/search_page.css
index fe69e63e01..9093c7f3ac 100644
--- a/apps/client/src/widgets/type_widgets/options/search_page.css
+++ b/apps/client/src/widgets/type_widgets/options/search_page.css
@@ -30,6 +30,13 @@
}
}
+/* The field says what is being done, so on a small screen the room above the results is worth more
+ than a banner repeating it. (The narrow flow drops it anyway, by the rule in OptionsPageHeader.css
+ that takes down a banner carrying nothing but a name.) */
+body.mobile .options-search .options-page-header {
+ display: none;
+}
+
/*
* A page brings its whole self along, of which the search wants only the cards: its header names
* the page it thinks it is showing, and its tables and listings are not settings anyone can search
diff --git a/apps/client/src/widgets/type_widgets/options/search_page.spec.tsx b/apps/client/src/widgets/type_widgets/options/search_page.spec.tsx
index c4479cfbb8..71a88d0bec 100644
--- a/apps/client/src/widgets/type_widgets/options/search_page.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/search_page.spec.tsx
@@ -41,7 +41,19 @@ vi.mock("../ContentWidget", async () => {
});
import { renderInto } from "../../../test/render";
-import OptionsSearchPage, { MIN_QUERY_LENGTH } from "./search_page";
+import OptionsSearchPage, { hasSearchTerms, MIN_QUERY_LENGTH } from "./search_page";
+
+describe("hasSearchTerms", () => {
+ it("waits for a word worth looking for, whatever space is typed around it", () => {
+ expect(hasSearchTerms("")).toBe(false);
+ expect(hasSearchTerms(" ")).toBe(false);
+ expect(hasSearchTerms("th")).toBe(false);
+ expect(hasSearchTerms(" th ")).toBe(false);
+
+ expect(hasSearchTerms("the")).toBe(true);
+ expect(hasSearchTerms(" theme ")).toBe(true);
+ });
+});
function fakePage(noteId: string, title: string) {
return { noteId, title, getIcon: () => "bx bx-cog" } as unknown as FNote;
diff --git a/apps/client/src/widgets/type_widgets/options/search_page.tsx b/apps/client/src/widgets/type_widgets/options/search_page.tsx
index 252f8270f5..815bb1ad13 100644
--- a/apps/client/src/widgets/type_widgets/options/search_page.tsx
+++ b/apps/client/src/widgets/type_widgets/options/search_page.tsx
@@ -19,6 +19,14 @@ export const MIN_QUERY_LENGTH = 3;
const DEBOUNCE_MS = 250;
+/**
+ * Whether there is enough typed to search by. Also what tells the mobile flow when to put the
+ * results in the list's place, so that the two agree on when a search has begun.
+ */
+export function hasSearchTerms(query: string) {
+ return query.trim().length >= MIN_QUERY_LENGTH;
+}
+
/**
* Pages the search leaves out. The Content Manager is a tool rather than a set of settings, and
* showing it costs a scan of the database that nobody asked for by typing in a search box.
@@ -36,7 +44,7 @@ const PAGES_LEFT_OUT = new Set([ "_optionsContentManager" ]);
*/
export default function OptionsSearchPage({ query }: { query: string }) {
const settled = useDebouncedValue(query.trim(), DEBOUNCE_MS);
- const filter = settled.length >= MIN_QUERY_LENGTH ? settled : "";
+ const filter = hasSearchTerms(settled) ? settled : "";
const ready = useDeferredMount();
if (!ready) {