chore(services): update components based on recent changes
Changes: services/frontend/src/features/dashboard/components/ChannelProfileDetail.tsx | 258 +++++++++++----------------------------------------------------------------- services/frontend/src/features/dashboard/components/ChannelSummaryList.tsx | 171 ++++++++------------------------------------------- services/frontend/src/features/dashboard/components/DashboardStats.tsx | 8 ++- services/frontend/src/features/dashboard/components/UserProfileDetail.tsx | 297 +++++++++++++--------------------------------------------------------------------------- services/frontend/src/features/dashboard/components/UserSummaryList.tsx | 204 +++++++++++------------------------------------------------- services/frontend/src/features/dashboard/hooks/useDashboard.ts | 203 +++++++++++++++--------------------------------------------- services/frontend/src/features/messages/components/MessageCard.tsx | 10 +-- services/frontend/src/shared/api/client.ts | 87 +++++++++++++++++++------- services/frontend/src/shared/hooks/useItemDetail.ts | 58 +++++++++++++++++ services/frontend/src/shared/hooks/usePaginatedList.ts | 105 +++++++++++++++++++++++++++++++
This commit is contained in:
@@ -1,16 +1,6 @@
|
||||
import { motion } from "framer-motion";
|
||||
import { AlertCircle, ArrowLeft, Hash, RefreshCw } from "lucide-react";
|
||||
import { Hash } from "lucide-react";
|
||||
import type { DashboardChannelDetail } from "../../../shared/api/client";
|
||||
import { cardItem, cardStagger } from "../../../shared/hooks/useFramerStagger";
|
||||
import { cn } from "../../../shared/lib/utils";
|
||||
import {
|
||||
Badge,
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
Skeleton,
|
||||
} from "../../../shared/ui";
|
||||
import { ProfileDetail } from "../../../shared/ui";
|
||||
|
||||
interface ChannelProfileDetailProps {
|
||||
detail: DashboardChannelDetail | null;
|
||||
@@ -27,218 +17,40 @@ export function ChannelProfileDetail({
|
||||
onBack,
|
||||
onRefetch,
|
||||
}: ChannelProfileDetailProps) {
|
||||
if (!detail && !loading && !error) return null;
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
className="grid gap-6"
|
||||
variants={cardStagger}
|
||||
initial="initial"
|
||||
animate="animate"
|
||||
>
|
||||
{/* Back button */}
|
||||
<motion.div variants={cardItem}>
|
||||
<button
|
||||
onClick={onBack}
|
||||
className="inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" /> Back to channels
|
||||
</button>
|
||||
</motion.div>
|
||||
|
||||
{/* Loading */}
|
||||
{loading && <DetailSkeleton />}
|
||||
|
||||
{/* Error */}
|
||||
{error && (
|
||||
<motion.div
|
||||
variants={cardItem}
|
||||
className="flex flex-col items-center gap-4 py-20 text-muted-foreground"
|
||||
>
|
||||
<AlertCircle className="h-10 w-10 text-destructive" />
|
||||
<p className="text-sm">{error}</p>
|
||||
<button
|
||||
onClick={onRefetch}
|
||||
className="inline-flex items-center gap-1.5 rounded-xl border border-border px-4 py-2 text-sm font-medium hover:bg-accent transition-colors"
|
||||
>
|
||||
<RefreshCw className="h-4 w-4" /> Retry
|
||||
</button>
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{detail && !error && (
|
||||
<>
|
||||
{/* Channel header */}
|
||||
<motion.div variants={cardItem}>
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="flex h-16 w-16 shrink-0 items-center justify-center rounded-full bg-muted ring-2 ring-border">
|
||||
<Hash className="h-8 w-8 text-muted-foreground" />
|
||||
</div>
|
||||
|
||||
<div className="min-w-0 flex-1">
|
||||
<h2 className="text-lg font-bold">
|
||||
#{detail.channel_name ?? detail.channel_id}
|
||||
</h2>
|
||||
<p className="mt-0.5 truncate font-mono text-xs text-muted-foreground">
|
||||
{detail.channel_id}
|
||||
</p>
|
||||
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2">
|
||||
{detail.flagged_count > 0 && (
|
||||
<Badge variant="destructive">
|
||||
{detail.flagged_count} flagged
|
||||
</Badge>
|
||||
)}
|
||||
{detail.culture_summary && (
|
||||
<Badge variant="default">AI Profile</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Culture summary */}
|
||||
{detail.culture_summary && (
|
||||
<div className="mt-4 rounded-lg bg-muted/50 p-3">
|
||||
<p className="text-xs font-medium text-muted-foreground mb-1">
|
||||
AI Channel Summary
|
||||
</p>
|
||||
<p className="text-sm whitespace-pre-wrap">
|
||||
{detail.culture_summary}
|
||||
</p>
|
||||
{detail.last_analyzed_at && (
|
||||
<p className="mt-1 text-[11px] text-muted-foreground">
|
||||
Last analyzed:{" "}
|
||||
{new Date(detail.last_analyzed_at).toLocaleString()}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</motion.div>
|
||||
|
||||
{/* Stats grid */}
|
||||
<motion.div variants={cardItem} className="grid gap-4 sm:grid-cols-3">
|
||||
<Card>
|
||||
<CardContent className="p-4 text-center">
|
||||
<p className="text-2xl font-bold text-primary">
|
||||
{detail.total_messages.toLocaleString()}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Total Messages
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardContent className="p-4 text-center">
|
||||
<p className="text-2xl font-bold text-emerald-600">
|
||||
{detail.clean_count.toLocaleString()}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">Clean</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardContent className="p-4 text-center">
|
||||
<p
|
||||
className={cn(
|
||||
"text-2xl font-bold",
|
||||
detail.flagged_count > 0
|
||||
? "text-destructive"
|
||||
: "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{detail.flagged_count.toLocaleString()}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">Flagged</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</motion.div>
|
||||
|
||||
{/* Recent messages */}
|
||||
<motion.div variants={cardItem}>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-primary">Recent Messages</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{detail.recent_messages.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
No messages found.
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-2 max-h-80 overflow-y-auto">
|
||||
{detail.recent_messages.map((msg) => (
|
||||
<div
|
||||
key={msg.id}
|
||||
className="rounded-lg border border-border p-3 text-sm"
|
||||
>
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<p className="line-clamp-2 flex-1 break-words text-xs text-foreground">
|
||||
{msg.content}
|
||||
</p>
|
||||
{msg.ai_status && (
|
||||
<span
|
||||
className={cn(
|
||||
"shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium",
|
||||
msg.ai_status === "flagged"
|
||||
? "bg-red-100 text-red-700"
|
||||
: msg.ai_status === "clean"
|
||||
? "bg-emerald-100 text-emerald-700"
|
||||
: msg.ai_status === "warn"
|
||||
? "bg-amber-100 text-amber-700"
|
||||
: "bg-muted text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{msg.ai_status}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-1 text-[10px] text-muted-foreground">
|
||||
{msg.username ?? "unknown"} ·{" "}
|
||||
{new Date(msg.created_at).toLocaleString()}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</motion.div>
|
||||
</>
|
||||
)}
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
|
||||
function DetailSkeleton() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<div className="flex items-start gap-4">
|
||||
<Skeleton className="h-16 w-16 rounded-full" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<Skeleton className="h-5 w-40" />
|
||||
<Skeleton className="h-3 w-60" />
|
||||
<div className="flex gap-2 mt-2">
|
||||
<Skeleton className="h-5 w-20 rounded-full" />
|
||||
<Skeleton className="h-5 w-24 rounded-full" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Skeleton className="mt-4 h-20 w-full rounded-lg" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="grid gap-4 sm:grid-cols-3">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardContent className="p-4 text-center space-y-1">
|
||||
<Skeleton className="mx-auto h-7 w-16" />
|
||||
<Skeleton className="mx-auto h-3 w-20" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<ProfileDetail
|
||||
loading={loading}
|
||||
error={error}
|
||||
onRetry={onRefetch}
|
||||
onBack={onBack}
|
||||
icon={<Hash className="h-8 w-8" />}
|
||||
title={detail ? `#${detail.channel_name ?? detail.channel_id}` : ""}
|
||||
subtitle={detail?.channel_id}
|
||||
summaryLabel="AI Channel Summary"
|
||||
summaryText={detail?.culture_summary ?? undefined}
|
||||
lastAnalyzedLabel={
|
||||
detail?.last_analyzed_at
|
||||
? `Last analyzed: ${new Date(detail.last_analyzed_at).toLocaleString()}`
|
||||
: undefined
|
||||
}
|
||||
stats={{
|
||||
totalLabel: "Total Messages",
|
||||
totalValue: detail?.total_messages ?? 0,
|
||||
cleanLabel: "Clean",
|
||||
cleanValue: detail?.clean_count ?? 0,
|
||||
flaggedLabel: "Flagged",
|
||||
flaggedValue: detail?.flagged_count ?? 0,
|
||||
}}
|
||||
messages={
|
||||
detail?.recent_messages.map((msg) => ({
|
||||
id: msg.id,
|
||||
content: msg.content,
|
||||
created_at: new Date(msg.created_at).toISOString(),
|
||||
ai_status: msg.ai_status,
|
||||
})) ?? []
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { motion } from "framer-motion";
|
||||
import { AlertCircle, Hash, Loader2, RefreshCw, Search } from "lucide-react";
|
||||
import { Hash } from "lucide-react";
|
||||
import type { DashboardChannel } from "../../../shared/api/client";
|
||||
import { cardItem, cardStagger } from "../../../shared/hooks/useFramerStagger";
|
||||
import { cn } from "../../../shared/lib/utils";
|
||||
import { Card, CardContent, Input, Skeleton } from "../../../shared/ui";
|
||||
import { SummaryList } from "../../../shared/ui";
|
||||
import type { SummaryItem } from "../../../shared/ui";
|
||||
|
||||
interface ChannelSummaryListProps {
|
||||
channels: DashboardChannel[];
|
||||
@@ -28,148 +26,31 @@ export function ChannelSummaryList({
|
||||
onRefetch,
|
||||
onSelectChannel,
|
||||
}: ChannelSummaryListProps) {
|
||||
const items: SummaryItem[] = channels.map((ch) => ({
|
||||
id: ch.channel_id,
|
||||
label: `#${ch.channel_name ?? ch.channel_id}`,
|
||||
subtitle: ch.flagged_count > 0 ? `${ch.flagged_count} flagged` : undefined,
|
||||
summaryText: ch.culture_summary ?? `${ch.total_messages} messages`,
|
||||
onClick: () => onSelectChannel(ch.channel_id),
|
||||
}));
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
className="grid gap-6"
|
||||
variants={cardStagger}
|
||||
initial="initial"
|
||||
animate="animate"
|
||||
>
|
||||
{/* Search bar */}
|
||||
<motion.div variants={cardItem} className="flex items-center gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-primary" />
|
||||
<Input
|
||||
className="pl-9 rounded-full focus-visible:ring-primary"
|
||||
placeholder="Search by channel name or ID..."
|
||||
value={search}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
/>
|
||||
<SummaryList
|
||||
items={items}
|
||||
loading={loading}
|
||||
error={error}
|
||||
searchValue={search}
|
||||
onSearchChange={onSearchChange}
|
||||
onRetry={onRefetch}
|
||||
hasMore={hasMore}
|
||||
onLoadMore={onLoadMore}
|
||||
loadingMore={loading}
|
||||
renderIcon={() => (
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-muted">
|
||||
<Hash className="h-5 w-5 text-muted-foreground" />
|
||||
</div>
|
||||
</motion.div>
|
||||
|
||||
{/* Error state */}
|
||||
{error && (
|
||||
<motion.div
|
||||
variants={cardItem}
|
||||
className="flex flex-col items-center gap-4 py-10 text-muted-foreground"
|
||||
>
|
||||
<AlertCircle className="h-10 w-10 text-destructive" />
|
||||
<p className="text-sm">{error}</p>
|
||||
<button
|
||||
onClick={onRefetch}
|
||||
className="inline-flex items-center gap-1.5 rounded-xl border border-border px-4 py-2 text-sm font-medium hover:bg-accent transition-colors"
|
||||
>
|
||||
<RefreshCw className="h-4 w-4" /> Retry
|
||||
</button>
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* Loading state */}
|
||||
{loading && channels.length === 0 && !error && <ChannelListSkeleton />}
|
||||
|
||||
{/* Empty state */}
|
||||
{!loading && !error && channels.length === 0 && (
|
||||
<motion.div
|
||||
variants={cardItem}
|
||||
className="flex flex-col items-center gap-4 py-20 text-muted-foreground"
|
||||
>
|
||||
<Hash className="h-10 w-10" />
|
||||
<p className="text-sm">No channels found.</p>
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* Channel cards */}
|
||||
{channels.length > 0 && (
|
||||
<motion.div variants={cardItem} className="grid gap-3 sm:grid-cols-2">
|
||||
{channels.map((ch) => (
|
||||
<button
|
||||
key={ch.channel_id}
|
||||
onClick={() => onSelectChannel(ch.channel_id)}
|
||||
className="group w-full text-left"
|
||||
>
|
||||
<Card className="transition-all hover:ring-1 hover:ring-primary/30 cursor-pointer">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
{/* Icon */}
|
||||
<div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-muted">
|
||||
<Hash className="h-5 w-5 text-muted-foreground" />
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="truncate text-sm font-semibold">
|
||||
#{ch.channel_name ?? ch.channel_id}
|
||||
</span>
|
||||
{ch.flagged_count > 0 && (
|
||||
<span className="shrink-0 rounded-full bg-red-100 px-2 py-0.5 text-[10px] font-medium text-red-700">
|
||||
{ch.flagged_count} flagged
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{ch.culture_summary && (
|
||||
<p className="mt-1 line-clamp-2 text-xs text-muted-foreground">
|
||||
{ch.culture_summary}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="mt-1.5 flex items-center gap-3 text-[11px] text-muted-foreground">
|
||||
<span>{ch.total_messages} messages</span>
|
||||
{ch.last_message_at && (
|
||||
<span>
|
||||
Last{" "}
|
||||
{new Date(ch.last_message_at).toLocaleDateString()}
|
||||
</span>
|
||||
)}
|
||||
{ch.culture_summary && (
|
||||
<span className="text-emerald-600">AI Summary</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</button>
|
||||
))}
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* Load more */}
|
||||
{hasMore && (
|
||||
<motion.div variants={cardItem} className="flex justify-center">
|
||||
<button
|
||||
onClick={onLoadMore}
|
||||
disabled={loading}
|
||||
className="inline-flex items-center gap-2 rounded-xl border border-border px-6 py-2 text-sm font-medium hover:bg-accent transition-colors disabled:opacity-50"
|
||||
>
|
||||
{loading && <Loader2 className="h-4 w-4 animate-spin" />}
|
||||
{loading ? "Loading..." : "Load More"}
|
||||
</button>
|
||||
</motion.div>
|
||||
)}
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
|
||||
function ChannelListSkeleton() {
|
||||
return (
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<Skeleton className="h-10 w-10 rounded-full" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<Skeleton className="h-3 w-full" />
|
||||
<Skeleton className="h-3 w-24" />
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
emptyMessage="No channels found."
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
Skeleton,
|
||||
StatusBadge,
|
||||
} from "../../../shared/ui";
|
||||
import { useDashboardStats } from "../hooks/useDashboard";
|
||||
import { useUIState } from "../../../shared/hooks/useUIState";
|
||||
@@ -189,7 +190,12 @@ export function DashboardStatsContent() {
|
||||
<CardTitle className="text-primary">Moderation Queue</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid gap-4 sm:grid-cols-3">
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<StatusBadge status="pending" />
|
||||
<StatusBadge status="processing" />
|
||||
<StatusBadge status="error" />
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-3 mt-4">
|
||||
<div className="rounded-xl border border-border bg-card p-4 text-center">
|
||||
<p className="text-2xl font-bold text-muted-foreground">
|
||||
{stats.moderation_overview.pending}
|
||||
|
||||
@@ -1,20 +1,6 @@
|
||||
import { motion } from "framer-motion";
|
||||
import { AlertCircle, ArrowLeft, RefreshCw, User } from "lucide-react";
|
||||
import { User } from "lucide-react";
|
||||
import type { DashboardUserDetail } from "../../../shared/api/client";
|
||||
import {
|
||||
cardItem,
|
||||
cardStagger,
|
||||
fadeSlideUp,
|
||||
} from "../../../shared/hooks/useFramerStagger";
|
||||
import { cn } from "../../../shared/lib/utils";
|
||||
import {
|
||||
Badge,
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
Skeleton,
|
||||
} from "../../../shared/ui";
|
||||
import { ProfileDetail } from "../../../shared/ui";
|
||||
|
||||
interface UserProfileDetailProps {
|
||||
detail: DashboardUserDetail | null;
|
||||
@@ -31,247 +17,50 @@ export function UserProfileDetail({
|
||||
onBack,
|
||||
onRefetch,
|
||||
}: UserProfileDetailProps) {
|
||||
if (!detail && !loading && !error) return null;
|
||||
|
||||
const icon = detail?.avatar_url ? (
|
||||
<img
|
||||
src={detail.avatar_url}
|
||||
alt=""
|
||||
className="h-16 w-16 rounded-full object-cover ring-2 ring-border"
|
||||
/>
|
||||
) : (
|
||||
<User className="h-8 w-8" />
|
||||
);
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
className="grid gap-6"
|
||||
variants={cardStagger}
|
||||
initial="initial"
|
||||
animate="animate"
|
||||
>
|
||||
{/* Back button */}
|
||||
<motion.div variants={cardItem}>
|
||||
<button
|
||||
onClick={onBack}
|
||||
className="inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" /> Back to users
|
||||
</button>
|
||||
</motion.div>
|
||||
|
||||
{/* Loading */}
|
||||
{loading && <DetailSkeleton />}
|
||||
|
||||
{/* Error */}
|
||||
{error && (
|
||||
<motion.div
|
||||
variants={cardItem}
|
||||
className="flex flex-col items-center gap-4 py-20 text-muted-foreground"
|
||||
>
|
||||
<AlertCircle className="h-10 w-10 text-destructive" />
|
||||
<p className="text-sm">{error}</p>
|
||||
<button
|
||||
onClick={onRefetch}
|
||||
className="inline-flex items-center gap-1.5 rounded-xl border border-border px-4 py-2 text-sm font-medium hover:bg-accent transition-colors"
|
||||
>
|
||||
<RefreshCw className="h-4 w-4" /> Retry
|
||||
</button>
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{detail && !error && (
|
||||
<>
|
||||
{/* Profile header */}
|
||||
<motion.div variants={cardItem}>
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<div className="flex items-start gap-4">
|
||||
{/* Avatar */}
|
||||
<div className="shrink-0">
|
||||
{detail.avatar_url ? (
|
||||
<img
|
||||
src={detail.avatar_url}
|
||||
alt={detail.username ?? "User"}
|
||||
className="h-16 w-16 rounded-full object-cover ring-2 ring-border"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-16 w-16 items-center justify-center rounded-full bg-muted ring-2 ring-border">
|
||||
<User className="h-8 w-8 text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div className="min-w-0 flex-1">
|
||||
<h2 className="text-lg font-bold">
|
||||
{detail.username ?? detail.user_id}
|
||||
</h2>
|
||||
<p className="mt-0.5 truncate font-mono text-xs text-muted-foreground">
|
||||
{detail.user_id}
|
||||
</p>
|
||||
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2">
|
||||
{detail.trust_score !== null && (
|
||||
<Badge
|
||||
variant={
|
||||
detail.trust_score >= 80
|
||||
? "success"
|
||||
: detail.trust_score >= 50
|
||||
? "warning"
|
||||
: "destructive"
|
||||
}
|
||||
>
|
||||
Trust: {detail.trust_score}
|
||||
</Badge>
|
||||
)}
|
||||
{detail.total_infractions !== null &&
|
||||
detail.total_infractions > 0 && (
|
||||
<Badge variant="destructive">
|
||||
{detail.total_infractions} infractions
|
||||
</Badge>
|
||||
)}
|
||||
{detail.clean_message_streak !== null &&
|
||||
detail.clean_message_streak > 0 && (
|
||||
<Badge variant="success">
|
||||
Streak: {detail.clean_message_streak}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Profile summary */}
|
||||
{detail.profile_summary && (
|
||||
<div className="mt-4 rounded-lg bg-muted/50 p-3">
|
||||
<p className="text-xs font-medium text-muted-foreground mb-1">
|
||||
AI Profile Summary
|
||||
</p>
|
||||
<p className="text-sm whitespace-pre-wrap">
|
||||
{detail.profile_summary}
|
||||
</p>
|
||||
{detail.last_analyzed_at && (
|
||||
<p className="mt-1 text-[11px] text-muted-foreground">
|
||||
Last analyzed:{" "}
|
||||
{new Date(detail.last_analyzed_at).toLocaleString()}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</motion.div>
|
||||
|
||||
{/* Stats grid */}
|
||||
<motion.div variants={cardItem} className="grid gap-4 sm:grid-cols-3">
|
||||
<Card>
|
||||
<CardContent className="p-4 text-center">
|
||||
<p className="text-2xl font-bold text-primary">
|
||||
{detail.total_messages.toLocaleString()}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Total Messages
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardContent className="p-4 text-center">
|
||||
<p className="text-2xl font-bold text-emerald-600">
|
||||
{detail.clean_count.toLocaleString()}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">Clean</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardContent className="p-4 text-center">
|
||||
<p
|
||||
className={cn(
|
||||
"text-2xl font-bold",
|
||||
detail.flagged_count > 0
|
||||
? "text-destructive"
|
||||
: "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{detail.flagged_count.toLocaleString()}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">Flagged</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</motion.div>
|
||||
|
||||
{/* Recent messages */}
|
||||
<motion.div variants={cardItem}>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-primary">Recent Messages</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{detail.recent_messages.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
No messages found.
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-2 max-h-80 overflow-y-auto">
|
||||
{detail.recent_messages.map((msg) => (
|
||||
<div
|
||||
key={msg.id}
|
||||
className="rounded-lg border border-border p-3 text-sm"
|
||||
>
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<p className="line-clamp-2 flex-1 break-words text-xs text-foreground">
|
||||
{msg.content}
|
||||
</p>
|
||||
{msg.ai_status && (
|
||||
<span
|
||||
className={cn(
|
||||
"shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium",
|
||||
msg.ai_status === "flagged"
|
||||
? "bg-red-100 text-red-700"
|
||||
: msg.ai_status === "clean"
|
||||
? "bg-emerald-100 text-emerald-700"
|
||||
: msg.ai_status === "warn"
|
||||
? "bg-amber-100 text-amber-700"
|
||||
: "bg-muted text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{msg.ai_status}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-1 text-[10px] text-muted-foreground">
|
||||
#{msg.channel_id} ·{" "}
|
||||
{new Date(msg.created_at).toLocaleString()}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</motion.div>
|
||||
</>
|
||||
)}
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
|
||||
function DetailSkeleton() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<div className="flex items-start gap-4">
|
||||
<Skeleton className="h-16 w-16 rounded-full" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<Skeleton className="h-5 w-40" />
|
||||
<Skeleton className="h-3 w-60" />
|
||||
<div className="flex gap-2 mt-2">
|
||||
<Skeleton className="h-5 w-20 rounded-full" />
|
||||
<Skeleton className="h-5 w-24 rounded-full" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Skeleton className="mt-4 h-20 w-full rounded-lg" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="grid gap-4 sm:grid-cols-3">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardContent className="p-4 text-center space-y-1">
|
||||
<Skeleton className="mx-auto h-7 w-16" />
|
||||
<Skeleton className="mx-auto h-3 w-20" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<ProfileDetail
|
||||
loading={loading}
|
||||
error={error}
|
||||
onRetry={onRefetch}
|
||||
onBack={onBack}
|
||||
icon={icon}
|
||||
title={detail?.username ?? detail?.user_id ?? ""}
|
||||
subtitle={detail?.user_id}
|
||||
summaryLabel="AI Profile Summary"
|
||||
summaryText={detail?.profile_summary ?? undefined}
|
||||
lastAnalyzedLabel={
|
||||
detail?.last_analyzed_at
|
||||
? `Last analyzed: ${new Date(detail.last_analyzed_at).toLocaleString()}`
|
||||
: undefined
|
||||
}
|
||||
stats={{
|
||||
totalLabel: "Total Messages",
|
||||
totalValue: detail?.total_messages ?? 0,
|
||||
cleanLabel: "Clean",
|
||||
cleanValue: detail?.clean_count ?? 0,
|
||||
flaggedLabel: "Flagged",
|
||||
flaggedValue: detail?.flagged_count ?? 0,
|
||||
}}
|
||||
messages={
|
||||
detail?.recent_messages.map((msg) => ({
|
||||
id: msg.id,
|
||||
content: msg.content,
|
||||
created_at: new Date(msg.created_at).toISOString(),
|
||||
ai_status: msg.ai_status,
|
||||
})) ?? []
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import { motion } from "framer-motion";
|
||||
import { AlertCircle, Loader2, RefreshCw, Search, User } from "lucide-react";
|
||||
import { User } from "lucide-react";
|
||||
import type { DashboardUser } from "../../../shared/api/client";
|
||||
import { cardItem, cardStagger } from "../../../shared/hooks/useFramerStagger";
|
||||
import { cn } from "../../../shared/lib/utils";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
Input,
|
||||
Skeleton,
|
||||
} from "../../../shared/ui";
|
||||
import { SummaryList } from "../../../shared/ui";
|
||||
import type { SummaryItem } from "../../../shared/ui";
|
||||
|
||||
interface UserSummaryListProps {
|
||||
users: DashboardUser[];
|
||||
@@ -35,163 +26,42 @@ export function UserSummaryList({
|
||||
onRefetch,
|
||||
onSelectUser,
|
||||
}: UserSummaryListProps) {
|
||||
const items: SummaryItem[] = users.map((u) => ({
|
||||
id: u.user_id,
|
||||
label: u.username ?? u.user_id,
|
||||
subtitle: u.trust_score !== null ? `Trust: ${u.trust_score}` : undefined,
|
||||
summaryText: u.profile_summary ?? `${u.total_messages} messages`,
|
||||
onClick: () => onSelectUser(u.user_id),
|
||||
}));
|
||||
|
||||
const avatarMap = new Map(users.map((u) => [u.user_id, u.avatar_url]));
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
className="grid gap-6"
|
||||
variants={cardStagger}
|
||||
initial="initial"
|
||||
animate="animate"
|
||||
>
|
||||
{/* Search bar */}
|
||||
<motion.div variants={cardItem} className="flex items-center gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-primary" />
|
||||
<Input
|
||||
className="pl-9 rounded-full focus-visible:ring-primary"
|
||||
placeholder="Search by username or user ID..."
|
||||
value={search}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
<SummaryList
|
||||
items={items}
|
||||
loading={loading}
|
||||
error={error}
|
||||
searchValue={search}
|
||||
onSearchChange={onSearchChange}
|
||||
onRetry={onRefetch}
|
||||
hasMore={hasMore}
|
||||
onLoadMore={onLoadMore}
|
||||
loadingMore={loading}
|
||||
renderIcon={(item) => {
|
||||
const avatarUrl = avatarMap.get(item.id);
|
||||
return avatarUrl ? (
|
||||
<img
|
||||
src={avatarUrl}
|
||||
alt=""
|
||||
className="h-10 w-10 rounded-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
</motion.div>
|
||||
|
||||
{/* Error state */}
|
||||
{error && (
|
||||
<motion.div
|
||||
variants={cardItem}
|
||||
className="flex flex-col items-center gap-4 py-10 text-muted-foreground"
|
||||
>
|
||||
<AlertCircle className="h-10 w-10 text-destructive" />
|
||||
<p className="text-sm">{error}</p>
|
||||
<button
|
||||
onClick={onRefetch}
|
||||
className="inline-flex items-center gap-1.5 rounded-xl border border-border px-4 py-2 text-sm font-medium hover:bg-accent transition-colors"
|
||||
>
|
||||
<RefreshCw className="h-4 w-4" /> Retry
|
||||
</button>
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* Loading state */}
|
||||
{loading && users.length === 0 && !error && <UserListSkeleton />}
|
||||
|
||||
{/* Empty state */}
|
||||
{!loading && !error && users.length === 0 && (
|
||||
<motion.div
|
||||
variants={cardItem}
|
||||
className="flex flex-col items-center gap-4 py-20 text-muted-foreground"
|
||||
>
|
||||
<User className="h-10 w-10" />
|
||||
<p className="text-sm">No users found.</p>
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* User cards */}
|
||||
{users.length > 0 && (
|
||||
<motion.div variants={cardItem} className="grid gap-3 sm:grid-cols-2">
|
||||
{users.map((u) => (
|
||||
<button
|
||||
key={u.user_id}
|
||||
onClick={() => onSelectUser(u.user_id)}
|
||||
className="group w-full text-left"
|
||||
>
|
||||
<Card className="transition-all hover:ring-1 hover:ring-primary/30 cursor-pointer">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
{/* Avatar */}
|
||||
<div className="shrink-0">
|
||||
{u.avatar_url ? (
|
||||
<img
|
||||
src={u.avatar_url}
|
||||
alt={u.username ?? "User"}
|
||||
className="h-10 w-10 rounded-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-muted">
|
||||
<User className="h-5 w-5 text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="truncate text-sm font-semibold">
|
||||
{u.username ?? u.user_id}
|
||||
</span>
|
||||
{u.trust_score !== null && (
|
||||
<span
|
||||
className={cn(
|
||||
"shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium",
|
||||
u.trust_score >= 80
|
||||
? "bg-emerald-100 text-emerald-700"
|
||||
: u.trust_score >= 50
|
||||
? "bg-amber-100 text-amber-700"
|
||||
: "bg-red-100 text-red-700",
|
||||
)}
|
||||
>
|
||||
{u.trust_score}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{u.profile_summary && (
|
||||
<p className="mt-1 line-clamp-2 text-xs text-muted-foreground">
|
||||
{u.profile_summary}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="mt-1.5 flex items-center gap-3 text-[11px] text-muted-foreground">
|
||||
<span>{u.total_messages} messages</span>
|
||||
{u.flagged_count > 0 && (
|
||||
<span className="text-destructive">
|
||||
{u.flagged_count} flagged
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</button>
|
||||
))}
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* Load more */}
|
||||
{hasMore && (
|
||||
<motion.div variants={cardItem} className="flex justify-center">
|
||||
<button
|
||||
onClick={onLoadMore}
|
||||
disabled={loading}
|
||||
className="inline-flex items-center gap-2 rounded-xl border border-border px-6 py-2 text-sm font-medium hover:bg-accent transition-colors disabled:opacity-50"
|
||||
>
|
||||
{loading && <Loader2 className="h-4 w-4 animate-spin" />}
|
||||
{loading ? "Loading..." : "Load More"}
|
||||
</button>
|
||||
</motion.div>
|
||||
)}
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
|
||||
function UserListSkeleton() {
|
||||
return (
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<Skeleton className="h-10 w-10 rounded-full" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<Skeleton className="h-3 w-full" />
|
||||
<Skeleton className="h-3 w-24" />
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-muted">
|
||||
<User className="h-5 w-5 text-muted-foreground" />
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
emptyMessage="No users found."
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
listDashboardChannels,
|
||||
listDashboardUsers,
|
||||
} from "../../../shared/api/client";
|
||||
import { useItemDetail } from "../../../shared/hooks/useItemDetail";
|
||||
import { usePaginatedList } from "../../../shared/hooks/usePaginatedList";
|
||||
|
||||
const logger = console;
|
||||
|
||||
@@ -48,58 +50,25 @@ export function useDashboardStats() {
|
||||
* Fetch paginated user list with optional search.
|
||||
*/
|
||||
export function useDashboardUsers() {
|
||||
const [users, setUsers] = useState<DashboardUser[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [nextCursor, setNextCursor] = useState<string | null>(null);
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
const fetchUsers = useCallback(
|
||||
async (cursor?: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await listDashboardUsers({
|
||||
limit: 20,
|
||||
cursor,
|
||||
search: search || undefined,
|
||||
});
|
||||
if (cursor) {
|
||||
setUsers((prev) => [...prev, ...result.data]);
|
||||
} else {
|
||||
setUsers(result.data);
|
||||
}
|
||||
setNextCursor(result.nextCursor);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : "Failed to load users";
|
||||
setError(msg);
|
||||
logger.error("[useDashboardUsers]", msg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[search],
|
||||
const paginated = usePaginatedList(
|
||||
(params) =>
|
||||
listDashboardUsers({
|
||||
limit: params.limit,
|
||||
search: params.search,
|
||||
cursor: params.cursor,
|
||||
}).then((r) => ({ data: r.data, nextCursor: r.nextCursor })),
|
||||
"",
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
fetchUsers().catch(() => undefined);
|
||||
}, [fetchUsers]);
|
||||
|
||||
const loadMore = useCallback(() => {
|
||||
if (nextCursor && !loading) {
|
||||
fetchUsers(nextCursor).catch(() => undefined);
|
||||
}
|
||||
}, [nextCursor, loading, fetchUsers]);
|
||||
|
||||
return {
|
||||
users,
|
||||
loading,
|
||||
error,
|
||||
search,
|
||||
setSearch,
|
||||
loadMore,
|
||||
hasMore: !!nextCursor,
|
||||
refetch: () => fetchUsers().catch(() => undefined),
|
||||
users: paginated.data,
|
||||
loading: paginated.loading,
|
||||
error: paginated.error,
|
||||
search: paginated.search,
|
||||
setSearch: paginated.setSearch,
|
||||
loadMore: paginated.loadMore,
|
||||
hasMore: paginated.hasMore,
|
||||
refetch: paginated.refetch,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -107,92 +76,40 @@ export function useDashboardUsers() {
|
||||
* Fetch a single user detail by userId.
|
||||
*/
|
||||
export function useDashboardUserDetail(userId: string | null) {
|
||||
const [detail, setDetail] = useState<DashboardUserDetail | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { data, loading, error, refetch } = useItemDetail(
|
||||
(_guildId, entityId) => getDashboardUserDetail(entityId),
|
||||
"",
|
||||
userId,
|
||||
"user",
|
||||
);
|
||||
|
||||
const fetch = useCallback(async () => {
|
||||
if (!userId) return;
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const data = await getDashboardUserDetail(userId);
|
||||
if (!data) {
|
||||
setError("User not found");
|
||||
return;
|
||||
}
|
||||
setDetail(data);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : "Failed to load user detail";
|
||||
setError(msg);
|
||||
logger.error("[useDashboardUserDetail]", msg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [userId]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch().catch(() => undefined);
|
||||
}, [fetch]);
|
||||
|
||||
return { detail, loading, error, refetch: fetch };
|
||||
return { detail: data, loading, error, refetch };
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch paginated channel list with optional search.
|
||||
*/
|
||||
export function useDashboardChannels() {
|
||||
const [channels, setChannels] = useState<DashboardChannel[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [nextCursor, setNextCursor] = useState<string | null>(null);
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
const fetchChannels = useCallback(
|
||||
async (cursor?: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await listDashboardChannels({
|
||||
limit: 20,
|
||||
search: search || undefined,
|
||||
});
|
||||
if (cursor) {
|
||||
setChannels((prev) => [...prev, ...result.data]);
|
||||
} else {
|
||||
setChannels(result.data);
|
||||
}
|
||||
setNextCursor(result.nextCursor);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : "Failed to load channels";
|
||||
setError(msg);
|
||||
logger.error("[useDashboardChannels]", msg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[search],
|
||||
const paginated = usePaginatedList(
|
||||
(params) =>
|
||||
listDashboardChannels({
|
||||
limit: params.limit,
|
||||
search: params.search,
|
||||
guild_id: params.guildId,
|
||||
cursor: params.cursor,
|
||||
}).then((r) => ({ data: r.data, nextCursor: r.nextCursor })),
|
||||
"",
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
fetchChannels().catch(() => undefined);
|
||||
}, [fetchChannels]);
|
||||
|
||||
const loadMore = useCallback(() => {
|
||||
if (nextCursor && !loading) {
|
||||
fetchChannels(nextCursor).catch(() => undefined);
|
||||
}
|
||||
}, [nextCursor, loading, fetchChannels]);
|
||||
|
||||
return {
|
||||
channels,
|
||||
loading,
|
||||
error,
|
||||
search,
|
||||
setSearch,
|
||||
loadMore,
|
||||
hasMore: !!nextCursor,
|
||||
refetch: () => fetchChannels().catch(() => undefined),
|
||||
channels: paginated.data,
|
||||
loading: paginated.loading,
|
||||
error: paginated.error,
|
||||
search: paginated.search,
|
||||
setSearch: paginated.setSearch,
|
||||
loadMore: paginated.loadMore,
|
||||
hasMore: paginated.hasMore,
|
||||
refetch: paginated.refetch,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -200,34 +117,12 @@ export function useDashboardChannels() {
|
||||
* Fetch a single channel detail by channelId.
|
||||
*/
|
||||
export function useDashboardChannelDetail(channelId: string | null) {
|
||||
const [detail, setDetail] = useState<DashboardChannelDetail | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { data, loading, error, refetch } = useItemDetail(
|
||||
(_guildId, entityId) => getDashboardChannelDetail(entityId),
|
||||
"",
|
||||
channelId,
|
||||
"channel",
|
||||
);
|
||||
|
||||
const fetch = useCallback(async () => {
|
||||
if (!channelId) return;
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const data = await getDashboardChannelDetail(channelId);
|
||||
if (!data) {
|
||||
setError("Channel not found");
|
||||
return;
|
||||
}
|
||||
setDetail(data);
|
||||
} catch (e) {
|
||||
const msg =
|
||||
e instanceof Error ? e.message : "Failed to load channel detail";
|
||||
setError(msg);
|
||||
logger.error("[useDashboardChannelDetail]", msg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [channelId]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch().catch(() => undefined);
|
||||
}, [fetch]);
|
||||
|
||||
return { detail, loading, error, refetch: fetch };
|
||||
return { detail: data, loading, error, refetch };
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { Fragment, useMemo, useState } from "react";
|
||||
import { parseMetadata } from "../../../entities/message/types";
|
||||
import type { MessageRecord } from "../../../shared/api/client";
|
||||
import { Badge, Button, Skeleton } from "../../../shared/ui";
|
||||
import { Badge, Button, Skeleton, StatusBadge } from "../../../shared/ui";
|
||||
|
||||
const CUSTOM_EMOJI_REGEX = /<(a)?:([a-zA-Z0-9_]+):(\d+)>/g;
|
||||
|
||||
@@ -194,15 +194,11 @@ function MessageRow({
|
||||
</span>
|
||||
)}
|
||||
<div className="ml-auto flex items-center gap-1">
|
||||
<Badge
|
||||
variant={aiVariant(aiStatus)}
|
||||
className="flex items-center gap-1 text-[10px] px-1.5 py-0"
|
||||
>
|
||||
<StatusBadge status={aiStatus} className="text-[10px] px-1.5 py-0">
|
||||
{aiStatus === "clean" && <CheckCircle2 className="h-3 w-3" />}
|
||||
{aiStatus === "flagged" && <AlertCircle className="h-3 w-3" />}
|
||||
{aiStatus === "error" && <AlertCircle className="h-3 w-3" />}
|
||||
{aiStatus}
|
||||
</Badge>
|
||||
</StatusBadge>
|
||||
{message.ai_severity && message.ai_severity !== "none" && (
|
||||
<Badge
|
||||
className={`text-[10px] px-1.5 py-0 ${severityColor(message.ai_severity)}`}
|
||||
|
||||
Reference in New Issue
Block a user