Skip to content

Conversation

@devin-ai-integration
Copy link

Phase 2: Implement Core Components and API Integration for React Migration

Summary

This PR implements Phase 2 of the Angular to React migration, building out all core components with real Hacker News API integration. The React app now fetches and displays real data from the Hacker News API with full functionality including feeds, pagination, item details, nested comments with collapsible threading, and user profiles.

Key changes:

  • Created TypeScript interfaces for all data models (Story, User, Comment, PollResult, FeedType)
  • Implemented HackerNewsAPIService with fetchFeed(), fetchItemContent(), and fetchUser() methods using the fetch API
  • Updated Feed component to fetch real data with bidirectional pagination (Prev/More links)
  • Created Item component for feed list items with settings integration (fontSize, spacing, openInNewTab)
  • Updated ItemDetails component to display item details, nested comments, polls, and HTML content
  • Created Comment component with collapsible threading functionality ([+/-] toggle buttons)
  • Updated User component to display user profiles with karma, created date, and about section
  • Added Loader and ErrorMessage components for consistent loading/error states

API Base URL: https://node-hnapi.herokuapp.com

Review & Testing Checklist for Human

⚠️ Important: This is a large PR combining infrastructure and core functionality. Please review carefully.

  • Build & Run: Clone the PR branch and run cd react-app && npm install && npm run dev. Verify the app starts at http://localhost:5173 and redirects to /news/1
  • Test All Feed Types: Navigate through all feed types (News, Newest, Show, Ask, Jobs) and verify data loads correctly
  • Test Pagination: Click "More" to go to page 2, then "Prev" to return to page 1. Verify correct page numbers and data
  • Test ItemDetails: Click on an item with comments (not a job post). Verify comments display with proper nesting
  • Test Comment Collapsing: Click the [-] button to collapse a comment, then [+] to expand it. Verify nested comments are hidden/shown correctly
  • Test Error Handling: Try navigating to /item/999999 and /user/invaliduser to verify error messages display correctly
  • Test Settings Integration: Toggle between Light/Dark themes. Verify theme applies to all pages and persists on refresh
  • Security Review: Review the use of dangerouslySetInnerHTML in Comment.tsx, ItemDetails.tsx, and User.tsx. Verify the API sanitizes HTML content to prevent XSS attacks

Notes

Known Limitation - User Profiles:
The user profile endpoint (/user/:id) does not exist on the node-hnapi.herokuapp.com API. This was confirmed via curl testing:

curl -s https://node-hnapi.herokuapp.com/user/pg
# Returns: "Cannot GET /user/pg"

This matches the Angular app's behavior - the endpoint is implemented identically but the API doesn't support it. Error handling displays "Could not load user {username}" when this occurs.

Testing Performed:

  • ✅ All 5 feed types load real data (news, newest, show, ask, jobs)
  • ✅ Bidirectional pagination works (More/Prev buttons)
  • ✅ ItemDetails displays correctly with nested comments
  • ✅ Comment collapsing verified programmatically (works correctly)
  • ✅ Error handling verified (invalid users/items show error messages)
  • ✅ Settings Context integration works (theme toggle applies globally)
  • ✅ Browser console has no JavaScript errors during testing
  • ✅ Lint passes with 0 errors (9 pre-existing warnings from Phase 1 shadcn/ui components)

Browser Screenshots:
News Feed with Dark Theme
Item Details with Comments
Jobs Feed with Header

Link to Devin run: https://app.devin.ai/sessions/d83e0f9ca9c44669a5a976f8e0ce006e
Requested by: Gabe Smith ([email protected])

devin-ai-integration bot and others added 2 commits October 23, 2025 15:08
… migration

- Created new React + TypeScript project with Vite inside angular2-hn repo
- Installed and configured React Router with all Angular routes:
  * Feed routes: /news/:page, /newest/:page, /show/:page, /ask/:page, /jobs/:page
  * Item details: /item/:id
  * User profile: /user/:id
- Implemented Settings Context API for state management:
  * Theme management (default/night) with system preference detection
  * localStorage persistence for all settings (theme, openLinkInNewTab, titleFontSize, listSpacing)
  * System dark mode preference detection using window.matchMedia
- Created placeholder page components (Feed, ItemDetails, User)
- Fixed lint error in pre-installed use-toast.ts hook
- Tested locally: app runs, routing works, theme switching functional

This establishes the foundation for migrating the Angular Hacker News client to React.

Co-Authored-By: Gabe Smith <[email protected]>
…ation

- Created TypeScript interfaces for Story, User, Comment, PollResult, FeedType
- Implemented HackerNewsAPIService with fetchFeed(), fetchItemContent(), fetchUser() methods using fetch API
- Created reusable Loader and ErrorMessage components for loading/error states
- Updated Feed component to fetch real Hacker News data with pagination (Prev/More links)
- Created Item component for feed list items with settings integration (fontSize, spacing, openInNewTab)
- Updated ItemDetails component to display item details with nested comments, poll support, HTML content rendering
- Created Comment component with collapsible threading functionality ([+/-] buttons)
- Updated User component to display user profiles with karma, created date, about section
- All components integrate with Settings Context from Phase 1 (theme, settings)
- Tested locally: all feed types work (news, newest, show, ask, jobs), pagination works bidirectionally, comment collapsing verified, error handling confirmed
- Browser console has no errors during navigation
- Lint passes with 0 errors

Note: User profile API endpoint (/user/:id) doesn't exist on node-hnapi.herokuapp.com, matching Angular app behavior
Co-Authored-By: Gabe Smith <[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