T431219 Refactor frontend to use live API for country data - #50
Open
pushpaktiwarii wants to merge 2 commits into
Open
T431219 Refactor frontend to use live API for country data#50pushpaktiwarii wants to merge 2 commits into
pushpaktiwarii wants to merge 2 commits into
Conversation
|
@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. |
There was a problem hiding this comment.
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/CountriesProviderto fetch and provide countries globally, plus helper lookups for name/flag. - Refactors multiple pages/components to replace
COUNTRIES/legacy helpers withuseCountries(). - Adds a
countryApiclient, 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 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); |
| useEffect(() => { | ||
| const fetchCountries = async () => { | ||
| try { | ||
| const response = await countryApi.getAll({ limit: 200 }); |
| }; | ||
| return country ? flags[country] ?? '🌍' : '🌍'; | ||
| }; | ||
| import { useCountries } from '../lib/CountriesContext'; |
| @@ -1,10 +1,45 @@ | |||
| # WikiSource Verifier API Documentation | |||
| # WikiSource Verifier API Documentation | |||
pushpaktiwarii
force-pushed
the
T431219-api-countries
branch
2 times, most recently
from
July 10, 2026 20:51
1061361 to
d5f52ce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Task
Fixes T431219
Overview
This PR replaces the hardcoded
COUNTRIESmock data with live data fetched from theGET /api/countriesbackend endpoint, ensuring the frontend and backend are perfectly synced.Changes Made
COUNTRIESarray and legacygetCountryFlag/getCountryNamefunctions frommock-data.ts.CountriesContextanduseCountrieshook to fetch and provide country data globally.SubmissionForm,PublicDirectory,CountryPage,AuthPage,AdminDashboard,UserProfile, andCountryNavigationto consume dynamic API data.Verification
npm run buildsucceeds with zero errors.