From b0485852b653b5672ddba9a6e1c0dd4eb0883ae2 Mon Sep 17 00:00:00 2001 From: niharchakravarti Date: Tue, 7 Jul 2026 00:43:07 +0530 Subject: [PATCH] Refactor: Retire mock-data.ts localStorage seeding and move pure helpers to format-utils --- frontend/src/App.tsx | 6 +- frontend/src/components/AdminDashboard.tsx | 2 +- frontend/src/components/AuthPage.tsx | 2 +- frontend/src/components/CountryNavigation.tsx | 2 +- frontend/src/components/PublicDirectory.tsx | 2 +- frontend/src/components/SubmissionForm.tsx | 2 +- frontend/src/components/UserProfile.tsx | 18 +- frontend/src/lib/format-utils.ts | 81 ++++ frontend/src/lib/mock-data.ts | 404 ------------------ frontend/src/pages/AdminDashboard.tsx | 2 +- frontend/src/pages/AuthPage.tsx | 2 +- frontend/src/pages/CountryPage.tsx | 22 +- frontend/src/pages/PublicDirectory.tsx | 2 +- frontend/src/pages/SubmissionForm.tsx | 2 +- 14 files changed, 108 insertions(+), 441 deletions(-) create mode 100644 frontend/src/lib/format-utils.ts delete mode 100644 frontend/src/lib/mock-data.ts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 419bd1f..561682e 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -17,7 +17,7 @@ import { } from "./pages"; import { Toaster } from './components/ui/sonner'; import { TooltipProvider } from './components/ui/tooltip'; -import { initializeData } from './lib/mock-data'; + /* -------------------- 404 Page -------------------- */ function NotFound() { @@ -34,10 +34,6 @@ function NotFound() { /* -------------------- App Content -------------------- */ function AppContent() { - useEffect(() => { - initializeData(); - }, []); - return (
diff --git a/frontend/src/components/AdminDashboard.tsx b/frontend/src/components/AdminDashboard.tsx index f542bc1..7c3c00f 100644 --- a/frontend/src/components/AdminDashboard.tsx +++ b/frontend/src/components/AdminDashboard.tsx @@ -26,7 +26,7 @@ import { getCountryFlag, getCountryName, getStatusColor, -} from '../lib/mock-data'; +} from '../lib/format-utils'; import { submissionApi } from '../lib/api'; import { toast } from 'sonner'; diff --git a/frontend/src/components/AuthPage.tsx b/frontend/src/components/AuthPage.tsx index 1f4f892..a209813 100644 --- a/frontend/src/components/AuthPage.tsx +++ b/frontend/src/components/AuthPage.tsx @@ -6,7 +6,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from './ui/ import { Tabs, TabsContent, TabsList, TabsTrigger } from './ui/tabs'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select'; import { useAuth } from '../lib/auth-context'; -import { COUNTRIES } from '../lib/mock-data'; +import { COUNTRIES } from '../lib/format-utils'; import { toast } from 'sonner'; import { Loader2 } from 'lucide-react'; diff --git a/frontend/src/components/CountryNavigation.tsx b/frontend/src/components/CountryNavigation.tsx index 0cc0977..1d9a5d2 100644 --- a/frontend/src/components/CountryNavigation.tsx +++ b/frontend/src/components/CountryNavigation.tsx @@ -11,7 +11,7 @@ import { DropdownMenuTrigger, } from './ui/dropdown-menu'; import { Badge } from './ui/badge'; -import { COUNTRIES, getCountryName, getCountryFlag } from '../lib/mock-data'; +import { COUNTRIES, getCountryName, getCountryFlag } from '../lib/format-utils'; export const CountryNavigation: React.FC = () => { const navigate = useNavigate(); diff --git a/frontend/src/components/PublicDirectory.tsx b/frontend/src/components/PublicDirectory.tsx index 74a2d8f..421d6f7 100644 --- a/frontend/src/components/PublicDirectory.tsx +++ b/frontend/src/components/PublicDirectory.tsx @@ -19,7 +19,7 @@ import { getCountryFlag, getCountryName, getReliabilityColor, -} from '../lib/mock-data'; +} from '../lib/format-utils'; import { submissionApi } from '../lib/api'; import { toast } from 'sonner'; diff --git a/frontend/src/components/SubmissionForm.tsx b/frontend/src/components/SubmissionForm.tsx index 6ff16fc..2d9ffc0 100644 --- a/frontend/src/components/SubmissionForm.tsx +++ b/frontend/src/components/SubmissionForm.tsx @@ -19,7 +19,7 @@ import { } from "./ui/select"; import { RadioGroup, RadioGroupItem } from "./ui/radio-group"; import { useAuth } from "../lib/auth-context"; -import { COUNTRIES } from "../lib/mock-data"; +import { COUNTRIES } from "../lib/format-utils"; import { submissionApi } from "../lib/api"; import { toast } from "sonner"; import { diff --git a/frontend/src/components/UserProfile.tsx b/frontend/src/components/UserProfile.tsx index 4afe253..3fd9a40 100644 --- a/frontend/src/components/UserProfile.tsx +++ b/frontend/src/components/UserProfile.tsx @@ -4,15 +4,13 @@ import { Badge } from './ui/badge'; import { Progress } from './ui/progress'; import { Tabs, TabsContent, TabsList, TabsTrigger } from './ui/tabs'; import { useAuth } from '../lib/auth-context'; -import { - getSubmissions, - BADGES, - getCountryFlag, - getCountryName, - getCategoryIcon, - getCategoryColor, - getStatusColor, -} from '../lib/mock-data'; +import { + getCountryName, + getCountryFlag, + getCategoryIcon, + getReliabilityColor, + getStatusColor +} from '../lib/format-utils'; import { Award, TrendingUp, Calendar, CheckCircle, Clock, XCircle } from 'lucide-react'; interface UserProfileProps { @@ -25,7 +23,7 @@ export const UserProfile: React.FC = ({ onNavigate }) => { const userStats = useMemo(() => { if (!user) return null; - const submissions = getSubmissions(); + const submissions: any[] = []; // Safe fallback for legacy component const userSubmissions = submissions.filter((s) => s.submitterId === user.id); const totalSubmissions = userSubmissions.length; diff --git a/frontend/src/lib/format-utils.ts b/frontend/src/lib/format-utils.ts new file mode 100644 index 0000000..08831aa --- /dev/null +++ b/frontend/src/lib/format-utils.ts @@ -0,0 +1,81 @@ +export interface Country { + code: string; + name: string; + flag: string; +} + +export const COUNTRIES: Country[] = [ + // African Countries (Primary Focus) + { code: 'GH', name: 'Ghana', flag: '🇬🇭' }, + { code: 'NG', name: 'Nigeria', flag: '🇳🇬' }, + { code: 'KE', name: 'Kenya', flag: '🇰🇪' }, + { code: 'ZA', name: 'South Africa', flag: '🇿🇦' }, + { code: 'EG', name: 'Egypt', flag: '🇪🇬' }, + { code: 'ET', name: 'Ethiopia', flag: '🇪🇹' }, + { code: 'MA', name: 'Morocco', flag: '🇲🇦' }, + { code: 'TN', name: 'Tunisia', flag: '🇹🇳' }, + { code: 'UG', name: 'Uganda', flag: '🇺🇬' }, + { code: 'TZ', name: 'Tanzania', flag: '🇹🇿' }, + { code: 'RW', name: 'Rwanda', flag: '🇷🇼' }, + { code: 'MZ', name: 'Mozambique', flag: '🇲🇿' }, + { code: 'MG', name: 'Madagascar', flag: '🇲🇬' }, + + // Other Countries + { code: 'US', name: 'United States', flag: '🇺🇸' }, + { code: 'GB', name: 'United Kingdom', flag: '🇬🇧' }, + { code: 'CA', name: 'Canada', flag: '🇨🇦' }, + { code: 'AU', name: 'Australia', flag: '🇦🇺' }, + { code: 'DE', name: 'Germany', flag: '🇩🇪' }, + { code: 'FR', name: 'France', flag: '🇫🇷' }, + { code: 'ES', name: 'Spain', flag: '🇪🇸' }, + { code: 'IT', name: 'Italy', flag: '🇮🇹' }, + { code: 'JP', name: 'Japan', flag: '🇯🇵' }, + { code: 'IN', name: 'India', flag: '🇮🇳' }, + { code: 'BR', name: 'Brazil', flag: '🇧🇷' }, + { code: 'MX', name: 'Mexico', flag: '🇲🇽' }, + { code: 'KR', name: 'South Korea', flag: '🇰🇷' }, + { code: 'CN', name: 'China', flag: '🇨🇳' }, +]; + +export const getCountryName = (code: string): string => { + return COUNTRIES.find(c => c.code === code)?.name || code; +}; + +export const getCountryFlag = (code: string): string => { + return COUNTRIES.find(c => c.code === code)?.flag || '🌍'; +}; + +export const getCategoryIcon = (category: string): string => { + switch (category) { + case 'primary': return '📗'; + case 'secondary': return '📘'; + case 'unreliable': return '🚫'; + default: return '📄'; + } +}; + +export const getCategoryColor = (category: string): string => { + switch (category) { + case 'primary': return 'bg-green-100 text-green-800 border-green-300'; + case 'secondary': return 'bg-blue-100 text-blue-800 border-blue-300'; + case 'unreliable': return 'bg-red-100 text-red-800 border-red-300'; + default: return 'bg-gray-100 text-gray-800 border-gray-300'; + } +}; + +export const getReliabilityColor = (reliability?: string): string => { + switch (reliability) { + case 'credible': return 'bg-green-100 text-green-800 border-green-300'; + case 'unreliable': return 'bg-red-100 text-red-800 border-red-300'; + default: return 'bg-gray-100 text-gray-800 border-gray-300'; + } +}; + +export const getStatusColor = (status: string): string => { + switch (status) { + case 'verified': return 'bg-green-100 text-green-800 border-green-300'; + case 'rejected': return 'bg-red-100 text-red-800 border-red-300'; + case 'pending': return 'bg-yellow-100 text-yellow-800 border-yellow-300'; + default: return 'bg-gray-100 text-gray-800 border-gray-300'; + } +}; \ No newline at end of file diff --git a/frontend/src/lib/mock-data.ts b/frontend/src/lib/mock-data.ts deleted file mode 100644 index afb42b7..0000000 --- a/frontend/src/lib/mock-data.ts +++ /dev/null @@ -1,404 +0,0 @@ -// Mock data and utilities for WikiSourceVerifier - -export interface User { - id: string; - username: string; - email: string; - country: string; - role: 'admin' | 'verifier' | 'contributor'; - points: number; - badges: string[]; - joinDate: string; -} - -export interface Submission { - id: string; - url: string; - title: string; - publisher: string; - country: string; - category: 'primary' | 'secondary' | 'unreliable'; - status: 'pending' | 'verified' | 'rejected'; - submitterId: string; - submitterName: string; - wikipediaArticle?: string; - fileName?: string; - mediaType: 'url' | 'pdf'; - submittedDate: string; - verifiedDate?: string; - verifierId?: string; - verifierNotes?: string; - reliability?: 'credible' | 'unreliable'; -} - -export interface Country { - code: string; - name: string; - flag: string; -} - - - -export const COUNTRIES: Country[] = [ - // African Countries (Primary Focus) - { code: 'GH', name: 'Ghana', flag: '🇬🇭' }, - { code: 'NG', name: 'Nigeria', flag: '🇳🇬' }, - { code: 'KE', name: 'Kenya', flag: '🇰🇪' }, - { code: 'ZA', name: 'South Africa', flag: '🇿🇦' }, - { code: 'EG', name: 'Egypt', flag: '🇪🇬' }, - { code: 'ET', name: 'Ethiopia', flag: '🇪🇹' }, - { code: 'MA', name: 'Morocco', flag: '🇲🇦' }, - { code: 'TN', name: 'Tunisia', flag: '🇹🇳' }, - { code: 'UG', name: 'Uganda', flag: '🇺🇬' }, - { code: 'TZ', name: 'Tanzania', flag: '🇹🇿' }, - { code: 'RW', name: 'Rwanda', flag: '🇷🇼' }, - { code: 'MZ', name: 'Mozambique', flag: '🇲🇿' }, - { code: 'MG', name: 'Madagascar', flag: '🇲🇬' }, - - // Other Countries - { code: 'US', name: 'United States', flag: '🇺🇸' }, - { code: 'GB', name: 'United Kingdom', flag: '🇬🇧' }, - { code: 'CA', name: 'Canada', flag: '🇨🇦' }, - { code: 'AU', name: 'Australia', flag: '🇦🇺' }, - { code: 'DE', name: 'Germany', flag: '🇩🇪' }, - { code: 'FR', name: 'France', flag: '🇫🇷' }, - { code: 'ES', name: 'Spain', flag: '🇪🇸' }, - { code: 'IT', name: 'Italy', flag: '🇮🇹' }, - { code: 'JP', name: 'Japan', flag: '🇯🇵' }, - { code: 'IN', name: 'India', flag: '🇮🇳' }, - { code: 'BR', name: 'Brazil', flag: '🇧🇷' }, - { code: 'MX', name: 'Mexico', flag: '🇲🇽' }, - { code: 'KR', name: 'South Korea', flag: '🇰🇷' }, - { code: 'CN', name: 'China', flag: '🇨🇳' }, -]; - -export const BADGES = [ - { id: 'first-submission', name: 'First Submission', icon: '🌟', description: 'Submitted your first reference' }, - { id: '10-verified', name: '10 Verified Sources', icon: '✅', description: 'Had 10 sources verified' }, - { id: 'country-expert', name: 'Country Expert', icon: '🏆', description: 'Top contributor in a country' }, - { id: 'early-adopter', name: 'Early Adopter', icon: '🚀', description: 'One of the first users' }, - { id: 'super-verifier', name: 'Super Verifier', icon: '⭐', description: 'Verified 50+ sources' }, - { id: 'quality-contributor', name: 'Quality Contributor', icon: '💎', description: '90% verification success rate' }, -]; - -export const mockUsers: User[] = [ - { - id: '1', - username: 'WikiEditor2024', - email: 'editor@example.com', - country: 'US', - role: 'contributor', - points: 150, - badges: ['first-submission', '10-verified', 'early-adopter'], - joinDate: '2024-01-15', - }, - { - id: '2', - username: 'SourceVerifier', - email: 'verifier@example.com', - country: 'GB', - role: 'verifier', - points: 450, - badges: ['super-verifier', 'country-expert'], - joinDate: '2024-01-10', - }, - { - id: '3', - username: 'AdminUser', - email: 'admin@example.com', - country: 'CA', - role: 'admin', - points: 1000, - badges: ['early-adopter', 'super-verifier', 'country-expert'], - joinDate: '2024-01-01', - }, -]; - - -export const mockSubmissions: Submission[] = [ - // African Country Submissions - { - id: '7', - url: 'https://www.graphic.com.gh/news/ghana/agricultural-policy-reform-2024.html', - title: 'Ghana Agricultural Policy Reform 2024', - publisher: 'The Graphic', - country: 'GH', - category: 'secondary', - status: 'verified', - submitterId: '1', - submitterName: 'WikiEditor2024', - wikipediaArticle: 'https://en.wikipedia.org/wiki/Agriculture_in_Ghana', - mediaType: 'url', - submittedDate: '2024-10-20', - verifiedDate: '2024-10-21', - verifierId: '2', - reliability: 'credible', - verifierNotes: 'Established Ghanaian newspaper, government policy documentation', - }, - { - id: '8', - url: 'https://www.nature.com/articles/africa-climate-research-2024', - title: 'Climate Change Impact on West Africa', - publisher: 'Nature Climate Change', - country: 'NG', - category: 'primary', - status: 'verified', - submitterId: '1', - submitterName: 'WikiEditor2024', - wikipediaArticle: 'https://en.wikipedia.org/wiki/Climate_change_in_Africa', - mediaType: 'url', - submittedDate: '2024-10-18', - verifiedDate: '2024-10-19', - verifierId: '2', - reliability: 'credible', - }, - { - id: '9', - url: 'https://www.nation.co.ke/news/education/education-reform-kenya-2024/', - title: 'Kenya Education Reform Initiative 2024', - publisher: 'Daily Nation', - country: 'KE', - category: 'secondary', - status: 'pending', - submitterId: '1', - submitterName: 'WikiEditor2024', - wikipediaArticle: 'https://en.wikipedia.org/wiki/Education_in_Kenya', - mediaType: 'url', - submittedDate: '2024-10-22', - }, - { - id: '10', - url: 'https://www.timeslive.co.za/news/south-africa/healthcare-study-2024/', - title: 'South Africa Healthcare System Analysis', - publisher: 'Times Live', - country: 'ZA', - category: 'secondary', - status: 'verified', - submitterId: '1', - submitterName: 'WikiEditor2024', - wikipediaArticle: 'https://en.wikipedia.org/wiki/Healthcare_in_South_Africa', - mediaType: 'url', - submittedDate: '2024-10-15', - verifiedDate: '2024-10-16', - verifierId: '2', - reliability: 'credible', - }, - { - id: '11', - url: 'https://academic.oup.com/afraf/article/123/1/123/2024/egyptian-economy', - title: 'Egyptian Economic Development Study 2024', - publisher: 'African Affairs Journal', - country: 'EG', - category: 'primary', - status: 'verified', - submitterId: '1', - submitterName: 'WikiEditor2024', - wikipediaArticle: 'https://en.wikipedia.org/wiki/Economy_of_Egypt', - mediaType: 'url', - submittedDate: '2024-10-10', - verifiedDate: '2024-10-11', - verifierId: '2', - reliability: 'credible', - }, - { - id: '12', - url: 'https://ethiopia.gov.et/documents/development-report-2024.pdf', - title: 'Ethiopia Development Report 2024', - publisher: 'Federal Democratic Republic of Ethiopia', - country: 'ET', - category: 'primary', - status: 'pending', - submitterId: '1', - submitterName: 'WikiEditor2024', - fileName: 'ethiopia-development-report-2024.pdf', - mediaType: 'pdf', - submittedDate: '2024-10-25', - }, - - // Original Submissions - { - id: '1', - url: 'https://www.nature.com/articles/climate-change-2024', - title: 'Climate Change Impact Study 2024', - publisher: 'Nature Publishing Group', - country: 'GB', - category: 'primary', - status: 'verified', - submitterId: '1', - submitterName: 'WikiEditor2024', - wikipediaArticle: 'https://en.wikipedia.org/wiki/Climate_change', - mediaType: 'url', - submittedDate: '2024-10-20', - verifiedDate: '2024-10-21', - verifierId: '2', - reliability: 'credible', - verifierNotes: 'Peer-reviewed journal, excellent source', - }, - { - id: '2', - url: 'https://arxiv.org/abs/2024.12345', - title: 'Quantum Computing Advances', - publisher: 'arXiv', - country: 'US', - category: 'primary', - status: 'pending', - submitterId: '1', - submitterName: 'WikiEditor2024', - mediaType: 'url', - submittedDate: '2024-10-25', - }, - { - id: '3', - url: 'https://www.bbc.com/news/world-europe-12345678', - title: 'European Union Policy Update', - publisher: 'BBC News', - country: 'GB', - category: 'secondary', - status: 'verified', - submitterId: '1', - submitterName: 'WikiEditor2024', - wikipediaArticle: 'https://en.wikipedia.org/wiki/European_Union', - mediaType: 'url', - submittedDate: '2024-10-18', - verifiedDate: '2024-10-19', - verifierId: '2', - reliability: 'credible', - }, - { - id: '4', - url: 'https://example-blog.com/conspiracy-theory', - title: 'Unverified Claims Article', - publisher: 'Random Blog', - country: 'US', - category: 'unreliable', - status: 'verified', - submitterId: '1', - submitterName: 'WikiEditor2024', - mediaType: 'url', - submittedDate: '2024-10-15', - verifiedDate: '2024-10-16', - verifierId: '2', - reliability: 'unreliable', - verifierNotes: 'No editorial oversight, unverified claims', - }, - { - id: '5', - url: 'https://history.gov/documents/historical-analysis.pdf', - title: 'Historical Analysis of WWII', - publisher: 'National Archives', - country: 'US', - category: 'primary', - status: 'pending', - submitterId: '1', - submitterName: 'WikiEditor2024', - fileName: 'historical-analysis.pdf', - mediaType: 'pdf', - submittedDate: '2024-10-26', - }, - { - id: '6', - url: 'https://www.sciencedirect.com/article/medical-research', - title: 'Medical Research Findings', - publisher: 'Elsevier', - country: 'DE', - category: 'primary', - status: 'verified', - submitterId: '1', - submitterName: 'WikiEditor2024', - wikipediaArticle: 'https://en.wikipedia.org/wiki/Medical_research', - mediaType: 'url', - submittedDate: '2024-10-22', - verifiedDate: '2024-10-23', - verifierId: '2', - reliability: 'credible', - }, -]; - -export const leaderboardData = [ - { username: 'AdminUser', country: 'CA', points: 1000, verified: 85 }, - { username: 'SourceVerifier', country: 'GB', points: 450, verified: 52 }, - { username: 'WikiEditor2024', country: 'US', points: 150, verified: 12 }, - { username: 'FactChecker', country: 'AU', points: 320, verified: 38 }, - { username: 'AcademicSource', country: 'DE', points: 280, verified: 29 }, -]; - -// Local storage keys -export const STORAGE_KEYS = { - USER: 'wikisource_user', - SUBMISSIONS: 'wikisource_submissions', -}; - -// Utility functions -export const getCountryName = (code: string): string => { - return COUNTRIES.find(c => c.code === code)?.name || code; -}; - -export const getCountryFlag = (code: string): string => { - return COUNTRIES.find(c => c.code === code)?.flag || '🌍'; -}; - -export const getCategoryIcon = (category: string): string => { - switch (category) { - case 'primary': return '📗'; - case 'secondary': return '📘'; - case 'unreliable': return '🚫'; - default: return '📄'; - } -}; - -export const getCategoryColor = (category: string): string => { - switch (category) { - case 'primary': return 'bg-green-100 text-green-800 border-green-300'; - case 'secondary': return 'bg-blue-100 text-blue-800 border-blue-300'; - case 'unreliable': return 'bg-red-100 text-red-800 border-red-300'; - default: return 'bg-gray-100 text-gray-800 border-gray-300'; - } -}; - -export const getReliabilityColor = (reliability?: string): string => { - switch (reliability) { - case 'credible': return 'bg-green-100 text-green-800 border-green-300'; - case 'unreliable': return 'bg-red-100 text-red-800 border-red-300'; - default: return 'bg-gray-100 text-gray-800 border-gray-300'; - } -}; - -export const getStatusColor = (status: string): string => { - switch (status) { - case 'verified': return 'bg-green-100 text-green-800 border-green-300'; - case 'rejected': return 'bg-red-100 text-red-800 border-red-300'; - case 'pending': return 'bg-yellow-100 text-yellow-800 border-yellow-300'; - default: return 'bg-gray-100 text-gray-800 border-gray-300'; - } -}; - -// Initialize data from localStorage or use mock data -export const initializeData = () => { - const storedSubmissions = localStorage.getItem(STORAGE_KEYS.SUBMISSIONS); - if (!storedSubmissions) { - localStorage.setItem(STORAGE_KEYS.SUBMISSIONS, JSON.stringify(mockSubmissions)); - } -}; - -// API simulation functions -export const saveSubmissions = (submissions: Submission[]) => { - localStorage.setItem(STORAGE_KEYS.SUBMISSIONS, JSON.stringify(submissions)); -}; - -export const getSubmissions = (): Submission[] => { - const stored = localStorage.getItem(STORAGE_KEYS.SUBMISSIONS); - return stored ? JSON.parse(stored) : mockSubmissions; -}; - -export const saveUser = (user: User | null) => { - if (user) { - localStorage.setItem(STORAGE_KEYS.USER, JSON.stringify(user)); - } else { - localStorage.removeItem(STORAGE_KEYS.USER); - } -}; - -export const getUser = (): User | null => { - const stored = localStorage.getItem(STORAGE_KEYS.USER); - return stored ? JSON.parse(stored) : null; -}; diff --git a/frontend/src/pages/AdminDashboard.tsx b/frontend/src/pages/AdminDashboard.tsx index 658918b..d0937dd 100644 --- a/frontend/src/pages/AdminDashboard.tsx +++ b/frontend/src/pages/AdminDashboard.tsx @@ -27,7 +27,7 @@ import { getCountryFlag, getCountryName, getStatusColor, -} from '../lib/mock-data'; +} from '../lib/format-utils'; import { submissionApi } from '../lib/api'; import { toast } from 'sonner'; diff --git a/frontend/src/pages/AuthPage.tsx b/frontend/src/pages/AuthPage.tsx index e1f3a8d..28e9c84 100644 --- a/frontend/src/pages/AuthPage.tsx +++ b/frontend/src/pages/AuthPage.tsx @@ -7,7 +7,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../co import { Tabs, TabsContent, TabsList, TabsTrigger } from '../components/ui/tabs'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../components/ui/select'; import { useAuth } from '../lib/auth-context'; -import { COUNTRIES } from '../lib/mock-data'; +import { COUNTRIES } from '../lib/format-utils'; import { toast } from 'sonner'; import { Loader2 } from 'lucide-react'; diff --git a/frontend/src/pages/CountryPage.tsx b/frontend/src/pages/CountryPage.tsx index 3e94a53..1d0e209 100644 --- a/frontend/src/pages/CountryPage.tsx +++ b/frontend/src/pages/CountryPage.tsx @@ -5,7 +5,8 @@ import { Button } from '../components/ui/button'; import { Badge } from '../components/ui/badge'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../components/ui/card'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '../components/ui/tabs'; -import { COUNTRIES, getCountryName, getCountryFlag, getSubmissions, getCategoryIcon, getReliabilityColor, getStatusColor } from '../lib/mock-data'; +import { COUNTRIES, getCountryName, getCountryFlag, getCategoryIcon, getReliabilityColor, getStatusColor } from '../lib/format-utils'; +import { toast } from 'sonner'; import { fetchWikidataCountryMetadata, WikidataCountryMetadata } from '../lib/wikidata-service'; import { submissionApi } from '../lib/api'; @@ -30,25 +31,20 @@ export const CountryPage: React.FC = () => { setMetadataLoading(true); try { - // Try to fetch from backend API first, fallback to local storage + // Fetch from backend API directly try { const response = await submissionApi.getAll({ country: countryCode }); - if (response.submissions) { + if (response && response.submissions) { setCountrySubmissions(response.submissions); } else { - // Fallback to local storage - const allSubmissions = getSubmissions(); - const filtered = allSubmissions.filter(sub => sub.country === countryCode); - setCountrySubmissions(filtered); + setCountrySubmissions([]); } } catch (apiError) { - console.log('API not available, using local data'); - const allSubmissions = getSubmissions(); - const filtered = allSubmissions.filter(sub => sub.country === countryCode); - setCountrySubmissions(filtered); + console.error('API not available or failed:', apiError); + setCountrySubmissions([]); // Safe empty fallback array } - - // Fetch Wikidata metadata + + // Fetch Wikidata metadata (Kept intact!) const metadata = await fetchWikidataCountryMetadata(countryCode, countryName); setCountryMetadata(metadata); } catch (error) { diff --git a/frontend/src/pages/PublicDirectory.tsx b/frontend/src/pages/PublicDirectory.tsx index 08c4121..ec7d2d3 100644 --- a/frontend/src/pages/PublicDirectory.tsx +++ b/frontend/src/pages/PublicDirectory.tsx @@ -31,7 +31,7 @@ import { getCountryFlag, getCountryName, getReliabilityColor, -} from "../lib/mock-data"; +} from "../lib/format-utils"; import { submissionApi } from "../lib/api"; import { toast } from "sonner"; import { diff --git a/frontend/src/pages/SubmissionForm.tsx b/frontend/src/pages/SubmissionForm.tsx index 216ac36..fa33215 100644 --- a/frontend/src/pages/SubmissionForm.tsx +++ b/frontend/src/pages/SubmissionForm.tsx @@ -8,7 +8,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../co import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../components/ui/select'; import { RadioGroup, RadioGroupItem } from '../components/ui/radio-group'; import { useAuth } from '../lib/auth-context'; -import { COUNTRIES } from '../lib/mock-data'; +import { COUNTRIES } from '../lib/format-utils'; import { submissionApi } from '../lib/api'; import { toast } from 'sonner'; import { Upload, Link2, FileText, CheckCircle, AlertCircle } from 'lucide-react';