mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
fix: memoize formatRelativeTime in thread list to prevent unnecessary re-renders
This commit is contained in:
parent
c2bd2bc935
commit
fc84dcffb0
1 changed files with 7 additions and 2 deletions
|
|
@ -9,7 +9,7 @@ import {
|
||||||
TrashIcon,
|
TrashIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { memo, useCallback, useEffect, useState } from "react";
|
import { memo, useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
|
|
@ -224,6 +224,11 @@ const ThreadListItemComponent = memo(function ThreadListItemComponent({
|
||||||
onUnarchive,
|
onUnarchive,
|
||||||
onDelete,
|
onDelete,
|
||||||
}: ThreadListItemComponentProps) {
|
}: ThreadListItemComponentProps) {
|
||||||
|
const relativeTime = useMemo(
|
||||||
|
() => formatRelativeTime(new Date(thread.updatedAt)),
|
||||||
|
[thread.updatedAt]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -237,7 +242,7 @@ const ThreadListItemComponent = memo(function ThreadListItemComponent({
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<p className="truncate text-sm font-medium">{thread.title || "New Chat"}</p>
|
<p className="truncate text-sm font-medium">{thread.title || "New Chat"}</p>
|
||||||
<p className="truncate text-xs text-muted-foreground">
|
<p className="truncate text-xs text-muted-foreground">
|
||||||
{formatRelativeTime(new Date(thread.updatedAt))}
|
{relativeTime}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue