Skip to content

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Dec 5, 2025

Phase 2: Data Layer Migration - React hooks for API and Settings Context

Summary

This PR adds React equivalents of the Angular HackerNewsAPIService and SettingsService as part of the migration to React.

New files:

  • src/hooks/api.ts - React Query hooks (useFetchFeed, useFetchItem, useFetchUser) that replace the Angular HackerNewsAPIService. Implements request cancellation via React Query's abort signal.
  • src/contexts/SettingsContext.tsx - React Context with SettingsProvider and useSettings hook that replaces the Angular SettingsService. Includes theme detection, localStorage persistence, and system color scheme preference handling.

Review & Testing Checklist for Human

  • Verify TypeScript interfaces match actual API responses - The interfaces (Story, User, Comment, PollResult) were derived from Angular models but not validated against the live API at https://node-hnapi.herokuapp.com
  • Review poll handling logic in useFetchItem - The original Angular code fetches poll options via sequential RxJS subscriptions; the React version uses Promise.all which waits for all options before returning. Verify this behavior change is acceptable.
  • Verify theme initialization matches original behavior - The Angular service dispatches a synthetic MediaQueryListEvent; the React version directly checks darkColorSchemeMedia.matches
  • Test with React Query setup - These hooks require @tanstack/react-query which isn't installed yet. Will need to test when React app infrastructure is in place.

Recommended test plan: Once React infrastructure is set up, create a simple test component that uses each hook and verify data fetching works correctly, especially for poll-type stories.

Notes

  • The Angular linter shows pre-existing errors unrelated to these changes
  • React Query dependency will need to be added when the React app is configured

Link to Devin run: https://app.devin.ai/sessions/3c769e7889e0455696358bc5bf6a2a06
Requested by: Cindy Huang (cindy.huang@cognition.ai) / @cindyyhuang

- Create src/hooks/api.ts with useFetchFeed, useFetchItem, useFetchUser hooks
  - Implements React Query based data fetching with abort signal support
  - Handles poll type stories with poll option fetching
  - Includes TypeScript interfaces for Story, User, Comment, PollResult

- Create src/contexts/SettingsContext.tsx with SettingsProvider and useSettings hook
  - Converts all settings from original SettingsService
  - Implements theme detection logic with system color scheme preference
  - Maintains localStorage persistence for all settings
  - Provides toggleSettings, toggleOpenLinksInNewTab, setTheme, setFont, setSpacing methods

Co-Authored-By: Cindy Huang <cindy.huang@cognition.ai>
@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