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
client/space usage tool: format the stats as a grid on mobile
Adorian Doran34fd2d344f92
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 6a93a01143..1dd367a3b1 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3116,6 +3116,10 @@"status_content_hint": "Space held by all notes (hidden ones included), their attachments and their revisions, with duplicated content counted once","status_deleted": "{{size}} in deleted notes and attachments","status_deleted_hint": "Space still held by deleted notes and by deleted attachments (whose note may still exist); erasing them reclaims it",+ "status_notes": "Notes",+ "status_total": "Total",+ "status_attachments": "Attachments",+ "status_deleted_items": "Deleted items","selection_hint": "Tap an item for details","menu_show_details": "Show details","menu_erase_deleted": "Erase deleted data",diff --git a/apps/client/src/widgets/type_widgets/space_usage/index.css b/apps/client/src/widgets/type_widgets/space_usage/index.cssindex e350eaae04..6aadd0db42 100644--- a/apps/client/src/widgets/type_widgets/space_usage/index.css+++ b/apps/client/src/widgets/type_widgets/space_usage/index.css@@ -101,20 +101,12 @@ body.mobile {background: var(--main-background-color);}- /* A figure to a line, rather than two sentences wrapping into each other wherever the width- happens to run out. The gap is between lines now, so it is tightened from the one a row- wanted. */- .space-usage-status {+ /* Where the status line's sentences go on a phone (see StatusGrid): above the map, as the+ line was, and no taller than the figures it holds. */+ .space-usage-status-figures {order: 1;- flex-direction: column;- align-items: center;- gap: 0.15em;- text-align: center;- }-- /* Nothing left to part once the figures are stacked. */- .space-usage-status-separator {- display: none;+ flex: 0 0 auto;+ margin-block: 12px 8px;}/* Sized by the map it holds rather than by what is left of the screen: the page scrolls, so@@ -139,6 +131,63 @@ body.mobile {}}+/* The totals as a grid of figures, two to a row until there is width for all four. Only a phone draws+ it, but how a figure reads is no more about a phone than anything else on the page, so the look sits+ here and the placing stays in the block above with the rest of what a phone moves.++ The row measures itself against the element around it, which carries nothing else: a container+ cannot answer its own query, so the two are separate elements rather than one. Flex rather than+ columns, because how many go on a line is then a basis the cells can be given. */+.space-usage-status-figures {+ container-type: inline-size;+}++.space-usage-status-grid {+ display: flex;+ flex-wrap: wrap;+ justify-content: center;+ gap: 10px 16px;+}++.space-usage-status-cell {+ display: flex;+ flex-direction: column;+ /* Half a line less its share of the gap, so exactly two sit on one. */+ flex: 1 1 calc(50% - 8px);+ min-width: 0;+}++/* Room enough for all four: one row, each cell no wider than what it holds, the four set about the+ middle of the row rather than spread across it. The gap opens up with them, or four cells that have+ stopped filling the row read as one crowded block.++ What is centred is the row, not what is written in it: inside a cell the label and the figure keep+ to the writing direction, as they do on every other line of the page. */+@container (min-width: 600px) {+ .space-usage-status-grid {+ column-gap: 48px;+ }++ .space-usage-status-cell {+ flex: 0 1 auto;+ }+}++/* What the figure is of, said quietly: it is read once, and the figure under it every time. */+.space-usage-status-label {+ color: var(--muted-text-color);+ font-size: 0.85em;+}++/* The same size and weight the selection strip gives a note's name, the other figure a phone reads+ off this page. */+.space-usage-status-value {+ margin-top: -0.1em;+ font-size: 1.35em;+ font-weight: 500;+ white-space: nowrap;+}+/* The bucket cells stand for no single note but for a crowd of them: the diagonal stripes set themapart from the solid note cells without spending a hue (user themes make any fixed paletteunreliable), their hover tooltip says which crowd, and they respond to nothing.diff --git a/apps/client/src/widgets/type_widgets/space_usage/index.tsx b/apps/client/src/widgets/type_widgets/space_usage/index.tsxindex c856e46e62..a91fb238ca 100644--- a/apps/client/src/widgets/type_widgets/space_usage/index.tsx+++ b/apps/client/src/widgets/type_widgets/space_usage/index.tsx@@ -19,12 +19,13 @@ import SelectionStrip, { type SpaceUsageSelection } from "./selection";const OVERVIEW_LIMIT = 500;/**- * Whether a tap on a mark names it rather than acting on it. A touch screen has no hover to identify- * a cell or a segment with, so there the charts keep a selection and the strip along the foot of the- * page says what is chosen; a pointer needs none of that and keeps its hover and its right-click.- * Read once, as the app's other phone branches do.+ * What a phone gets instead: the charts keep a selection, named by the strip along the foot of the+ * page, since a touch screen has no way to ask what a cell or a segment is; and the totals are a grid+ * of figures rather than the line of sentences there is no width for. A pointer needs neither and+ * keeps its hover, its right-click and its status line. Read once, as the app's other phone branches+ * do.*/-const TAP_SELECTS = isMobile();+const IS_MOBILE = isMobile();type SpaceUsageView = "overview" | "browse";@@ -112,7 +113,7 @@ export default function SpaceUsage() {refreshToken={refreshToken}onContentChanged={refresh}selectedMarkId={selection?.markId}- onSelect={TAP_SELECTS ? select : undefined}+ onSelect={IS_MOBILE ? select : undefined}onLoadingChange={setBrowseLoading}/>)}@@ -120,7 +121,7 @@ export default function SpaceUsage() {? <Overviewoverview={overview}selectedMarkId={selection?.markId}- onSelect={TAP_SELECTS ? select : undefined}+ onSelect={IS_MOBILE ? select : undefined}onShowDetails={showDetails}onContentChanged={refresh}/>@@ -128,8 +129,9 @@ export default function SpaceUsage() {{/* Overview only: these are whole-database totals, and beside a single note's donutthey would read as being about that note. */}- {view === "overview" && overview && (- <footer className="space-usage-status">+ {view === "overview" && overview && (IS_MOBILE+ ? <StatusGrid overview={overview} />+ : <footer className="space-usage-status"><StatusEntry// Revisions are left out: they carry their own cell on the map, which names// their size, so repeating it here would only lengthen the line.@@ -149,12 +151,11 @@ export default function SpaceUsage() {})}hint={t("space_usage.status_deleted_hint")}/>- </footer>- )}+ </footer>)}{/* Kept on show with nothing chosen as well, so the map is laid out with room for itfrom the start and a tap always has somewhere to report to. */}- {TAP_SELECTS && <SelectionStrip selection={selection} containerRef={stripRef} />}+ {IS_MOBILE && <SelectionStrip selection={selection} containerRef={stripRef} />}</div>);}@@ -176,6 +177,53 @@ function StatusEntry({ text, hint }: { text: string, hint: string }) {return <span ref={ref}>{text}</span>;}+/**+ * The whole-database totals as a grid of figures: the same numbers the status line carries as+ * sentences, in the shape a phone has the width for. Every figure is at rest, so each is formatted to+ * read rather than to hold still under a counter.+ */+function StatusGrid({ overview }: { overview: SpaceUsageOverviewResponse }) {+ const { content, deletedNotes } = overview;++ return (+ // The outer element is nothing but the container the row measures itself against: an element+ // cannot answer its own container query, so what changes shape has to sit inside what is+ // being measured.+ <div className="space-usage-status-figures">+ <div className="space-usage-status-grid">+ <StatusFigure+ label={t("space_usage.status_notes")}+ value={content.noteCount.toLocaleString()}+ />+ <StatusFigure+ label={t("space_usage.status_total")}+ value={formatSize(content.size)}+ />+ {/* Part of the total beside it rather than another slice of the database: what the+ notes counted above carry along with their own bodies. */}+ <StatusFigure+ label={t("space_usage.status_attachments")}+ value={formatSize(content.attachmentsSize)}+ />+ <StatusFigure+ label={t("space_usage.status_deleted_items")}+ value={formatSize(deletedNotes.size)}+ />+ </div>+ </div>+ );+}++/** One cell of it: what is being counted, small and quiet, over the figure that is the point of it. */+function StatusFigure({ label, value }: { label: string, value: string }) {+ return (+ <div className="space-usage-status-cell">+ <span className="space-usage-status-label">{label}</span>+ <span className="space-usage-status-value">{value}</span>+ </div>+ );+}+const VIEWS: { value: SpaceUsageView, label: string }[] = [{ value: "overview", label: t("space_usage.view_overview") },{ value: "browse", label: t("space_usage.view_browse") }