Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bc0a50f
feat: add isolated React migration foundation
devin-ai-integration[bot] Nov 11, 2026
118d5ef
fix: upgrade React router and test tooling security dependencies
devin-ai-integration[bot] Nov 11, 2026
4cbdbfc
fix: preserve Angular theme storage compatibility
devin-ai-integration[bot] Nov 11, 2026
8801203
feat: port React user profile page
devin-ai-integration[bot] Nov 11, 2026
3c461d2
feat: port React app shell and settings controls
devin-ai-integration[bot] Nov 11, 2026
0b0a272
feat: port React item details and recursive comments
devin-ai-integration[bot] Nov 11, 2026
656352c
Port Hacker News feed lists, items and pagination to React
devin-ai-integration[bot] Nov 11, 2026
fe0399d
fix: sanitize user profile about HTML
devin-ai-integration[bot] Nov 11, 2026
b302fd1
fix: secure targets in item HTML links
devin-ai-integration[bot] Nov 11, 2026
8176267
fix: reject invalid item details responses
devin-ai-integration[bot] Nov 11, 2026
98633e9
Merge React foundation (#932)
devin-ai-integration[bot] Nov 11, 2026
9639d8a
Merge React app shell (#934)
devin-ai-integration[bot] Nov 11, 2026
75cc8a4
Merge React feeds (#936)
devin-ai-integration[bot] Nov 11, 2026
97139dc
Merge React item details (#935)
devin-ai-integration[bot] Nov 11, 2026
6dcb233
Merge React user profile (#933)
devin-ai-integration[bot] Nov 11, 2026
24ae290
feat: promote React app to repository root
devin-ai-integration[bot] Nov 11, 2026
45bcc2b
feat: restore PWA shell and generate Workbox service worker
devin-ai-integration[bot] Nov 11, 2026
2c960c4
test: cover React PWA flows with production Playwright suite
devin-ai-integration[bot] Nov 11, 2026
381a030
docs: document React development PWA and deployment
devin-ai-integration[bot] Nov 11, 2026
efa4561
fix: restore visible loading shell before React mounts
devin-ai-integration[bot] Nov 11, 2026
6987ff2
fix: track initial and client-side navigation pageviews
devin-ai-integration[bot] Nov 11, 2026
5f5f1c7
test: verify pre-mount loader and scope shell logo assertions
devin-ai-integration[bot] Nov 11, 2026
3996436
fix: track only destination analytics for root redirect
devin-ai-integration[bot] Nov 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI
on:
push:
branches: [master]
pull_request:
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '24'
cache: npm
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '24'
cache: npm
- run: npm ci
- run: npx playwright install --with-deps chromium
- run: npm run e2e
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: playwright-report/
retention-days: 7
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

# dependencies
/node_modules
*.tsbuildinfo
/playwright-report
/test-results

# profiling files
chrome-profiler-events.json
Expand Down
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
language: node_js
node_js:
- "6.9"
- "24"

branches:
only:
- master

before_script:
- npm install -g firebase-tools
- npm install -g @angular/cli

install:
- npm ci

script:
- npm run build
Expand Down
57 changes: 35 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
# Contributing

Thank you for your interest in contributing! Please feel free to put up a PR for any issue or feature request.
Even if you have little to no experience with Angular, I'll be more than happy to help. :)
Thank you for your interest! Issues and pull requests are welcome.

## Setup

1. Fork the repo
2. Clone your fork
3. Make a branch for your feature or bug fix
4. If you don't have Angular CLI installed: `npm install -g angular-cli@latest`
5. `ng init`
6. Type `n` for each file to not overwrite any file changes
7. Run `npm start` and open `localhost:4200` in a browser
8. Work your magic
9. Run `npm run build` or `npm run static-serve` to kick off a production build and make sure nothing is broken
10. To test service worker changes:
* `npm run build` to kick off a fresh build and update the `dist/` directory
* `npm run precache` to generate the service worker file
* `npm run static-serve` to load the application along with the service worker asset using [live-server](https://github.com/tapio/live-server)
11. Add yourself to the [contributor's list](https://github.com/hdjirdeh/angular2-hn#contributors) in the README!
12. Commit your changes and reference the issue you're addressing (for example: `git commit -am 'Commit message. Closes #5'`)
13. Push your branch to your fork
14. Create a pull request from your branch on your fork to `master` on this repo
15. Have your branch get merged in! :star2:

If you experience a problem at any point, please don't hesitate to file an issue or send me a message!
1. Fork and clone the repository, then create a branch for your change.
2. Use Node.js 24 or newer and run `npm ci` from the repository root.
3. Run `npm run dev` and open the URL printed by Vite.
4. Make a focused change and add appropriate regression tests.

## Validation

```sh
npm run lint
npm test
npm run build
npx playwright install chromium
npm run e2e
```

On Linux CI, use `npx playwright install --with-deps chromium` to install browser OS
dependencies as well. Playwright builds and serves production on port 4173; stop any
other server on that port first. Tests use deterministic HN API fixtures and cover
desktop and mobile Chromium, including offline app-shell navigation.

For manual PWA checks, run `npm run build` followed by `npm run preview`. The dev server
does not enable the service worker. Wait until the worker controls the page before
testing offline reloads and deep links. API data is deliberately not cached.

## Pull requests

- Keep changes scoped and use shared models, API helpers, and settings contracts.
- Do not commit `dist/`, dependencies, Playwright reports, or credentials.
- Commit your changes, push your branch, and open a pull request targeting `master`.
- Describe the behavior change, test results, and any unverified scenarios. Include
desktop/mobile evidence for UI changes.

See the [README](README.md) for architecture, scripts, and deployment information and
the [license](LICENSE.md) for licensing terms.
223 changes: 121 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,102 +1,121 @@
<p align="center">
<a href="https://angular2-hn.firebaseapp.com">
<img alt="Angular 2 HN" title="Angular 2 HN" src="http://i.imgur.com/J303pQ4.png" width="150">
</a>
</p>

<p align="center">
A progressive Hacker News client built with Angular
</p>

<p align="center">
<a href="https://angular2-hn.firebaseapp.com">View App</a>
</p>

<p align="center">
<a href="/CONTRIBUTING.md"><img alt="PRs Welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"></a>
<a href="https://travis-ci.org/housseindjirdeh/angular2-hn"><img alt="Build Status" src="https://travis-ci.org/housseindjirdeh/angular2-hn.svg?branch=master"></a>
</p>

---

:zap: **Fast:** Service Worker App Shell + Dynamic Content model to achieve faster load times with and without a network.

:iphone: **Responsive:** Completely responsive UI that can be installed to your mobile home screen to provide a native feel.

:rocket: **Progressive:** [Lighthouse](https://github.com/GoogleChrome/lighthouse) score of 87/100.

<p align="center">
<img src = "http://i.imgur.com/fzJzLFO.png" width=500>
</p>

## Mobile Preview

<p align="center">
<img src = "http://i.imgur.com/ZloA1hn.gif">
</p>

## Laptop Preview

<p align="center">
<img src = "http://i.imgur.com/MrKHaln.gif">
</p>

## Offline Support

This app uses [Workbox](https://workboxjs.org/) to generate a service worker as part of the build step to load quickly and work offline.

## Manifest

With Chromium based browsers for Android (Chrome, Opera, etc...), Angular 2 HN includes a Web App Manifest that allows you to install to your homescreen.

<p align="center">
<img src = "http://i.imgur.com/1RaaNkr.png">
</p>

## Themes

Built in theme engine!

Current themes:
* Default
* Night
* Black (AMOLED)

More to come!

## Areas of improvement

- Realtime updating using the Firebase SDK (may need to add option to settings so service worker can still rely on REST endpoints)
- Server side rendering

Feel free to send me feedback on [twitter](https://twitter.com/hdjirdeh) or [file an issue](https://github.com/hdjirdeh/angular2-hn/issues/new)! Feature requests are always welcome.

## Build process

Note: This project has been ejected (with AOT + production settings) in order to customize Webpack configurations.

- Clone or download the repo
- `npm install`
- `npm start` to run the application with webpack-dev-server or `npm build` to kick off a fresh build and update the output directory (`dist/`)

Note: Any Service Worker changes will not be reflected when you run the application locally in development. To test service worker changes:
- `npm build`
- `npm run precache` to generate the service worker file
- `npm run static-serve` to load the application along with the service worker asset using [live-server](https://github.com/tapio/live-server)

## Contributors

A million thanks to some awesome people :)

* [Ashwin Sureshkumar](https://github.com/ashwin-sureshkumar)
* [Mateusz](https://github.com/mateuszwitkowski)
* [Jordi Collell](https://github.com/jordic)
* [Ben Brooks](https://github.com/bbrks)
* [Zach Berger](https://github.com/zachberger)
* [blAck PR](https://github.com/blackpr)
* [Bram Borggreve](https://github.com/beeman)
* [Antonio Indrianjafy](https://github.com/Antogin)
* [Addy Osmani](https://github.com/addyosmani)
* [Majid Hajian](https://github.com/mhadaily)
* [Jeff Cross](https://github.com/jeffbcross)
* [Minko Gechev](https://github.com/mgechev)
# Hacker News PWA

A responsive Hacker News client with paginated feeds, nested comments, user profiles,
and persistent display settings. Built with **React 18**, **TypeScript**, **React Router**,
and **Vite**. **Workbox**, through `vite-plugin-pwa`, generates the production service
worker. Profile HTML is sanitized with DOMPurify.

## Getting started

Use **Node.js 24 or newer** and npm. Run commands from the repository root:

```sh
npm ci
npm run dev
```

Open the URL printed by Vite. No Angular CLI or global build tools are required.

| Command | Purpose |
| --- | --- |
| `npm run dev` | Start the development server with hot reload. |
| `npm run build` | Typecheck and build the production app and service worker into `dist/`. |
| `npm run preview` | Serve the existing production build locally. |
| `npm run lint` | Run ESLint. |
| `npm test` | Run Vitest and React Testing Library tests in jsdom. |
| `npm run e2e` | Build and serve production, then run Playwright in desktop and mobile Chromium. |

Install bundled Chromium before running e2e tests:

```sh
npx playwright install chromium
npm run e2e
# Repeat every test three times:
npx playwright test --repeat-each=3
```

Playwright uses port 4173 and manages its own production preview server. API responses
are mocked from `e2e/fixtures/` so tests do not depend on the live HN API. The HTML report
is written to `playwright-report/`; failed runs retain traces and screenshots.

## PWA and offline behavior

The production build generates `sw.js` and registers it automatically. Workbox precaches
the app shell (HTML, JavaScript, CSS), favicon, `manifest.json`, and public icons/images.
After an online visit finishes installing the service worker and it controls the page,
reloads and deep links such as `/news/2`, `/item/123`, and `/user/alice` can load the
app shell offline through the `/index.html` navigation fallback.

**HN API data is not cached**, matching the original Angular app's service-worker
configuration. Offline pages display a load error while the header/navigation remains
available; previously viewed stories and profiles are not an offline data store.
The service worker uses automatic updates. The existing web app manifest and icons
support installation in compatible browsers.

Service workers are not enabled by the development server. To check the actual PWA:

```sh
npm run build
npm run preview -- --port 4173
```

Use localhost (or HTTPS when deployed), wait for service-worker activation/control,
then test offline reload/navigation. The Playwright suite covers this against the real
generated worker, removing API mocks before taking the browser offline.

## Settings

The cog opens controls for Default, Night, and Black (AMOLED) themes, title font size,
list spacing, and opening external links in a new tab. Settings retain the original
localStorage keys, including the legacy `amoledblack` theme value. System color-scheme
changes continue to override and persist the selected theme, as in the original app.

## Project layout

```text
src/
main.tsx Router and settings-provider composition
routes.tsx Feed, item, and user routes
App.tsx Shared header/footer layout
api/ node-hnapi requests, cancellation, and poll aggregation
models/ Shared story, comment, user, feed, and settings contracts
pages/ Feed/paging, item/comments, and user-profile views
components/ Header, footer, settings, loader, and error display
settings/ SettingsProvider and useSettings
styles/ Shared SCSS themes and layout
utils/ Comment-count formatting
public/ Original manifest, favicon, icons, and images
e2e/ Production-browser specs and deterministic JSON fixtures
vite.config.ts React, Vitest, and Workbox/PWA configuration
playwright.config.ts Desktop/mobile Chromium and production web server
firebase.json Hosting rewrites, cache headers, and database rules reference
```

Unit/component tests live beside source files. Shared API requests accept AbortSignals
and reject HTTP failures. The original API model spelling `User.crated_time` is retained.

## Deployment and CI

Firebase Hosting serves **`dist/`** with an SPA rewrite to `/index.html`. `sw.js` and
`index.html` have `Cache-Control: no-cache` headers so browsers can revalidate updates.
`database.rules.json` and the Firebase project aliases in `.firebaserc` are preserved.

`.travis.yml` installs dependencies and builds with Node 24 on `master`, then uses its
existing Firebase CLI deploy step with `FIREBASE_TOKEN`. Deployment credentials belong
in CI secrets, not source control.

GitHub Actions (`.github/workflows/ci.yml`) runs on pull requests and pushes to `master`:

- Node 24: `npm ci`, lint, unit tests, and production build.
- Separate e2e job: install Chromium with OS dependencies, then `npm run e2e`.
- Upload the Playwright HTML report on failure.

## History, contributing, and license

Originally **Angular 2 HN**, the Angular PWA by
[Houssein Djirdeh](https://github.com/hdjirdeh), this project has been migrated to React
while preserving its routes, themes, public assets, and app-shell offline behavior.
Thanks to the original contributors and maintainers.

See [CONTRIBUTING.md](CONTRIBUTING.md) for development and pull-request guidance and
[LICENSE.md](LICENSE.md) for the license.
Loading
Loading