From aa0011f4789ee8eb06ac2762c794ad8984ed8773 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:31:02 +0000 Subject: [PATCH 1/6] feature: port header, footer, settings panel and GA pageviews to React Co-Authored-By: Matthew Guerra --- react-app/index.html | 7 + react-app/src/App.tsx | 6 + react-app/src/analytics/usePageViews.ts | 17 ++ react-app/src/components/Footer/Footer.scss | 22 +++ react-app/src/components/Footer/Footer.tsx | 14 ++ react-app/src/components/Header/Header.scss | 148 ++++++++++++++++++ react-app/src/components/Header/Header.tsx | 53 +++++++ .../src/components/Settings/Settings.scss | 73 +++++++++ .../src/components/Settings/SettingsPanel.tsx | 81 ++++++++++ react-app/src/components/shell.test.tsx | 80 ++++++++++ react-app/src/routes.tsx | 5 +- 11 files changed, 504 insertions(+), 2 deletions(-) create mode 100644 react-app/src/analytics/usePageViews.ts create mode 100644 react-app/src/components/Footer/Footer.scss create mode 100644 react-app/src/components/Footer/Footer.tsx create mode 100644 react-app/src/components/Header/Header.scss create mode 100644 react-app/src/components/Header/Header.tsx create mode 100644 react-app/src/components/Settings/Settings.scss create mode 100644 react-app/src/components/Settings/SettingsPanel.tsx create mode 100644 react-app/src/components/shell.test.tsx diff --git a/react-app/index.html b/react-app/index.html index 37f11202a..121a8539f 100644 --- a/react-app/index.html +++ b/react-app/index.html @@ -13,5 +13,12 @@
+ diff --git a/react-app/src/App.tsx b/react-app/src/App.tsx index 9e7e24ab4..58a821073 100644 --- a/react-app/src/App.tsx +++ b/react-app/src/App.tsx @@ -1,18 +1,24 @@ import { Suspense } from 'react'; import { Outlet } from 'react-router-dom'; +import { usePageViews } from './analytics/usePageViews'; +import { Footer } from './components/Footer/Footer'; +import { Header } from './components/Header/Header'; import { Loader } from './components/Loader/Loader'; import { useSettings } from './settings'; import './styles/app.scss'; export default function App() { const { settings } = useSettings(); + usePageViews(); return (
+
}> +
); diff --git a/react-app/src/analytics/usePageViews.ts b/react-app/src/analytics/usePageViews.ts new file mode 100644 index 000000000..365013e69 --- /dev/null +++ b/react-app/src/analytics/usePageViews.ts @@ -0,0 +1,17 @@ +import { useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; + +declare global { + interface Window { + ga?: (...args: unknown[]) => void; + } +} + +// Mirrors AppComponent's NavigationEnd hook: one GA pageview per route change. +export function usePageViews() { + const { pathname, search } = useLocation(); + useEffect(() => { + window.ga?.('set', 'page', pathname + search); + window.ga?.('send', 'pageview'); + }, [pathname, search]); +} diff --git a/react-app/src/components/Footer/Footer.scss b/react-app/src/components/Footer/Footer.scss new file mode 100644 index 000000000..1749e3d63 --- /dev/null +++ b/react-app/src/components/Footer/Footer.scss @@ -0,0 +1,22 @@ +@use "../../styles/media" as *; + +#footer { + position: relative; + padding: 10px; + height: 60px; + letter-spacing: 0.7px; + text-align: center; + + a { + font-weight: bold; + text-decoration: none; + + &:hover { + text-decoration: underline; + } + } + + @media #{$mobile-only} { + display: none; + } +} diff --git a/react-app/src/components/Footer/Footer.tsx b/react-app/src/components/Footer/Footer.tsx new file mode 100644 index 000000000..07a86f8e0 --- /dev/null +++ b/react-app/src/components/Footer/Footer.tsx @@ -0,0 +1,14 @@ +import './Footer.scss'; + +export function Footer() { + return ( + + ); +} diff --git a/react-app/src/components/Header/Header.scss b/react-app/src/components/Header/Header.scss new file mode 100644 index 000000000..a0dd88ec6 --- /dev/null +++ b/react-app/src/components/Header/Header.scss @@ -0,0 +1,148 @@ +@use "../../styles/media" as *; + +#header { + color: #fff; + padding: 6px 0; + line-height: 18px; + vertical-align: middle; + position: relative; + z-index: 1; + width: 100%; + + @media #{$mobile-only} { + height: 50px; + position: fixed; + top: 0; + } + + a { + display: inline; + } +} + +.home-link { + width: 50px; + height: 66px; +} + +.logo-inner { + width: 32px; + position: absolute; + left: 17px; + top: 18px; + z-index: -1; + height: 32px; + border-radius: 50%; + + @media #{$mobile-only} { + left: 16px; + top: 12px; + } +} + +.logo { + width: 50px; + padding: 3px 8px 0; + + @media #{$mobile-only} { + width: 45px; + padding: 0 0 0 10px; + } +} + +h1 { + font-weight: normal; + display: inline-block; + vertical-align:middle; + margin: 0; + font-size: 16px; + + a { + color: #fff; + text-decoration: none; + } +} + +.name { + margin-right: 30px; + margin-bottom: 2px; + + @media #{$mobile-only} { + display: none; + } +} + +.header-text { + position: absolute; + width: inherit; + height: 20px; + left: 10px; + top: 27px; + z-index: -1; + + @media #{$mobile-only} { + top: 22px; + } +} + +.left { + position: absolute; + left: 60px; + font-size: 16px; + + @media #{$mobile-only} { + width: 100%; + left: 0; + } +} + +.header-nav { + display: inline-block; + margin-left: 20px; + + @media #{$mobile-only} { + margin-left: 60px; + } + + a { + color: hsla(0,0%,100%,.9); + text-decoration: none; + margin: 0 5px; + letter-spacing: 1.8px; + + &:hover { + color: #fff; + } + } + + .active { + color: #fff; + } +} + +.info { + position: absolute; + top: 0; + right: 20px; + height: 100%; + + @media #{$mobile-only} { + right: 10px; + } + + img { + opacity: 0.8; + width: 25px; + margin-top: 21.5px; + display: block; + + &:hover { + opacity: 1; + cursor: pointer; + } + + @media #{$mobile-only} { + margin-top: 15px; + } + } +} diff --git a/react-app/src/components/Header/Header.tsx b/react-app/src/components/Header/Header.tsx new file mode 100644 index 000000000..3fb4c4574 --- /dev/null +++ b/react-app/src/components/Header/Header.tsx @@ -0,0 +1,53 @@ +import { NavLink } from 'react-router-dom'; +import { useSettings } from '../../settings'; +import { SettingsPanel } from '../Settings/SettingsPanel'; +import './Header.scss'; + +const NAV_LINKS = [ + { to: '/newest/1', label: 'new' }, + { to: '/show/1', label: 'show' }, + { to: '/ask/1', label: 'ask' }, + { to: '/jobs/1', label: 'jobs' }, +]; + +function scrollTop() { + window.scrollTo(0, 0); +} + +export function Header() { + const { settings, toggleSettings } = useSettings(); + return ( +
+ + {settings.showSettings && } +
+ ); +} diff --git a/react-app/src/components/Settings/Settings.scss b/react-app/src/components/Settings/Settings.scss new file mode 100644 index 000000000..23213cceb --- /dev/null +++ b/react-app/src/components/Settings/Settings.scss @@ -0,0 +1,73 @@ +@use "../../styles/media" as *; + +.overlay { + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + background: rgba(0, 0, 0, 0.7); + opacity: 1; + z-index: 1; +} + +.popup { + margin: 70px auto; + padding: 30px; + border-radius: 5px; + width: 30%; + position: relative; + h1 { + margin-top: 0; + margin-bottom: 0px; + color: #fff; + text-align: center; + letter-spacing: 1px; + } + h2 { + padding-top: 10px; + } + hr { + width: 40%; + margin-bottom: 20px; + } + .close { + position: absolute; + top: 12px; + right: 20px; + font-size: 30px; + font-weight: bold; + text-decoration: none; + color: rgba(255,255,255,0.8); + &:hover { + color: #fff; + cursor: pointer; + } + } + .content { + max-height: 30%; + color: #fff; + letter-spacing: 1px; + overflow: auto; + } + input[type=number] { + display: block; + width: 80%; + height: 20px; + margin-bottom: 15px; + border-radius: 5px; + padding: 2px; + } +} + +.control-section { + margin-bottom: 15px; + padding-bottom: 15px; + border-bottom: 1px solid white; +} + +@media screen and (max-width: 700px) { + .box, .popup { + width: 70%; + } +} diff --git a/react-app/src/components/Settings/SettingsPanel.tsx b/react-app/src/components/Settings/SettingsPanel.tsx new file mode 100644 index 000000000..f0ed1e790 --- /dev/null +++ b/react-app/src/components/Settings/SettingsPanel.tsx @@ -0,0 +1,81 @@ +import type { Theme } from '../../models'; +import { useSettings } from '../../settings'; +import './Settings.scss'; + +const THEME_OPTIONS: { value: Theme; label: string }[] = [ + { value: 'default', label: 'Default' }, + { value: 'night', label: 'Night' }, + { value: 'amoledblack', label: 'Black (AMOLED)' }, +]; + +export function SettingsPanel() { + const { settings, toggleSettings, toggleOpenLinksInNewTab, setTheme, setFont, setSpacing } = useSettings(); + return ( +
+
+

Settings

+
+ + × + +
+
+

Links

+ +
+
+
+

Select a theme

+ {THEME_OPTIONS.map(({ value, label }) => ( +
+ +
+ ))} +
+
+

Change Font

+
+ +
+
+ +
+
+
+
+
+
+ ); +} diff --git a/react-app/src/components/shell.test.tsx b/react-app/src/components/shell.test.tsx new file mode 100644 index 000000000..76765b06b --- /dev/null +++ b/react-app/src/components/shell.test.tsx @@ -0,0 +1,80 @@ +import { render, screen, within } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { createMemoryRouter, RouterProvider } from 'react-router-dom'; +import { afterEach, describe, expect, it, vi } from 'vitest'; +import { routes } from '../routes'; +import { SettingsProvider } from '../settings'; + +function renderAt(path: string) { + const router = createMemoryRouter(routes, { initialEntries: [path] }); + const view = render( + + + + ); + return { router, ...view }; +} + +afterEach(() => { + delete window.ga; +}); + +describe('app shell', () => { + it('renders header nav links and footer', async () => { + renderAt('/news/1'); + await screen.findByTestId('feed-page'); + for (const label of ['new', 'show', 'ask', 'jobs']) { + expect(screen.getByRole('link', { name: label })).toBeInTheDocument(); + } + expect(screen.getByRole('link', { name: 'GitHub' })).toHaveAttribute( + 'href', + 'https://github.com/hdjirdeh/angular2-hn' + ); + }); + + it('navigates via the header and marks the active link', async () => { + const { router } = renderAt('/news/1'); + await screen.findByTestId('feed-page'); + await userEvent.click(screen.getByRole('link', { name: 'show' })); + expect(router.state.location.pathname).toBe('/show/1'); + expect(await screen.findByTestId('feed-page')).toHaveTextContent('show page 1'); + expect(screen.getByRole('link', { name: 'show' })).toHaveClass('active'); + expect(screen.getByRole('link', { name: 'new' })).not.toHaveClass('active'); + }); + + it('opens settings, changes theme and preferences, and closes', async () => { + const { container } = renderAt('/news/1'); + await screen.findByTestId('feed-page'); + expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); + + await userEvent.click(screen.getByRole('button', { name: 'Settings' })); + const dialog = screen.getByRole('dialog', { name: 'Settings' }); + + await userEvent.click(within(dialog).getByLabelText('Night')); + expect(container.firstChild).toHaveClass('night'); + expect(localStorage.getItem('theme')).toBe('night'); + + await userEvent.click(within(dialog).getByLabelText('Open links in a new tab')); + expect(localStorage.getItem('openLinkInNewTab')).toBe('true'); + + const font = within(dialog).getByLabelText('Font size:'); + await userEvent.clear(font); + await userEvent.type(font, '20'); + expect(localStorage.getItem('titleFontSize')).toBe('20'); + + await userEvent.click(within(dialog).getByRole('button', { name: 'Close settings' })); + expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); + }); + + it('sends a GA pageview on each route change', async () => { + const ga = vi.fn(); + window.ga = ga; + const { router } = renderAt('/'); + await screen.findByTestId('feed-page'); + await router.navigate('/item/1'); + await screen.findByTestId('item-page'); + expect(ga).toHaveBeenCalledWith('set', 'page', '/news/1'); + expect(ga).toHaveBeenCalledWith('set', 'page', '/item/1'); + expect(ga.mock.calls.filter(([cmd]) => cmd === 'send')).toHaveLength(2); + }); +}); diff --git a/react-app/src/routes.tsx b/react-app/src/routes.tsx index f3a591242..a2ced3822 100644 --- a/react-app/src/routes.tsx +++ b/react-app/src/routes.tsx @@ -1,5 +1,5 @@ import { lazy } from 'react'; -import { Navigate, type RouteObject } from 'react-router-dom'; +import { redirect, type RouteObject } from 'react-router-dom'; import App from './App'; import { FEED_TYPES } from './models'; import FeedPage from './pages/FeedPage'; @@ -13,7 +13,8 @@ export const routes: RouteObject[] = [ path: '/', element: , children: [ - { index: true, element: }, + // A loader redirect resolves before render, so `/` never produces its own pageview. + { index: true, loader: () => redirect('/news/1') }, ...FEED_TYPES.map((feedType) => ({ path: `${feedType}/:page`, element: , From 61230e052a51bb80978a678ddd5f384317e46fb5 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:32:50 +0000 Subject: [PATCH 2/6] bug: make settings open/close controls keyboard-accessible buttons Co-Authored-By: Matthew Guerra --- react-app/src/components/Header/Header.scss | 8 ++++++++ react-app/src/components/Header/Header.tsx | 10 +++------- react-app/src/components/Settings/Settings.scss | 5 +++++ react-app/src/components/Settings/SettingsPanel.tsx | 4 ++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/react-app/src/components/Header/Header.scss b/react-app/src/components/Header/Header.scss index a0dd88ec6..8c392180d 100644 --- a/react-app/src/components/Header/Header.scss +++ b/react-app/src/components/Header/Header.scss @@ -146,3 +146,11 @@ h1 { } } } + +.settings-button { + padding: 0; + border: 0; + background: none; + cursor: pointer; + font: inherit; +} diff --git a/react-app/src/components/Header/Header.tsx b/react-app/src/components/Header/Header.tsx index 3fb4c4574..f941e03f0 100644 --- a/react-app/src/components/Header/Header.tsx +++ b/react-app/src/components/Header/Header.tsx @@ -38,13 +38,9 @@ export function Header() {
- Settings +
{settings.showSettings && } diff --git a/react-app/src/components/Settings/Settings.scss b/react-app/src/components/Settings/Settings.scss index 23213cceb..1cc49ed05 100644 --- a/react-app/src/components/Settings/Settings.scss +++ b/react-app/src/components/Settings/Settings.scss @@ -32,6 +32,11 @@ margin-bottom: 20px; } .close { + padding: 0; + border: 0; + background: none; + cursor: pointer; + line-height: 1; position: absolute; top: 12px; right: 20px; diff --git a/react-app/src/components/Settings/SettingsPanel.tsx b/react-app/src/components/Settings/SettingsPanel.tsx index f0ed1e790..5f7802f60 100644 --- a/react-app/src/components/Settings/SettingsPanel.tsx +++ b/react-app/src/components/Settings/SettingsPanel.tsx @@ -15,9 +15,9 @@ export function SettingsPanel() {

Settings


- +

Links

From 57cd04e7ac51347f9db3898e76c8a6df9c0c3472 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:37:17 +0000 Subject: [PATCH 3/6] bug: drop placeholder text assertion from shell nav test so it survives the feeds PR Co-Authored-By: Matthew Guerra --- react-app/src/components/shell.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-app/src/components/shell.test.tsx b/react-app/src/components/shell.test.tsx index 76765b06b..e37097a1a 100644 --- a/react-app/src/components/shell.test.tsx +++ b/react-app/src/components/shell.test.tsx @@ -37,7 +37,7 @@ describe('app shell', () => { await screen.findByTestId('feed-page'); await userEvent.click(screen.getByRole('link', { name: 'show' })); expect(router.state.location.pathname).toBe('/show/1'); - expect(await screen.findByTestId('feed-page')).toHaveTextContent('show page 1'); + await screen.findByTestId('feed-page'); expect(screen.getByRole('link', { name: 'show' })).toHaveClass('active'); expect(screen.getByRole('link', { name: 'new' })).not.toHaveClass('active'); }); From 84468b7793f8425e0116da5a64e05a8fe21ce46b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:40:15 +0000 Subject: [PATCH 4/6] bug: scope header styles under #header so .name/.left don't leak into feed rows Co-Authored-By: Matthew Guerra --- react-app/src/components/Header/Header.scss | 202 ++++++++++---------- 1 file changed, 102 insertions(+), 100 deletions(-) diff --git a/react-app/src/components/Header/Header.scss b/react-app/src/components/Header/Header.scss index 8c392180d..2dd50da00 100644 --- a/react-app/src/components/Header/Header.scss +++ b/react-app/src/components/Header/Header.scss @@ -18,139 +18,141 @@ a { display: inline; } -} - -.home-link { - width: 50px; - height: 66px; -} -.logo-inner { - width: 32px; - position: absolute; - left: 17px; - top: 18px; - z-index: -1; - height: 32px; - border-radius: 50%; + // Scoped: React has no Angular view encapsulation, and feed rows also use .name/.left etc. - @media #{$mobile-only} { - left: 16px; - top: 12px; + .home-link { + width: 50px; + height: 66px; } -} -.logo { - width: 50px; - padding: 3px 8px 0; + .logo-inner { + width: 32px; + position: absolute; + left: 17px; + top: 18px; + z-index: -1; + height: 32px; + border-radius: 50%; - @media #{$mobile-only} { - width: 45px; - padding: 0 0 0 10px; + @media #{$mobile-only} { + left: 16px; + top: 12px; + } } -} -h1 { - font-weight: normal; - display: inline-block; - vertical-align:middle; - margin: 0; - font-size: 16px; + .logo { + width: 50px; + padding: 3px 8px 0; - a { - color: #fff; - text-decoration: none; + @media #{$mobile-only} { + width: 45px; + padding: 0 0 0 10px; + } } -} -.name { - margin-right: 30px; - margin-bottom: 2px; + h1 { + font-weight: normal; + display: inline-block; + vertical-align:middle; + margin: 0; + font-size: 16px; - @media #{$mobile-only} { - display: none; + a { + color: #fff; + text-decoration: none; + } } -} -.header-text { - position: absolute; - width: inherit; - height: 20px; - left: 10px; - top: 27px; - z-index: -1; + .name { + margin-right: 30px; + margin-bottom: 2px; - @media #{$mobile-only} { - top: 22px; + @media #{$mobile-only} { + display: none; + } } -} -.left { - position: absolute; - left: 60px; - font-size: 16px; + .header-text { + position: absolute; + width: inherit; + height: 20px; + left: 10px; + top: 27px; + z-index: -1; - @media #{$mobile-only} { - width: 100%; - left: 0; + @media #{$mobile-only} { + top: 22px; + } } -} -.header-nav { - display: inline-block; - margin-left: 20px; + .left { + position: absolute; + left: 60px; + font-size: 16px; - @media #{$mobile-only} { - margin-left: 60px; + @media #{$mobile-only} { + width: 100%; + left: 0; + } } - a { - color: hsla(0,0%,100%,.9); - text-decoration: none; - margin: 0 5px; - letter-spacing: 1.8px; + .header-nav { + display: inline-block; + margin-left: 20px; - &:hover { - color: #fff; + @media #{$mobile-only} { + margin-left: 60px; } - } - .active { - color: #fff; - } -} + a { + color: hsla(0,0%,100%,.9); + text-decoration: none; + margin: 0 5px; + letter-spacing: 1.8px; -.info { - position: absolute; - top: 0; - right: 20px; - height: 100%; + &:hover { + color: #fff; + } + } - @media #{$mobile-only} { - right: 10px; + .active { + color: #fff; + } } - img { - opacity: 0.8; - width: 25px; - margin-top: 21.5px; - display: block; + .info { + position: absolute; + top: 0; + right: 20px; + height: 100%; - &:hover { - opacity: 1; - cursor: pointer; + @media #{$mobile-only} { + right: 10px; } - @media #{$mobile-only} { - margin-top: 15px; + img { + opacity: 0.8; + width: 25px; + margin-top: 21.5px; + display: block; + + &:hover { + opacity: 1; + cursor: pointer; + } + + @media #{$mobile-only} { + margin-top: 15px; + } } } -} -.settings-button { - padding: 0; - border: 0; - background: none; - cursor: pointer; - font: inherit; + .settings-button { + padding: 0; + border: 0; + background: none; + cursor: pointer; + font: inherit; + } } From 75f43649da0195a07612e097df4deadd1875063a Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:53:04 +0000 Subject: [PATCH 5/6] bug: re-trigger GitHub Actions CI stuck in runner backlog Co-Authored-By: Matthew Guerra From 67070f4b456a8378308cda5e89314ae0441a7edb Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:55:44 +0000 Subject: [PATCH 6/6] bug: assert GA hits are pageviews in the shell test Co-Authored-By: Matthew Guerra --- react-app/src/components/shell.test.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/react-app/src/components/shell.test.tsx b/react-app/src/components/shell.test.tsx index e37097a1a..001760d0a 100644 --- a/react-app/src/components/shell.test.tsx +++ b/react-app/src/components/shell.test.tsx @@ -75,6 +75,9 @@ describe('app shell', () => { await screen.findByTestId('item-page'); expect(ga).toHaveBeenCalledWith('set', 'page', '/news/1'); expect(ga).toHaveBeenCalledWith('set', 'page', '/item/1'); - expect(ga.mock.calls.filter(([cmd]) => cmd === 'send')).toHaveLength(2); + expect(ga.mock.calls.filter(([cmd]) => cmd === 'send')).toEqual([ + ['send', 'pageview'], + ['send', 'pageview'], + ]); }); });