tahamajs/IE / Projects /front /src /components /messages /ForwardModal.tsx
tahamajs's picture
download
raw
3.59 kB
import { useState, useMemo } from "react";
import { ChatItem, Conversation, Group } from "@/types";
import { Search, Users } from "lucide-react";
interface ForwardModalProps {
isOpen: boolean;
onClose: () => void;
chats: ChatItem[];
onForward: (targetChat: ChatItem) => void;
}
export function ForwardModal({ isOpen, onClose, chats, onForward }: ForwardModalProps) {
const [search, setSearch] = useState("");
const filtered = useMemo(() => {
if (!search.trim()) return chats;
const lower = search.toLowerCase();
return chats.filter((chat) => {
const name =
chat.type === "private"
? (chat as Conversation).with
: (chat as Group).name;
return name?.toLowerCase().includes(lower);
});
}, [chats, search]);
if (!isOpen) return null;
return (
<div
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
onClick={onClose}
>
<div
className="bg-white dark:bg-gray-800 rounded-2xl w-full max-w-sm p-4 shadow-2xl animate-in zoom-in-95"
onClick={(e) => e.stopPropagation()}
>
<h3 className="font-bold text-lg mb-3 text-gray-800 dark:text-gray-100">
Forward to…
</h3>
<div className="relative mb-3">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" />
<input
type="text"
placeholder="Search chats"
value={search}
onChange={(e) => setSearch(e.target.value)}
className="w-full pl-9 pr-3 py-2 border rounded-lg dark:bg-gray-700 dark:text-gray-100 focus:ring-2 focus:ring-primary"
autoFocus
/>
</div>
<div className="max-h-64 overflow-y-auto space-y-1">
{filtered.length === 0 ? (
<div className="text-center text-gray-400 py-4">No chats found</div>
) : (
filtered.map((chat) => {
const name =
chat.type === "private"
? (chat as Conversation).with
: (chat as Group).name;
const isGroup = chat.type === "group";
return (
<div
key={
chat.type === "private"
? (chat as Conversation).with
: `g-${(chat as Group).id}`
}
onClick={() => onForward(chat)}
className="flex items-center gap-3 p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg cursor-pointer transition"
>
<div
className={`w-10 h-10 rounded-full flex items-center justify-center text-white text-sm font-bold shadow ${
isGroup
? "bg-linear-to-br from-green-400 to-teal-500"
: "bg-linear-to-br from-primary to-secondary"
}`}
>
{isGroup ? (
<Users className="w-5 h-5" />
) : (
(name?.[0] || "?").toUpperCase()
)}
</div>
<span className="font-medium text-gray-800 dark:text-gray-200">
{name}
</span>
</div>
);
})
)}
</div>
<button
onClick={onClose}
className="mt-3 btn btn-secondary btn-sm w-full rounded-full"
>
Cancel
</button>
</div>
</div>
);
}

Xet Storage Details

Size:
3.59 kB
·
Xet hash:
7fcdeb17246c8b5dc5dbeb3c40d76b7125f27436afc5d877a47879c85e99d480

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.