From 9b22814c288e814bf0e589406cc416c681f1c987 Mon Sep 17 00:00:00 2001 From: Bhavesh Mandalapu Date: Sun, 26 Apr 2026 14:19:13 -0500 Subject: [PATCH 1/3] Fix claim validation page claim count issue --- app/claim-validation/page.tsx | 48 +++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/app/claim-validation/page.tsx b/app/claim-validation/page.tsx index 8e8b86f..6a76d01 100644 --- a/app/claim-validation/page.tsx +++ b/app/claim-validation/page.tsx @@ -69,6 +69,7 @@ function mergeUniqueSorted(apiList: string[] | undefined, derived: string[]): st export default function ClaimValidationPage() { const [claims, setClaims] = useState([]) + const [apiStats, setApiStats] = useState<{ total: number; verified: number; disputed: number; under_review: number } | undefined>(undefined) const [filterMeta, setFilterMeta] = useState(undefined) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) @@ -86,12 +87,29 @@ export default function ClaimValidationPage() { const filterWrapRef = useRef(null) useEffect(() => { - apiFetch("/claims") - .then((response) => { - setClaims(response.data) - setFilterMeta(response.filter_options) - setError(null) - }) + const PAGE_LIMIT = 200 + async function fetchAllClaims() { + const first = await apiFetch(`/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(`/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)) }, []) @@ -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") { @@ -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) From ce2266cb1fb7df74113bf150d832954a6f1dbae9 Mon Sep 17 00:00:00 2001 From: Bhavesh Mandalapu Date: Sun, 26 Apr 2026 14:34:37 -0500 Subject: [PATCH 2/3] Fix trend analytics page graph --- app/trend-analytics/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/trend-analytics/page.tsx b/app/trend-analytics/page.tsx index b6bd635..98ff4f7 100644 --- a/app/trend-analytics/page.tsx +++ b/app/trend-analytics/page.tsx @@ -36,7 +36,7 @@ export default function TrendAnalyticsPage() { const [narratives, setNarratives] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); - const [range, setRange] = useState("30d"); + const [range, setRange] = useState("6m"); useEffect(() => { Promise.all([ From b824f45d52078937ab15531b996baa411b815d1b Mon Sep 17 00:00:00 2001 From: Bhavesh Mandalapu Date: Sun, 26 Apr 2026 14:50:52 -0500 Subject: [PATCH 3/3] Trend analytics sentiment shift graph --- app/trend-analytics/page.tsx | 67 +++++++++++++++++++++++++++++++++--- lib/types/sentiment.ts | 25 ++++++++++++++ 2 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 lib/types/sentiment.ts diff --git a/app/trend-analytics/page.tsx b/app/trend-analytics/page.tsx index 98ff4f7..3c41e06 100644 --- a/app/trend-analytics/page.tsx +++ b/app/trend-analytics/page.tsx @@ -4,6 +4,8 @@ import { useEffect, useMemo, useState } from "react"; import { AreaChart, Area, + BarChart, + Bar, XAxis, YAxis, Tooltip, @@ -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; @@ -37,6 +40,8 @@ export default function TrendAnalyticsPage() { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [range, setRange] = useState("6m"); + const [sentimentData, setSentimentData] = useState(null); + const [sentimentLoading, setSentimentLoading] = useState(false); useEffect(() => { Promise.all([ @@ -51,6 +56,14 @@ export default function TrendAnalyticsPage() { .finally(() => setLoading(false)); }, []); + useEffect(() => { + setSentimentLoading(true); + apiFetch("/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; @@ -146,10 +159,56 @@ export default function TrendAnalyticsPage() { -
-

Sentiment Shift

-

Sentiment analysis endpoint coming soon.

-

See docs/MISSING_APIS.md for details.

+
+

Sentiment Shift

+ {sentimentData && ( +
+ + + Positive {sentimentData.totals.positive} + + + + Neutral {sentimentData.totals.neutral} + + + + Negative {sentimentData.totals.negative} + +
+ )} +
+ {sentimentLoading ? ( +
+ Loading… +
+ ) : sentimentData && sentimentData.buckets.length > 0 ? ( + + + + + + + + + + + + + ) : ( +
+ No sentiment data for this range. +
+ )} +
diff --git a/lib/types/sentiment.ts b/lib/types/sentiment.ts new file mode 100644 index 0000000..3305f1c --- /dev/null +++ b/lib/types/sentiment.ts @@ -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[]; +}