mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-03 15:03:27 +00:00
feat: improve thread date formatting with relative time display (#130)
* Apply patch * Apply patch * Apply patch * formatting
This commit is contained in:
parent
13518b7269
commit
8ea2540032
1 changed files with 28 additions and 4 deletions
|
|
@ -1,5 +1,11 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { memo } from "react";
|
import { memo } from "react";
|
||||||
|
import {
|
||||||
|
formatDistanceToNow,
|
||||||
|
differenceInHours,
|
||||||
|
differenceInMinutes,
|
||||||
|
format,
|
||||||
|
} from "date-fns";
|
||||||
import { GitBranch, ArrowRight, ListTodo } from "lucide-react";
|
import { GitBranch, ArrowRight, ListTodo } from "lucide-react";
|
||||||
import { ThreadWithTasks, useThreads } from "@/providers/Thread";
|
import { ThreadWithTasks, useThreads } from "@/providers/Thread";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
@ -14,6 +20,27 @@ interface ThreadItemProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatRelativeDate(dateString: string): string {
|
||||||
|
const date = new Date(dateString);
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
const minutesAgo = differenceInMinutes(now, date);
|
||||||
|
const hoursAgo = differenceInHours(now, date);
|
||||||
|
|
||||||
|
// Within the last hour - show minutes ago
|
||||||
|
if (minutesAgo < 60) {
|
||||||
|
return `${minutesAgo} min ago`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Between 1-24 hours ago - show hours ago
|
||||||
|
if (hoursAgo < 24) {
|
||||||
|
return `${hoursAgo} hour${hoursAgo === 1 ? "" : "s"} ago`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// More than 24 hours ago - show month, day format
|
||||||
|
return format(date, "MMM do");
|
||||||
|
}
|
||||||
|
|
||||||
export const ThreadItem = memo(function ThreadItem({
|
export const ThreadItem = memo(function ThreadItem({
|
||||||
thread,
|
thread,
|
||||||
onClick,
|
onClick,
|
||||||
|
|
@ -26,10 +53,7 @@ export const ThreadItem = memo(function ThreadItem({
|
||||||
const isSidebar = variant === "sidebar";
|
const isSidebar = variant === "sidebar";
|
||||||
const isRecentlyUpdated = recentlyUpdatedThreads.has(thread.thread_id);
|
const isRecentlyUpdated = recentlyUpdatedThreads.has(thread.thread_id);
|
||||||
|
|
||||||
const displayDate = new Date(thread.created_at).toLocaleDateString("en-US", {
|
const displayDate = formatRelativeDate(thread.created_at);
|
||||||
month: "short",
|
|
||||||
day: "numeric",
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue