Sidebar polish round. Menus. `dropdown-menu` and `context-menu` were two copies of one engine that differed only in how the trigger fires — identical from `computePosition` down — and neither could nest. Both are now thin wrappers over `components/ui/menu/`, which owns anchoring, a pure page-stack navigation model, and one presentation fork: flyout on pointer, pushed pages in a sheet on compact. All 31 call sites are unchanged. Items got a rounded inset fill, a visible separator, and `selected` (a check) split from `active` (a fill). Sidebar display preferences. The flat wall of four sections becomes one row per decision with its value, and per-feature toggles over what a workspace row shows: host, pull request, checks, scripts. Each is independent — a ticked toggle that draws nothing is a lie. `display-preferences/` hides that grouping lives in zustand while title source and row items are app settings. Timestamps. "Last activity" now ticks itself. The label rounds to the minute and never shows seconds; past a week it becomes a date. The timer lives in the leaf `<Text>`, at most one per resolution tier shared by every row, and a tick only re-renders when the string actually changed — so a memoized row that legitimately never re-renders still stays current. Colour. Full status tier regenerated at 90% of gamut max (was 85), same rule as the muted tier, lightness and hue untouched. File icons are pulled toward neutral in OKLab behind `getFileIconSvg` — material-icon-theme picks its palette for a tree where the icon is the only colour on the row, and ours is not. New/deleted files use the forge square-plus/square-minus glyphs at muted weight instead of tinted pills. Project icons round a little more; uploaded icons never do. The project status badge is a knockout again: it fills with the colour of the row behind it, so the ring reads as a gap in the icon rather than a white halo. File rows. The always-visible kebab is gone from the file explorer and diff tree in favour of right-click, which also reclaims the reserved action slot.
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { subscribeToRelativeTimeTick, type TickResolution } from "@/utils/relative-time-ticker";
|
|
import { describeCompactTimeAgo } from "@/utils/time";
|
|
|
|
/**
|
|
* A compact relative timestamp that keeps itself current.
|
|
*
|
|
* Call this from the smallest component that renders the text. The state lives there, so a tick
|
|
* re-renders one `<Text>` and nothing above it — the row, the list, and the sidebar are never
|
|
* involved.
|
|
*
|
|
* Two things keep the cost near zero:
|
|
*
|
|
* - **Ticking is not re-rendering.** A tick recomputes the label and only sets state if the
|
|
* string actually changed. A row reading "3d" is woken hourly and re-renders roughly once a
|
|
* day, when it becomes "4d".
|
|
* - **The tier follows the label.** As a timestamp ages the label changes more slowly, so the
|
|
* subscription moves to a slower tier; past a week it unsubscribes for good, because a date
|
|
* never changes again.
|
|
*/
|
|
export function useCompactTimeAgo(date: Date | null): string {
|
|
const [label, setLabel] = useState(() => (date ? describeCompactTimeAgo(date).label : ""));
|
|
|
|
// Keyed on the instant, not the Date object: the store parses a fresh Date on every payload, so
|
|
// depending on identity would tear down and rebuild the subscription for an unchanged time.
|
|
const time = date === null ? null : date.getTime();
|
|
|
|
useEffect(() => {
|
|
if (time === null) {
|
|
setLabel("");
|
|
return undefined;
|
|
}
|
|
|
|
const source = new Date(time);
|
|
let current = describeCompactTimeAgo(source);
|
|
setLabel(current.label);
|
|
|
|
let unsubscribe: (() => void) | null = null;
|
|
|
|
const handleTick = () => {
|
|
const next = describeCompactTimeAgo(source);
|
|
if (next.label !== current.label) {
|
|
setLabel(next.label);
|
|
}
|
|
if (next.resolution !== current.resolution) {
|
|
// Aged into a slower tier — or out of them entirely.
|
|
current = next;
|
|
unsubscribe?.();
|
|
unsubscribe = null;
|
|
attach();
|
|
return;
|
|
}
|
|
current = next;
|
|
};
|
|
|
|
const attach = () => {
|
|
if (current.resolution === "static") return;
|
|
unsubscribe = subscribeToRelativeTimeTick(current.resolution as TickResolution, handleTick);
|
|
};
|
|
|
|
attach();
|
|
return () => {
|
|
unsubscribe?.();
|
|
};
|
|
}, [time]);
|
|
|
|
return label;
|
|
}
|