OpenLake/canonforces
在 GitHub 查看Refactor questions/[id].tsx - 527-line monolith combining 8 responsibilities
Open
#164 创建于 2026年4月5日
enhancementhelp wanted
仓库指标
- Star
- (10 star)
- PR 合并指标
- (PR 指标待抓取)
描述
Issue
src/pages/questions/[id].tsx is 527 lines of JSX + TypeScript combining:
- Data fetching (Firestore getDoc for problem)
- Code execution (API call to execute code)
- Codeforces submission verification
- AI Hint generation and display
- Comment section
- Streak tracking
- State management for 15+ useState hooks
Problems
- Hard to test - This component cannot be unit tested in isolation
- Performance - Every state change re-renders the entire page
- Maintainability - Adding a new feature (like hints) required touching 400+ lines of existing code
Suggestion
Extract into composable hooks and components:
useProblem(questionId)- Fetches and caches problem datauseCodeExecution(language, code, testCases)- handles run/submituseAiHints(questionId)- handles hint fetching and coin deduction<ProblemDescription>- Left panel with problem text<CodeEditor>- IDE-like component<SubmissionHistory>- Past submissions list<CommentsSection>- Threaded discussion