Skip to content

T431219 Refactor frontend to use live API for country data - #50

Open
pushpaktiwarii wants to merge 2 commits into
Tiisu:mainfrom
pushpaktiwarii:T431219-api-countries
Open

T431219 Refactor frontend to use live API for country data#50
pushpaktiwarii wants to merge 2 commits into
Tiisu:mainfrom
pushpaktiwarii:T431219-api-countries

Conversation

@pushpaktiwarii

Copy link
Copy Markdown
Contributor

Related Task

Fixes T431219

Overview

This PR replaces the hardcoded COUNTRIES mock data with live data fetched from the GET /api/countries backend endpoint, ensuring the frontend and backend are perfectly synced.

Changes Made

  • Removed Hardcoded Data: Deleted the static COUNTRIES array and legacy getCountryFlag/getCountryName functions from mock-data.ts.
  • Added React Context: Created CountriesContext and useCountries hook to fetch and provide country data globally.
  • Component Refactoring: Refactored SubmissionForm, PublicDirectory, CountryPage, AuthPage, AdminDashboard, UserProfile, and CountryNavigation to consume dynamic API data.
  • Fallback & Stability: Implemented a fallback array so the UI won't crash if the API is momentarily down, and automated flag generation using standard ISO codes.

Verification

  • npm run build succeeds with zero errors.
  • Global search confirms no remaining hardcoded country array imports.
  • Dropdowns and UI components render correctly with dynamic data.

Copilot AI review requested due to automatic review settings July 10, 2026 20:34
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

@pushpaktiwarii is attempting to deploy a commit to the Tiisu's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the frontend to remove the hardcoded country list and instead fetch country data from the backend via a new React context, so UI country names/flags stay in sync with server data. It also adds supporting API client code, wires the provider into the app root, and updates documentation/CI to match the expanded API/test needs.

Changes:

  • Introduces CountriesContext/CountriesProvider to fetch and provide countries globally, plus helper lookups for name/flag.
  • Refactors multiple pages/components to replace COUNTRIES/legacy helpers with useCountries().
  • Adds a countryApi client, updates backend test setup, expands API docs, and adds a GitHub Actions CI workflow.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
frontend/src/pages/UserProfile.tsx Switches to useCountries() for flag rendering; removes local flag helper.
frontend/src/pages/SubmissionForm.tsx Replaces COUNTRIES dropdown with context-provided countries.
frontend/src/pages/PublicDirectory.tsx Uses useCountries() for country dropdown and name/flag helpers.
frontend/src/pages/CountryPage.tsx Replaces static COUNTRIES lookup with context-based lookup.
frontend/src/pages/AuthPage.tsx Replaces COUNTRIES registration dropdown with context-provided countries.
frontend/src/pages/AdminDashboard.tsx Uses context-based country name/flag helpers.
frontend/src/lib/mock-data.ts Removes the hardcoded COUNTRIES list and country helper functions.
frontend/src/lib/CountriesContext.tsx Adds new provider/hook to fetch countries and expose lookup helpers with a fallback list.
frontend/src/lib/api.ts Adds countryApi.getAll() for fetching country data.
frontend/src/components/UserProfile.tsx Uses context-based country name/flag helpers.
frontend/src/components/SubmissionForm.tsx Replaces COUNTRIES dropdown with context-provided countries.
frontend/src/components/PublicDirectory.tsx Uses useCountries() for filtering dropdown and display helpers.
frontend/src/components/CountryNavigation.tsx Switches nav country sources to context-provided countries.
frontend/src/components/AuthPage.tsx Replaces COUNTRIES registration dropdown with context-provided countries.
frontend/src/components/AdminDashboard.tsx Uses context-based country name/flag helpers.
frontend/src/App.tsx Wraps app with CountriesProvider so useCountries() is available globally.
backend/tests/utils/testApp.js Removes unused Wikimedia OAuth route wiring from the test app.
backend/tests/setup.js Sets test-only JWT secrets to stabilize auth-dependent tests.
backend/API_DOCUMENTATION.md Expands/updates API documentation (plus formatting/encoding changes).
backend/.env.example Minor formatting fix.
.github/workflows/ci.yml Adds CI workflow to run backend tests and build the frontend on PRs/pushes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/pages/CountryPage.tsx Outdated
Comment on lines +22 to +25
const { countries, getCountryName, getCountryFlag } = useCountries();
const country = countries.find(c => c.code === countryCode);
const countryName = country ? country.name : (countryCode ? getCountryName(countryCode) : 'Unknown Country');
const countryFlag = country ? country.flag : (countryCode ? getCountryFlag(countryCode) : '🌍');
Comment on lines +21 to +23
// Get African countries (first 12 countries in the list)
const africanCountries = COUNTRIES.slice(0, 12);
const otherCountries = COUNTRIES.slice(12);
const africanCountries = countries.slice(0, 12);
const otherCountries = countries.slice(12);
Comment on lines +63 to +66
export const CountriesProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const [countries, setCountries] = useState<Country[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
Comment thread frontend/src/lib/CountriesContext.tsx Outdated
useEffect(() => {
const fetchCountries = async () => {
try {
const response = await countryApi.getAll({ limit: 200 });
Comment thread frontend/src/pages/UserProfile.tsx Outdated
};
return country ? flags[country] ?? '🌍' : '🌍';
};
import { useCountries } from '../lib/CountriesContext';
Comment thread backend/API_DOCUMENTATION.md Outdated
@@ -1,10 +1,45 @@
# WikiSource Verifier API Documentation
# WikiSource Verifier API Documentation
@pushpaktiwarii
pushpaktiwarii force-pushed the T431219-api-countries branch 2 times, most recently from 1061361 to d5f52ce Compare July 10, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants