Skip to content

Build your personal knowledge base with Trilium Notes

feat(mobile): list the workspaces as cards in the tree

Elian Dorane4778c9e4013
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index e0745a20c7..d096bc53d4 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2863,6 +2863,7 @@
"children_count_one": "{{count}} note",
"children_count_other": "{{count}} notes",
"children_hidden": "Child notes are hidden from the tree",
+ "workspaces": "Workspaces",
"add_child": "Add child note",
"more_actions": "More actions"
},
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
index e4bacaa923..a5f29389c6 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
@@ -35,16 +35,54 @@
}
.mobile-navigator-workspaces {
- display: flex;
- flex-wrap: wrap;
- gap: 8px;
- padding: 10px 16px 2px;
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
+ gap: 10px;
+ margin-inline: var(--navigator-group-inset);
+
+ & + .mobile-navigator-current-tile {
+ margin-block-start: var(--navigator-group-spacing);
+ }
}
.mobile-navigator-workspace {
- --badge-radius: 12px;
- --color: var(--input-background-color);
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 8px;
+ min-width: 0;
+ padding: 16px 8px 12px;
+ border-radius: var(--navigator-group-radius);
+ background: var(--navigator-group-background);
color: var(--main-text-color);
+ cursor: pointer;
+ user-select: none;
+ -webkit-tap-highlight-color: transparent;
+
+ &:active {
+ background-image: linear-gradient(var(--navigator-pressed-background), var(--navigator-pressed-background));
+ }
+}
+
+.mobile-navigator-workspace-icon {
+ display: grid;
+ place-items: center;
+ width: 52px;
+ height: 52px;
+ border-radius: 14px;
+ font-size: 2.2em;
+
+ .has-color & {
+ background: var(--color);
+ }
+}
+
+.mobile-navigator-workspace-title {
+ max-width: 100%;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ font-size: 0.9em;
}
.mobile-navigator-hoisted-badge .text {
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx
index 13fb9997ee..899d1f83e2 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx
@@ -10,7 +10,7 @@ import search from "../../services/search";
import { buildNote, buildNotes } from "../../test/easy-froca";
import { renderInto } from "../../test/render";
import { ParentComponent } from "../react/react_utils";
-import { getListedChildCount, TitleWithIndicators, WorkspaceBadges } from "./MobileNoteNavigator";
+import { getListedChildCount, TitleWithIndicators, WorkspaceCards } from "./MobileNoteNavigator";
vi.mock("../../services/i18n", () => ({
t: (key: string, options?: object) => (options ? `${key} ${JSON.stringify(options)}` : key),
@@ -95,7 +95,7 @@ describe("TitleWithIndicators", () => {
});
});
-describe("WorkspaceBadges", () => {
+describe("WorkspaceCards", () => {
it("lists the workspaces and hoists the tab into the one tapped", async () => {
const workspace = buildNote({ title: "Work", "#workspace": "", "#workspaceIconClass": "bx bx-briefcase" });
const searchForNotes = vi.spyOn(search, "searchForNotes").mockResolvedValue([ workspace ]);
@@ -108,7 +108,7 @@ describe("WorkspaceBadges", () => {
await act(async () => {
container = renderInto(
<ParentComponent.Provider value={parent}>
- <WorkspaceBadges />
+ <WorkspaceCards />
</ParentComponent.Provider>
);
});
@@ -116,11 +116,12 @@ describe("WorkspaceBadges", () => {
// The search resolves after the effect that starts it.
await act(async () => {});
expect(searchForNotes).toHaveBeenCalledWith("#workspace #!template");
- const badges = [ ...container.querySelectorAll(".mobile-navigator-workspace") ];
- expect(badges.map((badge) => badge.textContent)).toEqual([ "Work" ]);
- expect(badges[0]?.querySelector(".bx-briefcase")).not.toBeNull();
+ expect(container.querySelector(".mobile-navigator-workspaces-label")?.textContent).toBe("mobile_note_navigator.workspaces");
+ const cards = [ ...container.querySelectorAll(".mobile-navigator-workspaces .mobile-navigator-workspace") ];
+ expect(cards.map((card) => card.textContent)).toEqual([ "Work" ]);
+ expect(cards[0]?.querySelector(".mobile-navigator-workspace-icon.bx-briefcase")).not.toBeNull();
- (badges[0] as HTMLElement | undefined)?.click();
+ (cards[0] as HTMLElement | undefined)?.click();
expect(triggerCommand).toHaveBeenCalledWith("hoistNote", { noteId: workspace.noteId });
});
});
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
index 8680f1f13b..a0cb90ba71 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
@@ -265,7 +265,7 @@ export default function MobileNoteNavigator() {
<div ref={scrollRef} className={clsx("mobile-navigator-scroll", showInitialLoader && "is-pending")}>
<div ref={bodyRef} className="mobile-navigator-body">
- {!isHoisted && currentParentId === "root" && <WorkspaceBadges />}
+ {!isHoisted && currentParentId === "root" && <WorkspaceCards />}
{parentNote && (
<div
className={clsx("mobile-navigator-current-tile", parentColorClass, {
@@ -408,9 +408,10 @@ function HoistedNoteBadge({ hoistedNoteId }: { hoistedNoteId: string }) {
/**
* The workspace notes, as the empty tab lists them, for the root column of a tab that is not
- * hoisted. Tapping one hoists the tab into it.
+ * hoisted: a heading and a grid of cards, each with the workspace's icon over its title.
+ * Tapping one hoists the tab into it.
*/
-export function WorkspaceBadges() {
+export function WorkspaceCards() {
const [ workspaceNotes, setWorkspaceNotes ] = useState<FNote[]>([]);
const parentComponent = useContext(ParentComponent);
@@ -425,36 +426,47 @@ export function WorkspaceBadges() {
if (!workspaceNotes.length) return null;
return (
- <div className="mobile-navigator-workspaces">
- {workspaceNotes.map((workspaceNote) => (
- <WorkspaceBadge
- key={workspaceNote.noteId}
- note={workspaceNote}
- onClick={() => parentComponent?.triggerCommand("hoistNote", { noteId: workspaceNote.noteId })}
- />
- ))}
- </div>
+ <>
+ <div className="mobile-navigator-children-label mobile-navigator-workspaces-label">
+ {t("mobile_note_navigator.workspaces")}
+ </div>
+ <div className="mobile-navigator-workspaces">
+ {workspaceNotes.map((workspaceNote) => (
+ <WorkspaceCard
+ key={workspaceNote.noteId}
+ note={workspaceNote}
+ onClick={() => parentComponent?.triggerCommand("hoistNote", { noteId: workspaceNote.noteId })}
+ />
+ ))}
+ </div>
+ </>
);
}
-function WorkspaceBadge({ note, onClick }: { note: FNote, onClick: () => void }) {
+function WorkspaceCard({ note, onClick }: { note: FNote, onClick: () => void }) {
const icon = useNoteIcon(note);
const [ workspaceIconClass ] = useNoteLabel(note, "workspaceIconClass");
const [ workspaceColor ] = useNoteLabel(note, "workspaceTabBackgroundColor");
const title = useNoteTitle(note.noteId, undefined);
return (
- <Badge
- className="mobile-navigator-workspace"
- icon={workspaceIconClass || icon}
- text={title ?? note.title}
+ <div
+ className={clsx("mobile-navigator-workspace", { "has-color": !!workspaceColor })}
+ role="button"
+ tabIndex={0}
onClick={onClick}
- style={workspaceColorStyle(workspaceColor)}
- />
+ >
+ <Icon
+ icon={workspaceIconClass || icon}
+ className="mobile-navigator-workspace-icon"
+ style={workspaceColorStyle(workspaceColor)}
+ />
+ <span className="mobile-navigator-workspace-title">{title ?? note.title}</span>
+ </div>
);
}
-/** Paints a badge in the workspace's `#workspaceTabBackgroundColor`, with a text color readable on it. */
+/** Paints an element in the workspace's `#workspaceTabBackgroundColor`, with a text color readable on it. */
function workspaceColorStyle(workspaceColor: string | null | undefined) {
if (!workspaceColor) return undefined;
return { "--color": workspaceColor, "color": getReadableTextColor(workspaceColor) } as Record<string, string>;