TUI: display relative time for session updates in picker
Show "just now", "5m ago", "Yesterday" etc. instead of absolute timestamps for better readability in the session picker list.
This commit is contained in:
committed by
Peter Steinberger
parent
ddb7b5c6a4
commit
687c41e838
@@ -39,6 +39,22 @@ type CommandHandlerContext = {
|
||||
formatSessionKey: (key: string) => string;
|
||||
};
|
||||
|
||||
function formatRelativeTime(timestamp: number): string {
|
||||
const now = Date.now();
|
||||
const diff = now - timestamp;
|
||||
const seconds = Math.floor(diff / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const days = Math.floor(hours / 24);
|
||||
|
||||
if (seconds < 60) return "just now";
|
||||
if (minutes < 60) return `${minutes}m ago`;
|
||||
if (hours < 24) return `${hours}h ago`;
|
||||
if (days === 1) return "Yesterday";
|
||||
if (days < 7) return `${days}d ago`;
|
||||
return new Date(timestamp).toLocaleDateString(undefined, { month: "short", day: "numeric" });
|
||||
}
|
||||
|
||||
export function createCommandHandlers(context: CommandHandlerContext) {
|
||||
const {
|
||||
client,
|
||||
@@ -147,7 +163,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
|
||||
return {
|
||||
value: session.key,
|
||||
label: title ? `${title} (${formattedKey})` : formattedKey,
|
||||
description: session.updatedAt ? new Date(session.updatedAt).toLocaleString() : "",
|
||||
description: session.updatedAt ? formatRelativeTime(session.updatedAt) : "",
|
||||
searchText: [
|
||||
session.displayName,
|
||||
session.label,
|
||||
|
||||
Reference in New Issue
Block a user