Skip to content

Conversation

@devin-ai-integration
Copy link

Phase 2: Implement React hooks, context, and routing for Angular to React migration

Summary

This PR implements Phase 2 of the Angular to React migration by creating parallel React infrastructure without modifying the existing Angular application. The React code is isolated in src/react/ and uses a separate Vite build system.

Key Changes:

  • useHackerNewsAPI hook (src/react/hooks/useHackerNewsAPI.ts): Migrated from Angular's RxJS-based HackerNewsAPIService to native fetch with async/await. Includes fetchFeed, fetchItemContent (with concurrent poll fetching via Promise.all), and fetchUser methods.
  • SettingsContext + useSettings hook (src/react/contexts/SettingsContext.tsx): Migrated from Angular's SettingsService with localStorage persistence for theme, font size, and list spacing. Includes system dark mode detection via matchMedia listener with proper cleanup.
  • React Router setup (src/react/App.tsx): Configured all 7 routes matching Angular (news, newest, show, ask, jobs, item, user) with lazy loading for item and user pages using React.lazy() and Suspense.
  • Placeholder page components: Created FeedPage, ItemDetailsPage, and UserPage with basic routing verification (actual implementation is Phase 3).
  • Vite build system: Configured for React development on port 3000 (separate from Angular).

Dependencies Added:

  • React 19.2.0, React-DOM 19.2.0, React-Router-DOM 7.9.4
  • Vite 7.1.12, @vitejs/plugin-react 5.1.0

The React build (npm run react:build) completes successfully with no TypeScript errors. The dev server (npm run react:dev) starts and serves the app at http://localhost:3000.

Review & Testing Checklist for Human

⚠️ Important: This PR has NOT been comprehensively tested. The implementation compiles and basic routing works, but critical functionality remains unverified.

High Priority - Must Test:

  • Test API hook with real API calls: The useHackerNewsAPI hook has not been tested with actual API requests. Create a test component that calls fetchFeed, fetchItemContent, and fetchUser to verify the API integration works correctly and error handling is robust.
  • Test Settings Context functionality: Verify localStorage persistence, theme switching (default/night/AMOLED black), font size changes, list spacing changes, and system dark mode detection by:
    • Changing settings in a test UI
    • Refreshing the page to verify persistence
    • Changing OS dark mode preference to test matchMedia listener
  • Verify all 7 routes: Only /news/1 and /item/12345 were tested. Manually navigate to all routes (/newest/:page, /show/:page, /ask/:page, /jobs/:page, /user/:id) to ensure routing works correctly.
  • Resolve package manager conflict: The project uses Yarn (yarn.lock exists) but this PR used npm, creating a package-lock.json. Decide on one package manager and remove the other lockfile to avoid dependency resolution issues.

Medium Priority - Should Verify:

  • Check lazy loading: Open browser DevTools Network tab and verify that ItemDetailsPage and UserPage are loaded as separate chunks only when navigating to those routes.
  • Verify no console errors: Check browser console for any runtime errors, warnings, or React warnings.
  • Test concurrent poll fetching: The fetchItemContent method uses Promise.all to fetch poll options concurrently. Test with a poll item (if available in the API) to verify it works correctly.

Notes

  • No Angular code was modified - all changes are additive in src/react/ directory
  • Both apps can run simultaneously - Angular on default port, React on port 3000
  • Phase 3 TODO: Implement actual page components with data fetching and UI rendering
  • CI may need updates: The CI pipeline might not know about the React build yet. Consider adding npm run react:build to CI checks.

Link to Devin run: https://app.devin.ai/sessions/0b996b4ba2d046b29651d5302f56efeb
Requested by: @eashansinha

Screenshots:
React app running - News feed
React app running - Item details

- Created useHackerNewsAPI hook with fetch-based API calls
  - Migrated fetchFeed, fetchItemContent, fetchUser from Angular service
  - Converted nested RxJS subscriptions to Promise.all for poll handling
- Created SettingsContext with localStorage persistence and dark mode detection
  - Implemented useSettings hook for consuming context
  - Preserved all theme variants: default, night, AMOLED black
  - Maintains same localStorage keys as Angular for compatibility
- Set up React Router with lazy loading matching Angular routes
  - Regular routes: /news, /newest, /show, /ask, /jobs (all use FeedPage)
  - Lazy-loaded routes: /item/:id (ItemDetailsPage), /user/:id (UserPage)
  - Default redirect from / to /news/1
- Created placeholder page components for Phase 3 implementation
- Configured Vite build system for React development
- Added React scripts to package.json: react:dev, react:build, react:preview
- Installed React dependencies: react, react-dom, react-router-dom, vite

All TypeScript types defined based on Angular models.
React code isolated in src/react/ directory.
Both Angular and React apps can run simultaneously.

Co-Authored-By: Eashan Sinha <[email protected]>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

1 participant