Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(mobile): mark protected notes in the tree as on desktop
Elian Doran486ad950dce9
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 033b092719..f6c58066b3 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -2140,8 +2140,9 @@ pre.code-embed-editor > .cm-editor:not(.cm-focused) {}#mobile-sidebar-wrapper {+ --navigator-backdrop: var(--left-pane-background-color);transform: none !important;- background-color: var(--left-pane-background-color) !important;+ background-color: var(--navigator-backdrop) !important;}#mobile-rest-container > #mobile-sidebar-wrapper.left-pane-hidden {diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.cssindex e9abbf815c..bbe8e376e3 100644--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css@@ -363,6 +363,35 @@font-size: 1.2em;}+.mobile-navigator-row-icon.is-protected,+.mobile-navigator-current-icon.is-protected {+ position: relative;++ &::after {+ position: absolute;+ inset-block-end: 0;+ inset-inline-end: 0;+ font-family: "boxicons";+ font-size: 0.7em;+ content: "\eb4a";+ transform: translateX(25%);+ color: var(--quick-search-result-highlight-color);+ background:+ linear-gradient(var(--navigator-group-background) 0 0),+ var(--navigator-backdrop, var(--main-background-color));+ border-radius: 50%;+ }+}++body[dir=rtl] :is(.mobile-navigator-row-icon, .mobile-navigator-current-icon).is-protected::after {+ transform: translateX(-25%);+}++.mobile-navigator-title-group .is-locked {+ font-style: italic;+ opacity: 0.75;+}+.mobile-navigator-row-title {flex: 0 1 auto;overflow: hidden;diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsxindex c9fea6044e..adb87d54b8 100644--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx@@ -91,7 +91,7 @@ describe("TitleWithIndicators", () => {}/** Renders the title under a parent component that collects the reload handlers. */- function mount(note: FNote) {+ function mount(note: FNote, parentNoteId?: string) {const handlers: ((data: unknown) => void)[] = [];const parent = {componentId: "cid",@@ -104,7 +104,7 @@ describe("TitleWithIndicators", () => {act(() => {container = renderInto(<ParentComponent.Provider value={parent}>- <TitleWithIndicators note={note} title={note.title} className="title" />+ <TitleWithIndicators note={note} parentNoteId={parentNoteId} title={note.title} className="title" /></ParentComponent.Provider>);});@@ -136,6 +136,32 @@ describe("TitleWithIndicators", () => {expect(clone?.getAttribute("aria-label")).toContain("Second");expect(container.querySelector(".shared-indicator")).not.toBeNull();});++ it("replaces a protected note's title but not its prefix while the protected session is closed", () => {+ buildNote({ id: "vault", title: "Vault", children: [ { id: "secret", title: "Secret" } ] });+ const note = froca.notes["secret"];+ const branch = froca.branches[note?.parentToBranch["vault"] ?? ""];+ if (!note || !branch) throw new Error("expected the note and its branch");+ note.isProtected = true;+ const { isProtectedSessionAvailable } = glob;+ try {+ glob.isProtectedSessionAvailable = false;+ const locked = mount(note).container.querySelector(".title");+ expect(locked?.textContent).toBe("protected_session.locked_note_title");+ expect(locked?.querySelector(".is-locked")).not.toBeNull();++ branch.prefix = "2024";+ expect(mount(note, "vault").container.querySelector(".title")?.textContent)+ .toBe("2024 - protected_session.locked_note_title");++ glob.isProtectedSessionAvailable = true;+ const unlocked = mount(note).container.querySelector(".title");+ expect(unlocked?.textContent).toBe("Secret");+ expect(unlocked?.querySelector(".is-locked")).toBeNull();+ } finally {+ glob.isProtectedSessionAvailable = isProtectedSessionAvailable;+ }+ });});describe("WorkspaceCards", () => {diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsxindex 385a4637f3..80d7362e31 100644--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx@@ -325,8 +325,11 @@ export default function MobileNoteNavigator() {{...currentContextProps}><div className="mobile-navigator-current-header">- <Icon icon={parentIcon ?? "bx bx-folder"} className="mobile-navigator-current-icon" />- <TitleWithIndicators note={parentNote} title={parentTitle ?? parentNote.title} className="mobile-navigator-current-title" />+ <Icon+ icon={parentIcon ?? "bx bx-folder"}+ className={clsx("mobile-navigator-current-icon", parentNote.isProtected && "is-protected")}+ />+ <TitleWithIndicators note={parentNote} parentNoteId={grandparentId} title={parentTitle ?? parentNote.title} className="mobile-navigator-current-title" /><buttontype="button"className="mobile-navigator-current-action"@@ -671,8 +674,11 @@ function NavigatorRow({ note, parentNoteId, childNotePath, isActive, isPending,onClick={isPending ? undefined : () => (hasChildren ? onDrill(childNotePath) : onOpen(childNotePath))}{...contextProps}>- <Icon icon={icon ?? "bx bx-note"} className="mobile-navigator-row-icon" />- <TitleWithIndicators note={note} title={title} className="mobile-navigator-row-title" />+ <Icon+ icon={icon ?? "bx bx-note"}+ className={clsx("mobile-navigator-row-icon", note.isProtected && "is-protected")}+ />+ <TitleWithIndicators note={note} parentNoteId={parentNoteId} title={title} className="mobile-navigator-row-title" />{showHiddenBadge && (<spanclassName="mobile-navigator-row-hidden-badge"@@ -695,15 +701,23 @@ function NavigatorRow({ note, parentNoteId, childNotePath, isActive, isPending,/*** A note's title followed by the clone and share icons the desktop tree shows. The title- * shortens with an ellipsis, so the icons stay visible next to it.+ * shortens with an ellipsis, so the icons stay visible next to it. Until the protected session+ * starts, a protected note shows a placeholder after its branch prefix instead of its title.*/-export function TitleWithIndicators({ note, title, className }: { note: FNote, title: string, className: string }) {+export function TitleWithIndicators({ note, parentNoteId, title, className }: {+ note: FNote,+ parentNoteId: string | undefined,+ title: string,+ className: string+}) {const [ isShared ] = useShareState(note);const realParents = useRealParentNotes(note);return (<span className="mobile-navigator-title-group">- <span className={className}>{title}</span>+ <span className={className}>+ {note.isContentAvailable() ? title : <LockedTitle note={note} parentNoteId={parentNoteId} />}+ </span>{realParents.length > 1 && (<Iconicon="bx bxs-directions"@@ -724,6 +738,16 @@ export function TitleWithIndicators({ note, title, className }: { note: FNote, t);}+function LockedTitle({ note, parentNoteId }: { note: FNote, parentNoteId: string | undefined }) {+ const prefix = parentNoteId ? froca.getBranch(note.parentToBranch[parentNoteId], true)?.prefix : undefined;+ return (+ <>+ {prefix && `${prefix} - `}+ <span className="is-locked">{t("protected_session.locked_note_title")}</span>+ </>+ );+}+/** The real parents of `note`, read again when one of its branches changes. */function useRealParentNotes(note: FNote) {const [ realParents, setRealParents ] = useState(() => note.getRealParentNotes());