Skip to content

PR 3/10 — Port Hacker News data layer to fetch + useFetch hook - #755

Open
devanshi-gpta wants to merge 1 commit into
devin-09.08.2026-devanshi/port-models-and-shared-stylesfrom
devin-09.08.2026-devanshi/port-hackernews-data-layer
Open

devanshi-gpta wants to merge 1 commit into
devin-09.08.2026-devanshi/port-models-and-shared-stylesfrom
devin-09.08.2026-devanshi/port-hackernews-data-layer

Conversation

@devanshi-gpta

Copy link
Copy Markdown

Summary

Part of the Angular -> React migration chain; based on devin-09.08.2026-devanshi/port-models-and-shared-styles.

Ports src/app/shared/services/hackernews-api.service.ts and src/app/shared/pipes/comment.pipe.ts into react-app/, dropping RxJS entirely:

  • src/services/hackernews-api.tsfetchFeed, fetchItemContent, fetchPollContent, fetchUser as plain async functions over fetch, each taking an optional AbortSignal and throwing on non-ok responses (the Angular lazyFetch Observable wrapper silently ignored HTTP errors).
  • Behaviour change in the poll aggregation: the Angular version emitted the story first and mutated poll / poll_votes_count later via subscribe, so consumers saw a partially populated story. The port awaits the per-option requests in parallel, so the resolved story is already complete:
if (story.type === 'poll' && story.poll) {
    story.poll_votes_count = 0;
    const results = await Promise.all(story.poll.map((_, i) => fetchPollContent(story.id + i + 1, signal)));
    results.forEach((r, i) => { story.poll[i] = r; story.poll_votes_count += r.points; });
}
  • src/hooks/useFetch.tsuseFetch<T>(fetcher, deps) returning { data, error, loading }; aborts the in-flight request on deps change/unmount and swallows AbortError. Will back the feed, item-details and user pages.
  • src/utils/format-comment-count.tsformatCommentCount(count) replacing CommentPipe ('discuss' / '1 comment' / 'N comments').

Proposed fixes

  • Vitest coverage for formatCommentCount and, with a stubbed globalThis.fetch, for poll aggregation, the non-poll path, non-ok rejection and signal pass-through.
  • npm run typecheck, npm run lint, npm test and npm run build pass in react-app/.
  • No files under src/ (the Angular app) are touched.

Link to Devin session: https://app.devin.ai/sessions/50f5f5797eb8469d9e8e0eaab2586019
Open in Devin Desktop: https://app.devin.ai/desktop/session/50f5f5797eb8469d9e8e0eaab2586019?variant=devin
Requested by: @devanshi-gpta

Co-Authored-By: Devanshi Gupta <devanshi.gupta@cognition.ai>
@devin-ai-integration

Copy link
Copy Markdown

🤖 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, CI, and merge conflict 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