-
Notifications
You must be signed in to change notification settings - Fork 65
Frontend Infrastructure Cleanup — Fix Layout Bugs, Add Env Config, and Migrate Admin Hooks to TanStack Query #213
Description
Labels
Frontend
Description
ByteChain Academy's frontend has several accumulated infrastructure problems that collectively degrade the developer experience and user experience. There is a duplicate <Toaster> component rendering in layout.tsx causing double toast notifications, the frontend has no .env.example file leaving contributors confused about required environment variables, the admin data-fetching hooks use raw useState/useEffect instead of TanStack Query (which is specified in the project architecture), and all lesson video URLs in the codebase still point to a Rick Roll placeholder. This issue cleans all of this up and modernises the data-fetching layer.
Background & Context
frontend/app/layout.tsxrenders<Toaster>twice — once inside the provider tree and once after it — causing every notification to appear twice- There is no
frontend/.env.examplefile —NEXT_PUBLIC_API_URLis referenced inlib/api.tsbut undocumented frontend/hooks/use-admin-lessons.tsuses rawuseState+useEffect+ manualsetLoading/setError— the project spec requires TanStack Queryfrontend/hooks/use-lesson-quiz.tshas the same pattern- The project architecture document specifies TanStack Query for all client-side data fetching
@tanstack/react-querymay not be installed — checkpackage.jsonand install if missing
Requirements
- Remove the duplicate
<Toaster>fromfrontend/app/layout.tsx— keep only one instance - Create
frontend/.env.examplewithNEXT_PUBLIC_API_URL=http://localhost:3001and a comment explaining its purpose - Install
@tanstack/react-queryand@tanstack/react-query-devtoolsif not already present - Set up a
QueryClientProviderinlayout.tsxwrapping the app - Rewrite
use-admin-lessons.tsusinguseQueryfor fetching anduseMutationfor create/update/delete operations - Rewrite
use-lesson-quiz.tsusinguseQueryfor fetching quiz data anduseMutationfor create/update quiz operations - Update
frontend/app/admin/courses/[courseId]/lessons/page.tsxto use the new hook signatures if they change - Replace all hardcoded Rick Roll video URLs (
https://www.youtube.com/embed/dQw4w9WgXcQ) with an empty string or a proper placeholder constant
Suggested Execution
Branch: git checkout -b feat/frontend-infrastructure-cleanup
Files to touch:
frontend/app/layout.tsxfrontend/.env.example← create thisfrontend/package.jsonfrontend/hooks/use-admin-lessons.tsfrontend/hooks/use-lesson-quiz.tsfrontend/contexts/learning-context.tsx(video URL placeholder)frontend/app/admin/courses/[courseId]/lessons/page.tsx
Implement:
- Remove duplicate
<Toaster>— keep only the one inside the provider tree - Create
.env.examplewith documented env vars npm install @tanstack/react-query @tanstack/react-query-devtools- Add
<QueryClientProvider client={queryClient}>inlayout.tsx - Rewrite
useAdminLessonswithuseQuery({ queryKey: ['lessons', courseId], queryFn: ... }) - Add
useMutationfor delete lesson withonSuccess: () => queryClient.invalidateQueries(['lessons', courseId]) - Rewrite
useLessonQuizwithuseQueryanduseMutationfor create/update - Define
const PLACEHOLDER_VIDEO_URL = ''in a constants file and replace all Rick Roll references
Test & Validate:
- Trigger any action that fires a toast — verify it appears exactly once
- Check
frontend/.env.exampledocumentsNEXT_PUBLIC_API_URL - Admin lessons page loads correctly using the refactored TanStack Query hooks
- Creating, editing, or deleting a lesson correctly invalidates and refetches the lesson list
- No Rick Roll URLs remain anywhere in the codebase (
grep -r "dQw4w9WgXcQ" frontend/returns empty)
Acceptance Criteria
- Only one
<Toaster>exists inlayout.tsx -
frontend/.env.exampleexists withNEXT_PUBLIC_API_URLdocumented -
@tanstack/react-queryis installed andQueryClientProviderwraps the app -
use-admin-lessons.tsusesuseQueryanduseMutation -
use-lesson-quiz.tsusesuseQueryanduseMutation - Cache invalidation works correctly after mutations
- No Rick Roll placeholder URLs remain in the codebase
Example Commit Message
feat: fix duplicate toaster, add env.example, migrate admin hooks to TanStack Query, remove placeholder video URLs
Guidelines
- Assignment required before starting
- PR description must include
Closes #[issue_id] - Join our Telegram: https://t.me/ByteChainAcademy
- Complexity: High (200 pts)