mirror of
https://github.com/block/buzz.git
synced 2026-11-04 16:31:38 +00:00
feat(desktop): show activity timestamps on demand (#1506)
Signed-off-by: Taylor Ho <taylorkmho@gmail.com> Co-authored-by: npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w <52a228d6edf316ec6812ac3c9fc0d696ab59fc7954d77e7be31eedcddf91335b@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import * as React from "react";
|
||||
|
||||
/**
|
||||
* User preference for showing a timestamp under each activity row — polished
|
||||
* transcript rows and raw JSON-RPC cards alike. Persisted in localStorage and
|
||||
* shared across every transcript surface, same as the animation preference.
|
||||
* This is a device-level UI preference, not workspace-scoped data, so it is
|
||||
* intentionally not reset on workspace switch. Defaults off to keep the feed
|
||||
* compact.
|
||||
*/
|
||||
const STORAGE_KEY = "buzz:show-transcript-timestamps";
|
||||
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
let timestampsEnabled = readStoredPreference();
|
||||
|
||||
function readStoredPreference(): boolean {
|
||||
if (typeof window === "undefined") {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return window.localStorage.getItem(STORAGE_KEY) === "1";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function subscribe(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
function getSnapshot(): boolean {
|
||||
return timestampsEnabled;
|
||||
}
|
||||
|
||||
function getServerSnapshot(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Update the preference and notify all subscribed components. */
|
||||
export function setTranscriptTimestampsEnabled(enabled: boolean): void {
|
||||
timestampsEnabled = enabled;
|
||||
|
||||
try {
|
||||
window.localStorage.setItem(STORAGE_KEY, enabled ? "1" : "0");
|
||||
} catch {
|
||||
// Persistence is best-effort; the in-memory value still applies.
|
||||
}
|
||||
|
||||
for (const listener of listeners) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether polished activity rows should show a timestamp footer. */
|
||||
export function useTranscriptTimestampsEnabled(): boolean {
|
||||
return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
||||
}
|
||||
Reference in New Issue
Block a user