feat: newest message first, Raycast-style conversation sidebar (#7)
This commit was merged in pull request #7.
This commit is contained in:
@@ -29,6 +29,27 @@ export function formatRelativeTime(timestamp: number, now: number = Date.now()):
|
||||
return new Date(timestamp).toLocaleDateString(undefined, { month: "short", day: "numeric" });
|
||||
}
|
||||
|
||||
export type RecencyGroup = "Today" | "Yesterday" | "This week" | "Older";
|
||||
|
||||
/**
|
||||
* Buckets a timestamp for the conversation sidebar.
|
||||
*
|
||||
* Raycast groups its sidebar this way, and it buys the grouping that per-row
|
||||
* timestamps were trying to convey — without putting a timestamp on every row.
|
||||
*/
|
||||
export function recencyGroup(timestamp: number, now: number = Date.now()): RecencyGroup {
|
||||
const startOfToday = new Date(now);
|
||||
startOfToday.setHours(0, 0, 0, 0);
|
||||
const start = startOfToday.getTime();
|
||||
|
||||
const DAY = 86_400_000;
|
||||
|
||||
if (timestamp >= start) return "Today";
|
||||
if (timestamp >= start - DAY) return "Yesterday";
|
||||
if (timestamp >= start - 7 * DAY) return "This week";
|
||||
return "Older";
|
||||
}
|
||||
|
||||
/** Pulls a human-readable message out of anything that can be thrown. */
|
||||
export function errorMessage(error: unknown): string {
|
||||
if (error instanceof Error) return error.message;
|
||||
|
||||
Reference in New Issue
Block a user