fix: improve session management and UI highlights
This commit is contained in:
30
lib/utils/formatDate.ts
Normal file
30
lib/utils/formatDate.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export function formatRelativeTime(dateStr: string): string {
|
||||
const date = new Date(dateStr)
|
||||
const now = new Date()
|
||||
const diffMs = now.getTime() - date.getTime()
|
||||
const diffMin = Math.floor(diffMs / 60000)
|
||||
const diffHr = Math.floor(diffMin / 60)
|
||||
const diffDay = Math.floor(diffHr / 24)
|
||||
|
||||
if (diffMin < 1) return 'Just now'
|
||||
if (diffMin < 60) return `${diffMin}m ago`
|
||||
if (diffHr < 24) return `${diffHr}h ago`
|
||||
if (diffDay < 7) return `${diffDay}d ago`
|
||||
|
||||
return date.toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: date.getFullYear() !== now.getFullYear() ? 'numeric' : undefined,
|
||||
})
|
||||
}
|
||||
|
||||
export function formatFullDate(dateStr: string): string {
|
||||
return new Date(dateStr).toLocaleString('en-US', {
|
||||
weekday: 'short',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: 'numeric',
|
||||
minute: '2-digit',
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
/**
|
||||
* Request ID utilities for tracing API calls across services
|
||||
* Request IDs help debug issues by correlating logs across frontend and backends
|
||||
*
|
||||
* IMPORTANT: This module stores mutable state (lastRequestId) at module scope.
|
||||
* This is safe because apiRequest (the only caller) runs exclusively in the
|
||||
* browser where JS is single-threaded. If this ever needs server-side use,
|
||||
* replace the module variable with AsyncLocalStorage.
|
||||
*/
|
||||
|
||||
const REQUEST_ID_HEADER = 'X-Request-ID'
|
||||
@@ -23,7 +28,8 @@ export function getRequestIdHeader(): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the last request ID for error reporting
|
||||
* Store the last request ID for error reporting.
|
||||
* Browser-only — single-threaded, no concurrency risk.
|
||||
*/
|
||||
let lastRequestId: string | null = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user