import { ActionIcon, Box, Paper, Textarea, Tooltip } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; import { IconEye, IconEyeOff, IconTrash } from "@tabler/icons-react"; import { useEffect, useMemo, useState } from "react"; import dayjs from "dayjs"; export interface IMessageProps { data: IMessage; onDelete: () => void; } export default function Message({ data, onDelete }: IMessageProps) { const [show, { toggle }] = useDisclosure(true); const [animation, setAnimation] = useState(false); const messageContent = useMemo(() => { return show ? data.message : data.message.replace(/./g, "•"); }, [data.message, show]); // Tắt hiệu ứng nhấp nháy sau 1 giây useEffect(() => { if (!animation) return; const timer = setTimeout(() => { setAnimation(false); }, 5000); return () => clearTimeout(timer); }, [animation]); useEffect(() => { const showAnimation = new Date().getTime() - new Date(data.time).getTime() <= 110000; setAnimation(showAnimation); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return (
{data.recipient.length > 0 && {data.recipient}}
{dayjs(data.time).format("HH:mm D/M/YYYY")}