Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions app/claim-validation/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function mergeUniqueSorted(apiList: string[] | undefined, derived: string[]): st

export default function ClaimValidationPage() {
const [claims, setClaims] = useState<ClaimItem[]>([])
const [apiStats, setApiStats] = useState<{ total: number; verified: number; disputed: number; under_review: number } | undefined>(undefined)
const [filterMeta, setFilterMeta] = useState<ClaimFilterOptions | undefined>(undefined)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
Expand All @@ -86,12 +87,29 @@ export default function ClaimValidationPage() {
const filterWrapRef = useRef<HTMLDivElement | null>(null)

useEffect(() => {
apiFetch<ClaimListResponse>("/claims")
.then((response) => {
setClaims(response.data)
setFilterMeta(response.filter_options)
setError(null)
})
const PAGE_LIMIT = 200
async function fetchAllClaims() {
const first = await apiFetch<ClaimListResponse>(`/claims?limit=${PAGE_LIMIT}&skip=0`)
const total = first.count
let all = first.data

if (total > PAGE_LIMIT) {
const remaining = Math.ceil((total - PAGE_LIMIT) / PAGE_LIMIT)
const pages = await Promise.all(
Array.from({ length: remaining }, (_, i) =>
apiFetch<ClaimListResponse>(`/claims?limit=${PAGE_LIMIT}&skip=${(i + 1) * PAGE_LIMIT}`)
)
)
for (const page of pages) all = all.concat(page.data)
}

setClaims(all)
setApiStats(first.stats)
setFilterMeta(first.filter_options)
setError(null)
}

fetchAllClaims()
.catch((err) => setError(err instanceof Error ? err.message : String(err)))
.finally(() => setLoading(false))
}, [])
Expand All @@ -115,9 +133,16 @@ export default function ClaimValidationPage() {
)

const summaryStats = useMemo(() => {
if (apiStats) {
return {
total: apiStats.total,
verified: apiStats.verified,
under_review: apiStats.under_review,
}
}
// Fallback: derive from loaded claims if API stats not yet available
let verified = 0
let underReview = 0

for (const claim of claims) {
const status = normalizeClaimStatus(claim.status)
if (status === "verified" || status === "verified_true") {
Expand All @@ -126,13 +151,8 @@ export default function ClaimValidationPage() {
underReview += 1
}
}

return {
total: claims.length,
verified,
under_review: underReview,
}
}, [claims])
return { total: claims.length, verified, under_review: underReview }
}, [apiStats, claims])

const hasActiveFilters = Boolean(statusFilter || confidenceFilter)

Expand Down
69 changes: 64 additions & 5 deletions app/trend-analytics/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useEffect, useMemo, useState } from "react";
import {
AreaChart,
Area,
BarChart,
Bar,
XAxis,
YAxis,
Tooltip,
Expand All @@ -15,6 +17,7 @@ import { useTheme } from "@/components/layout/ThemeContext";
import { apiFetch } from "@/lib/api";
import type { ExecutiveOverviewResponse } from "@/lib/types/executive-overview";
import type { NarrativeListResponse, NarrativeItem } from "@/lib/types/narrative";
import type { SentimentShiftResponse } from "@/lib/types/sentiment";

type TopicTrend = Record<string, string | number>;

Expand All @@ -36,7 +39,9 @@ export default function TrendAnalyticsPage() {
const [narratives, setNarratives] = useState<NarrativeItem[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [range, setRange] = useState("30d");
const [range, setRange] = useState("6m");
const [sentimentData, setSentimentData] = useState<SentimentShiftResponse | null>(null);
const [sentimentLoading, setSentimentLoading] = useState(false);

useEffect(() => {
Promise.all([
Expand All @@ -51,6 +56,14 @@ export default function TrendAnalyticsPage() {
.finally(() => setLoading(false));
}, []);

useEffect(() => {
setSentimentLoading(true);
apiFetch<SentimentShiftResponse>("/overview/sentiment-shift", { range })
.then((data) => setSentimentData(data))
.catch(() => setSentimentData(null))
.finally(() => setSentimentLoading(false));
}, [range]);

const filteredTrends = useMemo(() => {
if (!execData) return [];
const trends = execData.topic_trends;
Expand Down Expand Up @@ -146,10 +159,56 @@ export default function TrendAnalyticsPage() {
</div>
</div>

<div className="flex flex-col items-center justify-center rounded-xl border border-zinc-200 bg-white p-5 dark:border-zinc-700 dark:bg-zinc-800">
<h3 className="mb-2 font-medium text-zinc-900 dark:text-zinc-100">Sentiment Shift</h3>
<p className="text-sm text-zinc-400 dark:text-zinc-500">Sentiment analysis endpoint coming soon.</p>
<p className="mt-1 text-xs text-zinc-300 dark:text-zinc-600">See docs/MISSING_APIS.md for details.</p>
<div className="rounded-xl border border-zinc-200 bg-white p-5 dark:border-zinc-700 dark:bg-zinc-800">
<h3 className="mb-1 font-medium text-zinc-900 dark:text-zinc-100">Sentiment Shift</h3>
{sentimentData && (
<div className="mb-3 flex gap-4 text-xs text-zinc-500 dark:text-zinc-400">
<span className="flex items-center gap-1">
<span className="inline-block h-2 w-2 rounded-full bg-emerald-500" />
Positive {sentimentData.totals.positive}
</span>
<span className="flex items-center gap-1">
<span className="inline-block h-2 w-2 rounded-full bg-zinc-400" />
Neutral {sentimentData.totals.neutral}
</span>
<span className="flex items-center gap-1">
<span className="inline-block h-2 w-2 rounded-full bg-red-500" />
Negative {sentimentData.totals.negative}
</span>
</div>
)}
<div className="h-60">
{sentimentLoading ? (
<div className="flex h-full items-center justify-center text-sm text-zinc-400 dark:text-zinc-500">
Loading…
</div>
) : sentimentData && sentimentData.buckets.length > 0 ? (
<ResponsiveContainer width="100%" height="100%">
<BarChart data={sentimentData.buckets}>
<CartesianGrid strokeDasharray="3 3" stroke={gridColor} />
<XAxis dataKey="date" tick={{ fill: axisTick, fontSize: 11 }} tickLine={false} axisLine={false} />
<YAxis tick={{ fill: axisTick, fontSize: 11 }} tickLine={false} axisLine={false} />
<Tooltip
contentStyle={{
backgroundColor: tooltipBg,
border: `1px solid ${tooltipBorder}`,
borderRadius: 8,
color: tooltipText,
fontSize: 12,
}}
/>
<Legend wrapperStyle={{ color: axisTick, fontSize: 12 }} />
<Bar dataKey="positive" stackId="s" fill="#10b981" name="Positive" />
<Bar dataKey="neutral" stackId="s" fill="#9ca3af" name="Neutral" />
<Bar dataKey="negative" stackId="s" fill="#ef4444" name="Negative" />
</BarChart>
</ResponsiveContainer>
) : (
<div className="flex h-full items-center justify-center text-sm text-zinc-400 dark:text-zinc-500">
No sentiment data for this range.
</div>
)}
</div>
</div>
</div>

Expand Down
25 changes: 25 additions & 0 deletions lib/types/sentiment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export interface SentimentBucket {
date: string;
positive: number;
neutral: number;
negative: number;
total: number;
avg_score: number | null;
}

export interface SentimentTotals {
positive: number;
neutral: number;
negative: number;
total: number;
avg_score: number | null;
}

export interface SentimentShiftResponse {
ok: boolean;
range: string;
bucket_size_days: number;
window_days: number;
totals: SentimentTotals;
buckets: SentimentBucket[];
}
Loading