2024-07-05 14:36:50 +08:00
|
|
|
import { Clock, Edit, Share, Trash } from "lucide-react";
|
|
|
|
import { Message } from "./ChatWindow";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { formatTimeDifference } from "@/lib/utils";
|
2024-04-09 19:10:15 +05:30
|
|
|
|
|
|
|
const Navbar = ({ messages }: { messages: Message[] }) => {
|
2024-07-05 14:36:50 +08:00
|
|
|
const [title, setTitle] = useState<string>("");
|
|
|
|
const [timeAgo, setTimeAgo] = useState<string>("");
|
2024-04-09 19:10:15 +05:30
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (messages.length > 0) {
|
|
|
|
const newTitle =
|
2024-07-05 15:49:43 +08:00
|
|
|
messages[0].content.length > 20 ? `${messages[0].content.slice(0, 20).trim()}...` : messages[0].content;
|
2024-04-09 19:10:15 +05:30
|
|
|
setTitle(newTitle);
|
2024-07-05 14:36:50 +08:00
|
|
|
const newTimeAgo = formatTimeDifference(new Date(), messages[0].createdAt);
|
2024-04-09 19:10:15 +05:30
|
|
|
setTimeAgo(newTimeAgo);
|
|
|
|
}
|
|
|
|
}, [messages]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const intervalId = setInterval(() => {
|
|
|
|
if (messages.length > 0) {
|
2024-07-05 14:36:50 +08:00
|
|
|
const newTimeAgo = formatTimeDifference(new Date(), messages[0].createdAt);
|
2024-04-09 19:10:15 +05:30
|
|
|
setTimeAgo(newTimeAgo);
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
return () => clearInterval(intervalId);
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, []);
|
2024-04-09 16:21:05 +05:30
|
|
|
|
|
|
|
return (
|
2024-05-28 07:30:28 +08:00
|
|
|
<div className="fixed z-40 top-0 left-0 right-0 px-4 lg:pl-[104px] lg:pr-6 lg:px-8 flex flex-row items-center justify-between w-full py-4 text-sm text-black dark:text-white/70 border-b bg-light-primary dark:bg-dark-primary border-light-100 dark:border-dark-200">
|
2024-07-05 14:36:50 +08:00
|
|
|
<Edit size={17} className="active:scale-95 transition duration-100 cursor-pointer lg:hidden" />
|
2024-04-18 17:47:51 +05:30
|
|
|
<div className="hidden lg:flex flex-row items-center justify-center space-x-2">
|
2024-04-09 16:21:05 +05:30
|
|
|
<Clock size={17} />
|
2024-04-09 19:10:15 +05:30
|
|
|
<p className="text-xs">{timeAgo} ago</p>
|
2024-04-09 16:21:05 +05:30
|
|
|
</div>
|
2024-04-09 19:10:15 +05:30
|
|
|
<p className="hidden lg:flex">{title}</p>
|
2024-05-28 10:48:58 +08:00
|
|
|
|
2024-05-29 14:31:42 +08:00
|
|
|
<div className="flex flex-row items-center space-x-4">
|
2024-07-05 14:36:50 +08:00
|
|
|
<Share size={17} className="active:scale-95 transition duration-100 cursor-pointer" />
|
|
|
|
<Trash size={17} className="text-red-400 active:scale-95 transition duration-100 cursor-pointer" />
|
2024-04-09 16:21:05 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Navbar;
|