Skip to content

React migration phase 1: typed HN API, settings, comment util, models - #866

Closed
vibhaseshadri-cognition wants to merge 1 commit into
devin/1791294814-react-phase0-scaffoldfrom
devin/1791294942-react-phase1-data-layer
Closed

vibhaseshadri-cognition wants to merge 1 commit into
devin/1791294814-react-phase0-scaffoldfrom
devin/1791294942-react-phase1-data-layer

Conversation

@vibhaseshadri-cognition

@vibhaseshadri-cognition vibhaseshadri-cognition commented Oct 6, 2026 •

Copy link
Copy Markdown

Summary

Phase 1 of the Angular → React migration: the framework-free data layer and settings state under react/src/shared/, built to the shared module contract so Phase 2 (routing/UI) can consume it. Stacked on #865. No UI and no App.tsx changes.

  • shared/models/: TS interfaces mirroring the Angular models. Fields the live node-hnapi can leave out are optional. Story.type is ItemType | 'link' | 'ask' | 'comment' because the API returns link/ask too. time_ago is string, which is what the API actually sends (Angular typed it as number). User.crated_time keeps Angular's typo. Also adds FeedName / FEED_NAMES.
  • shared/services/hackernewsApi.ts: fetchFeed / fetchItemContent / fetchPollContent / fetchUser use native fetch.
    • Errors: rejects on network errors and on non-2xx (HN API request to /item/2 failed with status 500). An already-aborted signal rejects with its AbortError before fetching; an abort mid-request comes through from fetch.
    • Polls: options id+1 … id+poll.length load in parallel with Promise.all, then poll[i] is replaced and poll_votes_count set to the sum of points. The promise resolves only after every option has loaded (Angular returned the story before its poll options arrived).
  • shared/services/settings.ts: the same localStorage keys and serialization as Angular, so existing users keep their settings. A saved theme that isn't a known Theme is ignored and the system theme is used instead; an openLinkInNewTab value that won't parse falls back to false (Angular would throw).
    • Helper added outside the contract: getSavedTheme().
  • SettingsProvider / useSettings / SettingsContext:
    • On first load with no saved theme, the system theme is saved (same effect as Angular's synthetic change event).
    • Subscribes to matchMedia(DARK_SCHEME_QUERY) change events and removes the same handler on unmount. This fixes Angular's removeEventListener(fn.bind(this)) bug.
    • toggleSettings is not persisted.
  • shared/utils/comment.ts: formatCommentCount, matching CommentPipe.
  • src/test/matchMedia.ts: a reusable mockMatchMedia() helper for tests (jsdom has no matchMedia; no polyfill in app code).

Locally, format:check, lint, typecheck, test, build and e2e all pass.

npm test coverage

-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------|---------|----------|---------|---------|-------------------
All files          |     100 |      100 |     100 |     100 |
 src               |     100 |      100 |     100 |     100 |
  App.tsx          |     100 |      100 |     100 |     100 |
 src/shared/models |     100 |      100 |     100 |     100 |
  comment.ts       |       0 |        0 |       0 |       0 |
  feed-type.ts     |     100 |      100 |     100 |     100 |
  index.ts         |     100 |      100 |     100 |     100 |
  poll-result.ts   |       0 |        0 |       0 |       0 |
  settings.ts      |       0 |        0 |       0 |       0 |
  story.ts         |       0 |        0 |       0 |       0 |
  user.ts          |       0 |        0 |       0 |       0 |
 ...hared/services |     100 |      100 |     100 |     100 |
  ...sProvider.tsx |     100 |      100 |     100 |     100 |
  hackernewsApi.ts |     100 |      100 |     100 |     100 |
  settings.ts      |     100 |      100 |     100 |     100 |
  ...ngsContext.ts |     100 |      100 |     100 |     100 |
  useSettings.ts   |     100 |      100 |     100 |     100 |
 src/shared/utils  |     100 |      100 |     100 |     100 |
  comment.ts       |     100 |      100 |     100 |     100 |
-------------------|---------|----------|---------|---------|-------------------

The 0 rows are type-only model files with no runtime code. 45 tests across 6 files.

Devin-Org: engineering

Link to Devin session: https://app.devin.ai/sessions/05362fe05359497282a4e9d0f37366a5
Open in Devin Desktop: https://app.devin.ai/desktop/session/05362fe05359497282a4e9d0f37366a5?variant=devin
Requested by: @vibhaseshadri-cognition

…comment util, models

Co-Authored-By: Vibha  Seshadri <vibha.seshadri@cognition.ai>
@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown

Closing as part of the nightly demo-repo reset — reopen if this demo artifact is still needed.

@devin-ai-integration
devin-ai-integration Bot deleted the devin/1791294942-react-phase1-data-layer branch October 26, 2026 12:11
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