feature: Migrate Angular 9 HN PWA to Create React App + TypeScript#441
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
feature: Migrate Angular 9 HN PWA to Create React App + TypeScript#441devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Port the Angular Hacker News client to a new CRA + TypeScript project in react-app/ (react-router-dom v6, sass). Models, API service (async + AbortController + Promise.all poll logic), SettingsContext, routing with lazy/Suspense, all components, styles, PWA service worker, and GA pageview tracking are ported. Adds Jest + RTL tests for the API, helper, context, and Feed/Comment/Item components. Co-Authored-By: Vibha Seshadri <vibha.seshadri@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Author
End-to-end test resultsRan the migrated CRA app locally (
Full recording of the session: Devin session: https://app.devin.ai/sessions/38b93608d6844a8ea9f01300fe753510 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the Angular 9 Hacker News PWA to a new Create React App + TypeScript project in
react-app/, leaving the original Angular source untouched for reference. Stack: CRA TS template,react-router-domv6,sass, CRA's built-in Jest + React Testing Library.The Angular pieces map to React as follows:
src/models/): the Angular model classes become plain TS interfaces, carried over unchanged.Storygains optionalcontent?/text?(the Angular template already read these off the API response even though the class omitted them — required now understrictTS).src/api/hackerNews.ts):HackerNewsAPIService(RxJSObservable+unfetch) becomes async functions overfetchtargetinghttps://node-hnapi.herokuapp.com, each accepting an optionalAbortControllersignal. The nested RxJS poll subscriptions infetchItemContentare rewritten withPromise.all:src/context/SettingsProvider.tsx):SettingsServicebecomes aSettingsContext+ provider. State initializes fromlocalStorage; thematchMedia('(prefers-color-scheme: dark)')subscription +initThemelogic moves into auseEffectwith cleanup;toggleSettings/toggleOpenLinksInNewTab/setTheme/setFont/setSpacingupdate state and persist tolocalStorage.App.tsx): rebuilt withreact-router-domv6 — a<Feed feedType=... />per feed at/:feedType/:page,/→/news/1via<Navigate>, and/item/:id+/user/:idviaReact.lazy()+<Suspense>.App.tsxis the layout shell (settings.themewrapper,<Header/>, routed outlet,<Footer/>) and converts the GA pageview logic into auseEffectonuseLocation().Header/Footer/Settings(context-driven, Angular[checked]/(change)→ controlledchecked/onChange), sharedLoader/ErrorMessage,Feed(useParamspage, effect keyed on[feedType, pageNum],<Link>Prev/More gated onlistStart !== 1/items.length === 30),Item(hasUrlderived value,[ngStyle]→ inlinestyle, conditionaltarget/rel),ItemDetails(goBack→useNavigate()(-1),[innerHTML]→dangerouslySetInnerHTML, poll bar width inline), recursiveComment(collapseviauseState, deleted branch), andUser. Angular'scommentpipe becomesformatComments(count).shared/scss/+ per-component.scsscopied tosrc/styles/and colocated files;:host,>>>,::ng-deeprewritten as plain selectors; deprecated Sass/division replaced with equivalents for Dart Sass compatibility.styles.scssglobals →src/index.scss.ServiceWorkerModulereplaced with CRA'sserviceWorkerRegistration.register()+ a Workboxservice-worker.ts; the GA snippet lives inpublic/index.html.Tests
Jest + RTL, mocking
fetch(andmatchMedia/scrollTopolyfilled insetupTests.ts):hackerNews.ts:fetchFeedURL + parsed stories;fetchItemContentpoll accumulation/population;fetchUserparsing.formatComments:"discuss"/"1 comment"/"N comments".SettingsContext: setters update state + writelocalStorage; theme initializes fromlocalStorage.Feed: loader → items, error on rejection, Prev/More visibility by page + item count.Comment: nested recursion, collapse toggle, deleted branch.Item:hasUrl(external vs internal link) and new-tabtarget/relwhenopenLinkInNewTabis set.Verification
Run from
react-app/(Node 20):npx tsc --noEmit— cleannpm run lint— cleanCI=true npm test— 6 suites, 19 tests passingnpm run build— compiles successfully (service worker emitted)Link to Devin session: https://app.devin.ai/sessions/38b93608d6844a8ea9f01300fe753510
Requested by: @vibhaseshadri-cognition
Devin Review