2026-07-26 11:27:21 +07:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
AlertCircle,
|
|
|
|
|
ExternalLink,
|
2026-07-26 12:01:51 +07:00
|
|
|
Flag,
|
2026-07-26 15:13:18 +07:00
|
|
|
Hash,
|
2026-07-26 12:01:51 +07:00
|
|
|
Loader2,
|
|
|
|
|
RefreshCw,
|
|
|
|
|
Search,
|
2026-07-26 15:13:18 +07:00
|
|
|
Sparkles,
|
2026-07-26 12:01:51 +07:00
|
|
|
X,
|
2026-07-26 11:27:21 +07:00
|
|
|
} from "lucide-react";
|
2026-07-26 14:27:36 +07:00
|
|
|
import Image from "next/image";
|
2026-07-26 12:01:51 +07:00
|
|
|
import { useCallback, useEffect, useState } from "react";
|
2026-07-26 15:13:18 +07:00
|
|
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "@/components/ui/dialog";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { Progress } from "@/components/ui/progress";
|
|
|
|
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
|
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
} from "@/components/ui/select";
|
|
|
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
|
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
2026-07-26 12:01:51 +07:00
|
|
|
import { messagesApi, voiceApi } from "@/lib/api";
|
|
|
|
|
import type { AttachmentRecord, Channel, MessageRecord } from "@/lib/types";
|
2026-07-26 15:13:18 +07:00
|
|
|
import { cn } from "@/lib/utils";
|
2026-07-26 12:01:51 +07:00
|
|
|
import { useWebSocket } from "@/lib/ws/context";
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-07-26 13:45:05 +07:00
|
|
|
export function MessagesPanel({ guildId }: { guildId: string }) {
|
2026-07-26 11:27:21 +07:00
|
|
|
const [messages, setMessages] = useState<MessageRecord[]>([]);
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
const [loadingMore, setLoadingMore] = useState(false);
|
|
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
|
const [cursor, setCursor] = useState<string | null>(null);
|
|
|
|
|
const [hasMore, setHasMore] = useState(true);
|
|
|
|
|
const [searchQuery, setSearchQuery] = useState("");
|
2026-07-26 12:01:51 +07:00
|
|
|
const [searchResults, setSearchResults] = useState<MessageRecord[] | null>(
|
|
|
|
|
null,
|
|
|
|
|
);
|
2026-07-26 14:27:36 +07:00
|
|
|
const [_searching, setSearching] = useState(false);
|
2026-07-26 11:27:21 +07:00
|
|
|
const [viewTab, setViewTab] = useState<"all" | "images" | "review">("all");
|
|
|
|
|
const [imageMessages, setImageMessages] = useState<MessageRecord[]>([]);
|
|
|
|
|
const [reviewMessages, setReviewMessages] = useState<MessageRecord[]>([]);
|
|
|
|
|
const [channels, setChannels] = useState<Channel[]>([]);
|
2026-07-26 12:01:51 +07:00
|
|
|
const [detailMessage, setDetailMessage] = useState<MessageRecord | null>(
|
|
|
|
|
null,
|
|
|
|
|
);
|
|
|
|
|
const [detailAttachments, setDetailAttachments] = useState<
|
|
|
|
|
AttachmentRecord[]
|
|
|
|
|
>([]);
|
2026-07-26 11:27:21 +07:00
|
|
|
const [detailLoading, setDetailLoading] = useState(false);
|
|
|
|
|
const [selectedChannel, setSelectedChannel] = useState("");
|
|
|
|
|
|
|
|
|
|
const ws = useWebSocket();
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
// ── Data fetching ──
|
2026-07-26 13:45:05 +07:00
|
|
|
|
2026-07-26 11:27:21 +07:00
|
|
|
useEffect(() => {
|
2026-07-26 14:27:36 +07:00
|
|
|
if (!guildId) return;
|
2026-07-26 12:01:51 +07:00
|
|
|
voiceApi
|
|
|
|
|
.getTextChannels(guildId)
|
|
|
|
|
.then(setChannels)
|
|
|
|
|
.catch(() => {});
|
2026-07-26 11:27:21 +07:00
|
|
|
}, [guildId]);
|
|
|
|
|
|
|
|
|
|
const fetchMessages = useCallback(async () => {
|
2026-07-26 14:27:36 +07:00
|
|
|
if (!guildId) return;
|
2026-07-26 11:27:21 +07:00
|
|
|
setLoading(true);
|
|
|
|
|
setError(null);
|
|
|
|
|
try {
|
2026-07-26 12:01:51 +07:00
|
|
|
const result = await messagesApi.list(
|
|
|
|
|
guildId,
|
|
|
|
|
50,
|
|
|
|
|
selectedChannel || undefined,
|
|
|
|
|
);
|
2026-07-26 11:27:21 +07:00
|
|
|
setMessages(result.data);
|
|
|
|
|
setCursor(result.nextCursor);
|
|
|
|
|
setHasMore(result.nextCursor !== null);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
setError(err instanceof Error ? err.message : "Failed to load messages");
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
}, [guildId, selectedChannel]);
|
|
|
|
|
|
|
|
|
|
const fetchImages = useCallback(async () => {
|
2026-07-26 14:27:36 +07:00
|
|
|
if (!guildId) return;
|
2026-07-26 11:27:21 +07:00
|
|
|
try {
|
|
|
|
|
const result = await messagesApi.getImages(guildId, 50);
|
|
|
|
|
setImageMessages(result.data);
|
|
|
|
|
} catch {
|
|
|
|
|
// silently fail
|
|
|
|
|
}
|
|
|
|
|
}, [guildId]);
|
|
|
|
|
|
|
|
|
|
const fetchReview = useCallback(async () => {
|
|
|
|
|
try {
|
2026-07-26 12:01:51 +07:00
|
|
|
const result = await messagesApi.getReview(
|
|
|
|
|
50,
|
|
|
|
|
selectedChannel || undefined,
|
|
|
|
|
);
|
2026-07-26 11:27:21 +07:00
|
|
|
setReviewMessages(result.results);
|
|
|
|
|
} catch {
|
|
|
|
|
// silently fail
|
|
|
|
|
}
|
|
|
|
|
}, [selectedChannel]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchMessages();
|
|
|
|
|
fetchImages();
|
|
|
|
|
}, [fetchMessages, fetchImages]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (viewTab === "review") fetchReview();
|
|
|
|
|
}, [viewTab, fetchReview]);
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
// WS subscriptions
|
2026-07-26 11:27:21 +07:00
|
|
|
useEffect(() => {
|
2026-07-26 14:27:36 +07:00
|
|
|
if (!guildId) return;
|
2026-07-26 11:27:21 +07:00
|
|
|
const unsubCreated = ws.on("message_created", (msg) => {
|
|
|
|
|
setMessages((prev) => [msg as MessageRecord, ...prev]);
|
|
|
|
|
});
|
|
|
|
|
const unsubUpdated = ws.on("message_updated", (msg) => {
|
|
|
|
|
setMessages((prev) =>
|
|
|
|
|
prev.map((m) =>
|
|
|
|
|
(msg as MessageRecord).id === m.id ? (msg as MessageRecord) : m,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
const unsubDeleted = ws.on("message_deleted", (id) => {
|
|
|
|
|
setMessages((prev) =>
|
|
|
|
|
prev.filter((m) => m.id !== (id as unknown as string)),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
const unsubAnalyzed = ws.on("message_analyzed", (msg) => {
|
|
|
|
|
setMessages((prev) =>
|
|
|
|
|
prev.map((m) =>
|
|
|
|
|
(msg as MessageRecord).id === m.id ? (msg as MessageRecord) : m,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
unsubCreated();
|
|
|
|
|
unsubUpdated();
|
|
|
|
|
unsubDeleted();
|
|
|
|
|
unsubAnalyzed();
|
|
|
|
|
};
|
2026-07-26 14:27:36 +07:00
|
|
|
}, [ws, guildId]);
|
2026-07-26 11:27:21 +07:00
|
|
|
|
|
|
|
|
const handleSearch = useCallback(async () => {
|
|
|
|
|
if (!searchQuery.trim()) {
|
|
|
|
|
setSearchResults(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setSearching(true);
|
|
|
|
|
try {
|
|
|
|
|
const result = await messagesApi.search(searchQuery, 50);
|
|
|
|
|
setSearchResults(result.results);
|
|
|
|
|
} catch {
|
|
|
|
|
setSearchResults([]);
|
|
|
|
|
} finally {
|
|
|
|
|
setSearching(false);
|
|
|
|
|
}
|
|
|
|
|
}, [searchQuery]);
|
|
|
|
|
|
|
|
|
|
const handleLoadMore = useCallback(async () => {
|
|
|
|
|
if (!cursor || loadingMore) return;
|
|
|
|
|
setLoadingMore(true);
|
|
|
|
|
try {
|
2026-07-26 12:01:51 +07:00
|
|
|
const result = await messagesApi.list(
|
|
|
|
|
guildId,
|
|
|
|
|
50,
|
|
|
|
|
selectedChannel || undefined,
|
|
|
|
|
cursor,
|
|
|
|
|
);
|
2026-07-26 11:27:21 +07:00
|
|
|
setMessages((prev) => [...prev, ...result.data]);
|
|
|
|
|
setCursor(result.nextCursor);
|
|
|
|
|
setHasMore(result.nextCursor !== null);
|
|
|
|
|
} catch {
|
|
|
|
|
// ignore
|
|
|
|
|
} finally {
|
|
|
|
|
setLoadingMore(false);
|
|
|
|
|
}
|
|
|
|
|
}, [cursor, loadingMore, guildId, selectedChannel]);
|
|
|
|
|
|
|
|
|
|
const handleMessageClick = useCallback(async (id: string) => {
|
|
|
|
|
setDetailLoading(true);
|
|
|
|
|
setDetailAttachments([]);
|
|
|
|
|
try {
|
|
|
|
|
const detail = await messagesApi.getDetail(id);
|
|
|
|
|
setDetailMessage(detail);
|
|
|
|
|
if (detail.channel_id && id) {
|
|
|
|
|
messagesApi
|
|
|
|
|
.getAttachments(detail.channel_id, 10)
|
|
|
|
|
.then((res) => setDetailAttachments(res.data))
|
|
|
|
|
.catch(() => {});
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
setDetailMessage(null);
|
|
|
|
|
} finally {
|
|
|
|
|
setDetailLoading(false);
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleReanalyze = useCallback(async (id: string) => {
|
|
|
|
|
try {
|
|
|
|
|
await messagesApi.reanalyze(id);
|
|
|
|
|
} catch {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleReanalyzeBatch = useCallback(async () => {
|
|
|
|
|
try {
|
2026-07-26 13:45:05 +07:00
|
|
|
await messagesApi.reanalyzeBatch(guildId);
|
2026-07-26 11:27:21 +07:00
|
|
|
} catch {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
2026-07-26 13:45:05 +07:00
|
|
|
}, [guildId]);
|
2026-07-26 11:27:21 +07:00
|
|
|
|
|
|
|
|
const displayMessages = searchResults ?? messages;
|
|
|
|
|
const isEmpty = !loading && displayMessages.length === 0;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="flex flex-col items-center justify-center py-20 text-center">
|
|
|
|
|
<AlertCircle className="size-10 text-destructive mb-3" />
|
|
|
|
|
<p className="text-sm text-muted-foreground mb-4 max-w-sm">{error}</p>
|
|
|
|
|
<Button variant="outline" onClick={fetchMessages}>
|
|
|
|
|
<RefreshCw className="size-4 mr-2" />
|
2026-07-26 11:27:21 +07:00
|
|
|
Retry
|
2026-07-26 15:13:18 +07:00
|
|
|
</Button>
|
2026-07-26 11:27:21 +07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="space-y-5">
|
2026-07-26 11:27:21 +07:00
|
|
|
{/* Search + toolbar */}
|
|
|
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
|
|
|
|
|
<div className="relative flex-1">
|
|
|
|
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" />
|
2026-07-26 15:13:18 +07:00
|
|
|
<Input
|
2026-07-26 11:27:21 +07:00
|
|
|
type="text"
|
|
|
|
|
placeholder="Search messages…"
|
|
|
|
|
value={searchQuery}
|
|
|
|
|
onChange={(e) => setSearchQuery(e.target.value)}
|
|
|
|
|
onKeyDown={(e) => e.key === "Enter" && handleSearch()}
|
2026-07-26 15:13:18 +07:00
|
|
|
className="pl-9 h-9"
|
2026-07-26 11:27:21 +07:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Channel filter */}
|
|
|
|
|
{channels.length > 0 && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<Select
|
2026-07-26 11:27:21 +07:00
|
|
|
value={selectedChannel}
|
2026-07-26 15:13:18 +07:00
|
|
|
onValueChange={(v) => v && setSelectedChannel(v)}
|
2026-07-26 11:27:21 +07:00
|
|
|
>
|
2026-07-26 15:13:18 +07:00
|
|
|
<SelectTrigger className="h-9 w-full sm:w-44">
|
|
|
|
|
<SelectValue placeholder="All channels" />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
<SelectItem value=" ">All channels</SelectItem>
|
|
|
|
|
{channels.map((ch) => (
|
|
|
|
|
<SelectItem key={ch.id} value={ch.id}>
|
|
|
|
|
# {ch.name}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
2026-07-26 11:27:21 +07:00
|
|
|
)}
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
<Button variant="outline" size="sm" onClick={handleReanalyzeBatch}>
|
|
|
|
|
<RefreshCw className="size-4 mr-1.5" />
|
2026-07-26 11:27:21 +07:00
|
|
|
Reanalyze Errors
|
2026-07-26 15:13:18 +07:00
|
|
|
</Button>
|
2026-07-26 11:27:21 +07:00
|
|
|
</div>
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
{/* Tab bar using shadcn Tabs */}
|
|
|
|
|
<Tabs
|
|
|
|
|
value={viewTab}
|
|
|
|
|
onValueChange={(v) => setViewTab(v as "all" | "images" | "review")}
|
|
|
|
|
>
|
|
|
|
|
<TabsList>
|
|
|
|
|
<TabsTrigger value="all" onClick={() => setViewTab("all")}>
|
|
|
|
|
All ({messages.length})
|
|
|
|
|
</TabsTrigger>
|
|
|
|
|
<TabsTrigger value="images" onClick={() => setViewTab("images")}>
|
|
|
|
|
Images ({imageMessages.length})
|
|
|
|
|
</TabsTrigger>
|
|
|
|
|
<TabsTrigger value="review" onClick={() => setViewTab("review")}>
|
|
|
|
|
<Flag className="size-3.5 mr-1" />
|
|
|
|
|
Review ({reviewMessages.length})
|
|
|
|
|
</TabsTrigger>
|
|
|
|
|
</TabsList>
|
|
|
|
|
</Tabs>
|
2026-07-26 11:27:21 +07:00
|
|
|
|
|
|
|
|
{/* Search results count */}
|
|
|
|
|
{searchResults !== null && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<p className="text-sm text-muted-foreground animate-fade-in-up">
|
2026-07-26 11:27:21 +07:00
|
|
|
Found {searchResults.length} result
|
|
|
|
|
{searchResults.length !== 1 ? "s" : ""}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Messages feed */}
|
|
|
|
|
{viewTab === "all" ? (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="space-y-2 animate-fade-in-up">
|
2026-07-26 11:27:21 +07:00
|
|
|
{loading ? (
|
|
|
|
|
<div className="space-y-3">
|
2026-07-26 15:13:18 +07:00
|
|
|
{Array.from({ length: 8 }, (_, i) => (
|
|
|
|
|
<Skeleton key={i} className="h-28 rounded-xl" />
|
2026-07-26 11:27:21 +07:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
) : isEmpty ? (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="flex flex-col items-center justify-center py-20 text-center">
|
|
|
|
|
<Search className="size-10 text-muted-foreground/40 mb-3" />
|
2026-07-26 11:27:21 +07:00
|
|
|
<p className="text-sm text-muted-foreground">
|
|
|
|
|
{searchResults !== null
|
|
|
|
|
? "No messages found matching your search."
|
|
|
|
|
: "No captures yet."}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
{displayMessages.map((msg) => (
|
|
|
|
|
<MessageCard
|
|
|
|
|
key={msg.id}
|
|
|
|
|
message={msg}
|
|
|
|
|
onClick={handleMessageClick}
|
|
|
|
|
onReanalyze={handleReanalyze}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
{hasMore && searchResults === null && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="flex justify-center py-6">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
2026-07-26 11:27:21 +07:00
|
|
|
onClick={handleLoadMore}
|
|
|
|
|
disabled={loadingMore}
|
|
|
|
|
>
|
2026-07-26 15:13:18 +07:00
|
|
|
{loadingMore && (
|
|
|
|
|
<Loader2 className="size-4 animate-spin mr-2" />
|
|
|
|
|
)}
|
2026-07-26 11:27:21 +07:00
|
|
|
{loadingMore ? "Loading…" : "Load more"}
|
2026-07-26 15:13:18 +07:00
|
|
|
</Button>
|
2026-07-26 11:27:21 +07:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
) : viewTab === "images" ? (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3 animate-fade-in-up">
|
|
|
|
|
{imageMessages.length === 0 ? (
|
|
|
|
|
<div className="col-span-full flex flex-col items-center justify-center py-20 text-center">
|
|
|
|
|
<ImageIcon className="size-10 text-muted-foreground/40 mb-3" />
|
|
|
|
|
<p className="text-sm text-muted-foreground">No images yet.</p>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
imageMessages.map((msg) => {
|
|
|
|
|
let imageUrl: string | null = null;
|
|
|
|
|
try {
|
|
|
|
|
const meta = JSON.parse(msg.metadata ?? "{}");
|
|
|
|
|
const attachments: Array<{
|
|
|
|
|
url: string;
|
|
|
|
|
contentType?: string;
|
|
|
|
|
}> = meta.attachments ?? [];
|
|
|
|
|
const img = attachments.find((a) =>
|
|
|
|
|
a.contentType?.startsWith("image/"),
|
|
|
|
|
);
|
|
|
|
|
imageUrl = img?.url ?? null;
|
|
|
|
|
} catch {
|
|
|
|
|
// metadata malformed
|
|
|
|
|
}
|
2026-07-26 14:42:16 +07:00
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
return (
|
|
|
|
|
<Card
|
|
|
|
|
key={msg.id}
|
|
|
|
|
className="group relative overflow-hidden cursor-pointer"
|
|
|
|
|
onClick={() => handleMessageClick(msg.id)}
|
|
|
|
|
>
|
|
|
|
|
<div className="aspect-square relative bg-muted">
|
|
|
|
|
{imageUrl ? (
|
|
|
|
|
<Image
|
|
|
|
|
src={imageUrl}
|
|
|
|
|
alt={msg.content || "Image"}
|
|
|
|
|
fill
|
|
|
|
|
className="object-cover transition-transform duration-300 group-hover:scale-105"
|
|
|
|
|
sizes="(max-width: 768px) 50vw, 25vw"
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex items-center justify-center size-full text-muted-foreground text-xs">
|
|
|
|
|
No image
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{/* Hover overlay */}
|
|
|
|
|
{msg.content && (
|
|
|
|
|
<div className="absolute inset-0 bg-gradient-to-t from-black/70 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-200 flex items-end p-3">
|
|
|
|
|
<p className="text-xs text-white/90 line-clamp-2">
|
|
|
|
|
{msg.username}: {msg.content}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-07-26 14:42:16 +07:00
|
|
|
</div>
|
2026-07-26 15:13:18 +07:00
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
)}
|
2026-07-26 11:27:21 +07:00
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
/* Review tab */
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="space-y-2 animate-fade-in-up">
|
2026-07-26 11:27:21 +07:00
|
|
|
{reviewMessages.length === 0 ? (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="flex flex-col items-center justify-center py-20 text-center">
|
|
|
|
|
<Flag className="size-10 text-muted-foreground/40 mb-3" />
|
2026-07-26 11:27:21 +07:00
|
|
|
<p className="text-sm text-muted-foreground">
|
|
|
|
|
No flagged messages to review.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
reviewMessages.map((msg) => (
|
|
|
|
|
<MessageCard
|
|
|
|
|
key={msg.id}
|
|
|
|
|
message={msg}
|
|
|
|
|
onClick={handleMessageClick}
|
|
|
|
|
onReanalyze={handleReanalyze}
|
|
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
{/* Message Detail Dialog */}
|
|
|
|
|
<Dialog
|
|
|
|
|
open={detailMessage !== null}
|
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
if (!open) setDetailMessage(null);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DialogContent className="sm:max-w-2xl max-h-[85vh]">
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle className="flex items-center gap-2">
|
|
|
|
|
<MessageSquare className="size-4" />
|
|
|
|
|
Message Detail
|
|
|
|
|
</DialogTitle>
|
|
|
|
|
</DialogHeader>
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
<ScrollArea className="max-h-[70vh] pr-1">
|
|
|
|
|
<div className="space-y-5">
|
2026-07-26 11:27:21 +07:00
|
|
|
{detailLoading ? (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="flex justify-center py-12">
|
|
|
|
|
<Loader2 className="size-6 animate-spin text-muted-foreground" />
|
2026-07-26 11:27:21 +07:00
|
|
|
</div>
|
2026-07-26 15:13:18 +07:00
|
|
|
) : detailMessage ? (
|
2026-07-26 11:27:21 +07:00
|
|
|
<>
|
|
|
|
|
{/* Message info */}
|
|
|
|
|
<div className="flex items-start gap-3">
|
2026-07-26 15:13:18 +07:00
|
|
|
<Avatar className="size-10">
|
|
|
|
|
<AvatarImage
|
|
|
|
|
src={detailMessage.avatar_url ?? undefined}
|
|
|
|
|
/>
|
|
|
|
|
<AvatarFallback>
|
|
|
|
|
{detailMessage.username.charAt(0).toUpperCase()}
|
|
|
|
|
</AvatarFallback>
|
|
|
|
|
</Avatar>
|
2026-07-26 11:27:21 +07:00
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<div className="flex items-center gap-2 flex-wrap">
|
|
|
|
|
<span className="text-sm font-medium">
|
|
|
|
|
{detailMessage.username}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="text-xs text-muted-foreground">
|
|
|
|
|
{new Date(detailMessage.created_at).toLocaleString()}
|
|
|
|
|
</span>
|
|
|
|
|
{detailMessage.type === "deleted" && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<Badge variant="destructive" className="text-[10px]">
|
2026-07-26 11:27:21 +07:00
|
|
|
deleted
|
2026-07-26 15:13:18 +07:00
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
{detailMessage.type === "edited" && (
|
|
|
|
|
<Badge variant="outline" className="text-[10px]">
|
|
|
|
|
edited
|
|
|
|
|
</Badge>
|
2026-07-26 11:27:21 +07:00
|
|
|
)}
|
|
|
|
|
</div>
|
2026-07-26 15:13:18 +07:00
|
|
|
<p className="text-sm mt-2 whitespace-pre-wrap break-words leading-relaxed">
|
2026-07-26 11:27:21 +07:00
|
|
|
{detailMessage.content}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
{/* AI Analysis */}
|
2026-07-26 11:27:21 +07:00
|
|
|
{detailMessage.ai_analysis && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="rounded-lg bg-gradient-to-br from-primary/5 to-primary/[0.02] border border-primary/10 p-4">
|
|
|
|
|
<div className="flex items-center gap-2 mb-2">
|
|
|
|
|
<Sparkles className="size-4 text-primary" />
|
|
|
|
|
<p className="text-xs text-muted-foreground font-medium">
|
|
|
|
|
AI Analysis
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-sm leading-relaxed">
|
|
|
|
|
{detailMessage.ai_analysis}
|
2026-07-26 11:27:21 +07:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* AI flags */}
|
|
|
|
|
{detailMessage.ai_moderation_flags &&
|
|
|
|
|
detailMessage.ai_moderation_flags !== "[]" && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="space-y-2">
|
|
|
|
|
<p className="text-xs text-muted-foreground font-medium">
|
2026-07-26 11:27:21 +07:00
|
|
|
Moderation Flags
|
|
|
|
|
</p>
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="flex flex-wrap gap-1.5">
|
2026-07-26 11:27:21 +07:00
|
|
|
{safeParseJsonArray(
|
|
|
|
|
detailMessage.ai_moderation_flags,
|
|
|
|
|
).map((flag) => (
|
2026-07-26 15:13:18 +07:00
|
|
|
<Badge
|
2026-07-26 11:27:21 +07:00
|
|
|
key={flag}
|
2026-07-26 15:13:18 +07:00
|
|
|
variant="destructive"
|
|
|
|
|
className="text-[11px]"
|
2026-07-26 11:27:21 +07:00
|
|
|
>
|
|
|
|
|
{flag}
|
2026-07-26 15:13:18 +07:00
|
|
|
</Badge>
|
2026-07-26 11:27:21 +07:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* AI Scores */}
|
|
|
|
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
|
|
|
|
|
{detailMessage.ai_status && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<Card>
|
|
|
|
|
<CardContent className="p-3">
|
|
|
|
|
<p className="text-xs text-muted-foreground">
|
|
|
|
|
Status
|
|
|
|
|
</p>
|
|
|
|
|
<p className="text-sm font-medium mt-0.5 capitalize">
|
|
|
|
|
{detailMessage.ai_status}
|
|
|
|
|
</p>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2026-07-26 11:27:21 +07:00
|
|
|
)}
|
|
|
|
|
{detailMessage.ai_severity &&
|
|
|
|
|
detailMessage.ai_severity !== "none" && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<Card>
|
|
|
|
|
<CardContent className="p-3">
|
|
|
|
|
<p className="text-xs text-muted-foreground">
|
|
|
|
|
Severity
|
|
|
|
|
</p>
|
|
|
|
|
<p className="text-sm font-medium mt-0.5 text-destructive capitalize">
|
|
|
|
|
{detailMessage.ai_severity}
|
|
|
|
|
</p>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2026-07-26 11:27:21 +07:00
|
|
|
)}
|
|
|
|
|
{detailMessage.ai_confidence != null && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<Card>
|
|
|
|
|
<CardContent className="p-3">
|
|
|
|
|
<p className="text-xs text-muted-foreground">
|
|
|
|
|
Confidence
|
|
|
|
|
</p>
|
|
|
|
|
<p className="text-sm font-medium mt-0.5 tabular-nums">
|
|
|
|
|
{(detailMessage.ai_confidence * 100).toFixed(0)}%
|
|
|
|
|
</p>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2026-07-26 11:27:21 +07:00
|
|
|
)}
|
|
|
|
|
{detailMessage.ai_recommended_action &&
|
|
|
|
|
detailMessage.ai_recommended_action !== "none" && (
|
2026-07-26 15:13:18 +07:00
|
|
|
<Card>
|
|
|
|
|
<CardContent className="p-3">
|
|
|
|
|
<p className="text-xs text-muted-foreground">
|
|
|
|
|
Action
|
|
|
|
|
</p>
|
|
|
|
|
<p className="text-sm font-medium mt-0.5 capitalize">
|
|
|
|
|
{detailMessage.ai_recommended_action}
|
|
|
|
|
</p>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2026-07-26 11:27:21 +07:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Attachments */}
|
|
|
|
|
{detailAttachments.length > 0 && (
|
|
|
|
|
<div className="space-y-2">
|
2026-07-26 15:13:18 +07:00
|
|
|
<p className="text-xs text-muted-foreground font-medium">
|
2026-07-26 11:27:21 +07:00
|
|
|
Attachments ({detailAttachments.length})
|
|
|
|
|
</p>
|
|
|
|
|
<div className="grid grid-cols-2 gap-2">
|
|
|
|
|
{detailAttachments.map((att) => (
|
|
|
|
|
<a
|
|
|
|
|
key={att.id}
|
|
|
|
|
href={att.uploaded_url ?? att.discord_url}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
2026-07-26 15:13:18 +07:00
|
|
|
className="flex items-center gap-2 rounded-lg border border-border/50 p-2 hover:bg-muted transition-colors group"
|
2026-07-26 11:27:21 +07:00
|
|
|
>
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<p className="text-xs font-medium truncate">
|
|
|
|
|
{att.filename}
|
|
|
|
|
</p>
|
2026-07-26 15:13:18 +07:00
|
|
|
<p className="text-[11px] text-muted-foreground">
|
2026-07-26 11:27:21 +07:00
|
|
|
{att.type} · {formatBytes(att.size)}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2026-07-26 15:13:18 +07:00
|
|
|
<ExternalLink className="size-3 shrink-0 text-muted-foreground/50 group-hover:text-muted-foreground transition-colors" />
|
2026-07-26 11:27:21 +07:00
|
|
|
</a>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Raw metadata */}
|
|
|
|
|
{detailMessage.metadata &&
|
|
|
|
|
detailMessage.metadata !== "{}" && (
|
|
|
|
|
<div className="space-y-1">
|
2026-07-26 15:13:18 +07:00
|
|
|
<p className="text-xs text-muted-foreground font-medium">
|
2026-07-26 11:27:21 +07:00
|
|
|
Metadata (raw)
|
|
|
|
|
</p>
|
2026-07-26 15:13:18 +07:00
|
|
|
<pre className="text-xs bg-muted/50 rounded-lg p-3 overflow-x-auto max-h-32 border border-border/50">
|
2026-07-26 11:27:21 +07:00
|
|
|
{JSON.stringify(
|
|
|
|
|
safeParseJsonObject(detailMessage.metadata),
|
|
|
|
|
null,
|
|
|
|
|
2,
|
|
|
|
|
)}
|
|
|
|
|
</pre>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2026-07-26 15:13:18 +07:00
|
|
|
) : null}
|
2026-07-26 11:27:21 +07:00
|
|
|
</div>
|
2026-07-26 15:13:18 +07:00
|
|
|
</ScrollArea>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
2026-07-26 11:27:21 +07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
// ── Message Card ────────────────────────────────
|
2026-07-26 11:27:21 +07:00
|
|
|
|
|
|
|
|
function MessageCard({
|
|
|
|
|
message: msg,
|
|
|
|
|
onClick,
|
|
|
|
|
onReanalyze,
|
|
|
|
|
}: {
|
|
|
|
|
message: MessageRecord;
|
|
|
|
|
onClick: (id: string) => void;
|
|
|
|
|
onReanalyze: (id: string) => void;
|
|
|
|
|
}) {
|
|
|
|
|
const aiStatusColor: Record<string, string> = {
|
2026-07-26 15:13:18 +07:00
|
|
|
clean:
|
|
|
|
|
"bg-green-500/15 text-green-600 dark:text-green-400 border-green-500/20",
|
|
|
|
|
warn: "bg-yellow-500/15 text-yellow-600 dark:text-yellow-400 border-yellow-500/20",
|
|
|
|
|
flagged: "bg-red-500/15 text-red-600 dark:text-red-400 border-red-500/20",
|
|
|
|
|
error: "bg-gray-500/15 text-gray-600 dark:text-gray-400 border-gray-500/20",
|
|
|
|
|
pending:
|
|
|
|
|
"bg-blue-500/15 text-blue-600 dark:text-blue-400 border-blue-500/20",
|
|
|
|
|
processing:
|
|
|
|
|
"bg-blue-500/15 text-blue-600 dark:text-blue-400 border-blue-500/20",
|
2026-07-26 11:27:21 +07:00
|
|
|
};
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
const severityLeftBorder: Record<string, string> = {
|
|
|
|
|
low: "border-l-sky-400",
|
2026-07-26 11:27:21 +07:00
|
|
|
medium: "border-l-yellow-400",
|
|
|
|
|
high: "border-l-orange-400",
|
|
|
|
|
critical: "border-l-red-500",
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
const hasSeverity =
|
|
|
|
|
msg.ai_severity &&
|
|
|
|
|
msg.ai_severity !== "none" &&
|
|
|
|
|
severityLeftBorder[msg.ai_severity];
|
2026-07-26 11:27:21 +07:00
|
|
|
|
|
|
|
|
return (
|
2026-07-26 15:13:18 +07:00
|
|
|
<Card
|
|
|
|
|
className={cn(
|
|
|
|
|
"cursor-pointer transition-all duration-200 hover:bg-accent/5 hover:shadow-sm",
|
|
|
|
|
hasSeverity && "border-l-2",
|
|
|
|
|
hasSeverity && severityLeftBorder[msg.ai_severity as string],
|
|
|
|
|
)}
|
2026-07-26 11:27:21 +07:00
|
|
|
onClick={() => onClick(msg.id)}
|
|
|
|
|
>
|
2026-07-26 15:13:18 +07:00
|
|
|
<CardContent className="p-4">
|
|
|
|
|
<div className="flex items-start gap-3">
|
|
|
|
|
<Avatar className="size-8 shrink-0 mt-0.5">
|
|
|
|
|
<AvatarImage src={msg.avatar_url ?? undefined} />
|
|
|
|
|
<AvatarFallback className="text-xs">
|
|
|
|
|
{msg.username.charAt(0).toUpperCase()}
|
|
|
|
|
</AvatarFallback>
|
|
|
|
|
</Avatar>
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
<div className="flex-1 min-w-0 space-y-2">
|
|
|
|
|
{/* Username + time + badges */}
|
|
|
|
|
<div className="flex items-center gap-2 flex-wrap">
|
|
|
|
|
<span className="text-sm font-medium">{msg.username}</span>
|
2026-07-26 12:01:51 +07:00
|
|
|
<span className="text-xs text-muted-foreground">
|
2026-07-26 15:13:18 +07:00
|
|
|
{new Date(msg.created_at).toLocaleString()}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="text-xs text-muted-foreground">
|
|
|
|
|
<Hash className="size-3 inline mr-0.5" />
|
|
|
|
|
{msg.channel_id.slice(0, 8)}
|
2026-07-26 12:01:51 +07:00
|
|
|
</span>
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
{/* AI Status badge */}
|
|
|
|
|
{msg.ai_status && aiStatusColor[msg.ai_status] && (
|
|
|
|
|
<Badge
|
|
|
|
|
variant="outline"
|
|
|
|
|
className={cn(
|
|
|
|
|
"text-[10px] px-1.5 py-0 h-4 font-medium",
|
|
|
|
|
aiStatusColor[msg.ai_status],
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{msg.ai_status}
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Severity badge */}
|
|
|
|
|
{msg.ai_severity && msg.ai_severity !== "none" && (
|
|
|
|
|
<Badge
|
|
|
|
|
variant="destructive"
|
|
|
|
|
className="text-[10px] px-1.5 py-0 h-4"
|
|
|
|
|
>
|
|
|
|
|
{msg.ai_severity}
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Deleted/edited badges */}
|
|
|
|
|
{msg.type === "deleted" && (
|
|
|
|
|
<Badge
|
|
|
|
|
variant="destructive"
|
|
|
|
|
className="text-[10px] px-1.5 py-0 h-4"
|
|
|
|
|
>
|
|
|
|
|
deleted
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
{msg.type === "edited" && (
|
|
|
|
|
<Badge
|
|
|
|
|
variant="outline"
|
|
|
|
|
className="text-[10px] px-1.5 py-0 h-4"
|
|
|
|
|
>
|
|
|
|
|
edited
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Content */}
|
|
|
|
|
<p
|
|
|
|
|
className={cn(
|
|
|
|
|
"text-sm leading-relaxed",
|
|
|
|
|
msg.type === "deleted" &&
|
|
|
|
|
"italic text-muted-foreground line-through",
|
|
|
|
|
)}
|
2026-07-26 11:27:21 +07:00
|
|
|
>
|
2026-07-26 15:13:18 +07:00
|
|
|
{msg.content}
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
{/* AI flags */}
|
|
|
|
|
{msg.ai_moderation_flags && msg.ai_moderation_flags !== "[]" && (
|
|
|
|
|
<div className="flex flex-wrap gap-1">
|
|
|
|
|
{safeParseJsonArray(msg.ai_moderation_flags).map((flag) => (
|
|
|
|
|
<Badge
|
|
|
|
|
key={flag}
|
|
|
|
|
variant="destructive"
|
|
|
|
|
className="text-[10px] px-1.5 py-0 h-4"
|
|
|
|
|
>
|
|
|
|
|
{flag}
|
|
|
|
|
</Badge>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* AI analysis snippet */}
|
|
|
|
|
{msg.ai_analysis && (
|
|
|
|
|
<p className="text-xs text-muted-foreground italic line-clamp-2 leading-relaxed">
|
|
|
|
|
{msg.ai_analysis}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Confidence bar */}
|
|
|
|
|
{msg.ai_confidence !== undefined && msg.ai_confidence !== null && (
|
|
|
|
|
<div className="flex items-center gap-2 max-w-40">
|
|
|
|
|
<Progress value={msg.ai_confidence * 100} className="h-1.5" />
|
|
|
|
|
<span className="text-[11px] text-muted-foreground tabular-nums shrink-0">
|
|
|
|
|
{(msg.ai_confidence * 100).toFixed(0)}%
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Actions */}
|
|
|
|
|
<div className="flex gap-1.5 pt-0.5">
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="xs"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onReanalyze(msg.id);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RefreshCw className="size-3 mr-1" />
|
|
|
|
|
Reanalyze
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2026-07-26 11:27:21 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-07-26 15:13:18 +07:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2026-07-26 11:27:21 +07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
// ── Helpers ─────────────────────────────────────
|
2026-07-26 11:27:21 +07:00
|
|
|
|
|
|
|
|
function safeParseJsonObject(
|
|
|
|
|
value: string | null | undefined,
|
|
|
|
|
): Record<string, unknown> {
|
|
|
|
|
if (!value) return {};
|
|
|
|
|
try {
|
|
|
|
|
const parsed = JSON.parse(value);
|
|
|
|
|
if (typeof parsed === "object" && parsed !== null) return parsed;
|
|
|
|
|
return {};
|
|
|
|
|
} catch {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatBytes(bytes: number): string {
|
|
|
|
|
if (bytes < 1024) return `${bytes} B`;
|
|
|
|
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
|
|
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-26 12:01:51 +07:00
|
|
|
function safeParseJsonArray(value: string | null | undefined): string[] {
|
2026-07-26 11:27:21 +07:00
|
|
|
if (!value) return [];
|
|
|
|
|
try {
|
|
|
|
|
const parsed = JSON.parse(value);
|
|
|
|
|
if (Array.isArray(parsed)) return parsed;
|
|
|
|
|
return [];
|
|
|
|
|
} catch {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-26 15:13:18 +07:00
|
|
|
|
|
|
|
|
// Inline icon components to avoid missing imports
|
|
|
|
|
function ImageIcon({ className }: { className?: string }) {
|
|
|
|
|
return (
|
|
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
width="24"
|
|
|
|
|
height="24"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
fill="none"
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
strokeWidth="2"
|
|
|
|
|
strokeLinecap="round"
|
|
|
|
|
strokeLinejoin="round"
|
|
|
|
|
className={className}
|
|
|
|
|
role="img"
|
|
|
|
|
aria-label="Image"
|
|
|
|
|
>
|
|
|
|
|
<title>Image</title>
|
|
|
|
|
<rect width="18" height="18" x="3" y="3" rx="2" ry="2" />
|
|
|
|
|
<circle cx="9" cy="9" r="2" />
|
|
|
|
|
<path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" />
|
|
|
|
|
</svg>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function MessageSquare({ className }: { className?: string }) {
|
|
|
|
|
return (
|
|
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
width="24"
|
|
|
|
|
height="24"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
fill="none"
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
strokeWidth="2"
|
|
|
|
|
strokeLinecap="round"
|
|
|
|
|
strokeLinejoin="round"
|
|
|
|
|
className={className}
|
|
|
|
|
role="img"
|
|
|
|
|
aria-label="Message"
|
|
|
|
|
>
|
|
|
|
|
<title>Message</title>
|
|
|
|
|
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
|
|
|
</svg>
|
|
|
|
|
);
|
|
|
|
|
}
|