import "@/assets/sharing.less"; import { useParams } from "react-router-dom"; import { viewConversation, ViewData, ViewForm, } from "@/conversation/sharing.ts"; import { copyClipboard, saveAsFile } from "@/utils/dom.ts"; import { useEffectAsync } from "@/utils/hook.ts"; import { useState } from "react"; import { Copy, File, HelpCircle, Loader2, MessagesSquare } from "lucide-react"; import { useTranslation } from "react-i18next"; import MessageSegment from "@/components/Message.tsx"; import { Button } from "@/components/ui/button.tsx"; import router from "@/router.tsx"; import { useToast } from "@/components/ui/use-toast.ts"; import { sharingEvent } from "@/events/sharing.ts"; import { Message } from "@/conversation/types.ts"; type SharingFormProps = { refer?: string; data: ViewData | null; }; function SharingForm({ refer, data }: SharingFormProps) { if (data === null) return null; const { t } = useTranslation(); const date = new Date(data.time); const time = `${ date.getMonth() + 1 }-${date.getDate()} ${date.getHours()}:${date.getMinutes()}`; const value = JSON.stringify(data, null, 2); const { toast } = useToast(); return (
{data.username}
{data.name}
{time}
{data.messages.map((message, i) => ( ))}
); } function Sharing() { const { t } = useTranslation(); const { hash } = useParams(); const [setup, setSetup] = useState(false); const [data, setData] = useState(null); useEffectAsync(async () => { if (!hash || setup) return; setSetup(true); const resp = await viewConversation(hash as string); setData(resp); if (!resp.status) console.debug(`[sharing] error: ${resp.message}`); }, []); return (
{data === null ? (
) : data.status ? ( ) : (

{t("share.not-found")}

{t("share.not-found-description")}

)}
); } export default Sharing;