feat(webui): refine mobile message actions and hover timestamps
This commit is contained in:
1 parent
4693bba81f
commit
7aac9355ec
10 files changed
+334
-73
No files matched your search
@@ -83,6 +83,7 @@ const RELATIVE_THRESHOLDS: [number, Intl.RelativeTimeFormatUnit][] = [
|
||||
const relativeTimeFormatters = new Map<string, Intl.RelativeTimeFormat>();
|
||||
const dateTimeFormatters = new Map<string, Intl.DateTimeFormat>();
|
||||
const clockTimeFormatters = new Map<string, Intl.DateTimeFormat>();
|
||||
const hoverTimeFormatters = new Map<string, Intl.DateTimeFormat>();
|
||||
|
||||
function activeLocale(locale?: string): string {
|
||||
return locale || i18n.resolvedLanguage || i18n.language || currentLocale();
|
||||
@@ -167,6 +168,27 @@ export function formatMessageEndTime(
|
||||
: dateTimeFormatter(loc).format(date);
|
||||
}
|
||||
|
||||
/** One-line gutter label; the full local date/time belongs in its tooltip. */
|
||||
export function formatMessageHoverTime(
|
||||
value: number | null | undefined,
|
||||
locale?: string,
|
||||
now = new Date(),
|
||||
): string {
|
||||
const date = parseDate(value);
|
||||
if (!date) return "";
|
||||
const loc = activeLocale(locale);
|
||||
const today = isSameLocalCalendarDay(date, now);
|
||||
const key = `${loc}:${today ? "clock" : "date"}`;
|
||||
let formatter = hoverTimeFormatters.get(key);
|
||||
if (!formatter) {
|
||||
formatter = new Intl.DateTimeFormat(loc, today
|
||||
? { hour: "2-digit", minute: "2-digit", hourCycle: "h23" }
|
||||
: { month: "numeric", day: "numeric" });
|
||||
hoverTimeFormatters.set(key, formatter);
|
||||
}
|
||||
return formatter.format(date);
|
||||
}
|
||||
|
||||
/** Human-readable turn duration (wall-clock), locale-aware via ``Intl`` (seconds/minutes). */
|
||||
export function formatTurnLatency(ms: number, locale?: string): string {
|
||||
const loc = activeLocale(locale);
|
||||
|
||||
Reference in new issue
Block a user