progmaweb
The site and account service of Progmasoft: a Next.js frontend and an ASP.NET Core API.
Clonegit clone https://git.progmasoft.com/progmaweb
Show the most important article large and the others in a sideways rail
- Commit
51d2052d6170646310767bd831a02b8f7c939638- Author
- Leitwolf11 ·
- Parents
5968b8155b8c
Changes
apps/web/app/news/news.css | 81 +++++++++++++++++++++++--- apps/web/app/news/page.tsx | 83 +++++++++++++++----------- apps/web/components/site/NewsRail.tsx | 106 ++++++++++++++++++++++++++++++++++ apps/web/lib/news.ts | 28 +++++++++ apps/web/tests/news.test.mjs | 20 +++++++ 5 files changed, 274 insertions(+), 44 deletions(-) diff --git a/apps/web/app/news/news.css b/apps/web/app/news/news.css index 8c129eb..4837cde 100644 --- a/apps/web/app/news/news.css +++ b/apps/web/app/news/news.css @@ -81,13 +81,82 @@ padding-block: 24px clamp(72px, 9vw, 120px); } -.pm-news-list ul { +/* The rail: cards in one row that scrolls sideways and stops on each card. */ +.pm-news-rail-head { + display: flex; + align-items: end; + justify-content: space-between; + gap: 16px; + margin-bottom: 18px; +} + +.pm-news-rail-head h2 { + margin: 0; + font-size: clamp(28px, 3vw, 40px); + font-weight: 400; + letter-spacing: -0.02em; +} + +.pm-news-rail-buttons { + display: flex; + gap: 8px; +} + +.pm-news-rail-buttons button { display: grid; - grid-template-columns: repeat(2, minmax(0, 1fr)); + place-items: center; + width: 44px; + height: 44px; + border: 1px solid var(--home-rule); + border-radius: 999px; + background: var(--home-card); + color: var(--home-ink); + cursor: pointer; + transition: + background 200ms var(--ease), + opacity 200ms var(--ease); +} + +.pm-news-rail-buttons button:hover:not(:disabled) { + background: var(--home-ink); + color: var(--home-paper); +} + +.pm-news-rail-buttons button:disabled { + opacity: 0.35; + cursor: default; +} + +.pm-news-rail-buttons svg { + width: 20px; + height: 20px; + fill: none; + stroke: currentcolor; + stroke-width: 2; + stroke-linecap: round; + stroke-linejoin: round; +} + +.pm-news-rail-track { + display: grid; + grid-auto-columns: min(440px, 86%); + grid-auto-flow: column; gap: 16px; margin: 0; - padding: 0; + padding: 0 0 8px; list-style: none; + overflow-x: auto; + overscroll-behavior-x: contain; + scroll-snap-type: x mandatory; + scrollbar-width: none; +} + +.pm-news-rail-track::-webkit-scrollbar { + display: none; +} + +.pm-news-rail-track > li { + scroll-snap-align: start; } .pm-news-list a { @@ -171,9 +240,3 @@ .pm-article-back a { color: var(--home-soft); } - -@media (width <= 760px) { - .pm-news-list ul { - grid-template-columns: 1fr; - } -} diff --git a/apps/web/app/news/page.tsx b/apps/web/app/news/page.tsx index 8435ace..8470f9e 100644 --- a/apps/web/app/news/page.tsx +++ b/apps/web/app/news/page.tsx @@ -9,7 +9,14 @@ import { Flow } from "@/components/site/Flow"; import { Reveal } from "@/components/site/Reveal"; import { accentField, accentStyle } from "@/lib/brand-colours"; import { getLocale } from "@/lib/locale.server"; -import { articles, articleUrl, getNewsMessages, articleText } from "@/lib/news"; +import { NewsRail } from "@/components/site/NewsRail"; +import { + articleText, + articleUrl, + getNewsMessages, + leadArticle, + sideArticles, +} from "@/lib/news"; import { productFacts } from "@/lib/products"; export async function generateMetadata(): Promise<Metadata> { @@ -22,13 +29,15 @@ export async function generateMetadata(): Promise<Metadata> { } /** - * news.progmasoft.com: the newest article large, over a field in the colour - * of its product, then every other article as a card. + * news.progmasoft.com: the article that matters most large, over a field in + * the colour of its product, then the other articles in a rail that scrolls + * sideways. */ export default async function NewsPage() { const locale = await getLocale(); const news = getNewsMessages(locale); - const [first, ...rest] = articles; + const first = leadArticle(); + const rest = sideArticles(); return ( <div className="pm-page pm-home pm-news-site"> <SiteHeader locale={locale} /> @@ -61,37 +70,41 @@ export default async function NewsPage() { </section> ) : null} - <section className="pm-shell pm-news-list" aria-label={news.latest}> - <ul> - {rest.map((article, index) => ( - <li - key={article.slug} - data-reveal - style={{ "--i": index } as React.CSSProperties} - > - <a href={articleUrl(article)}> - <span className="pm-news-meta"> - <span - className="pm-chip pm-live-accent" - style={accentStyle(productFacts(article.product).accent)} - aria-hidden="true" - /> - <span>{productFacts(article.product).name}</span> - <time dateTime={article.date}> - {formatDay(locale, article.date)} - </time> - </span> - <strong className="pm-serif"> - {articleText(article, locale).title} - </strong> - <span className="pm-news-text"> - {articleText(article, locale).summary} - </span> - </a> - </li> - ))} - </ul> - </section> + {rest.length > 0 ? ( + <section className="pm-shell pm-news-list" data-reveal> + <NewsRail + label={news.latest} + previous={news.previous} + next={news.next} + > + {rest.map((article) => ( + <li key={article.slug}> + <a href={articleUrl(article)}> + <span className="pm-news-meta"> + <span + className="pm-chip pm-live-accent" + style={accentStyle( + productFacts(article.product).accent, + )} + aria-hidden="true" + /> + <span>{productFacts(article.product).name}</span> + <time dateTime={article.date}> + {formatDay(locale, article.date)} + </time> + </span> + <strong className="pm-serif"> + {articleText(article, locale).title} + </strong> + <span className="pm-news-text"> + {articleText(article, locale).summary} + </span> + </a> + </li> + ))} + </NewsRail> + </section> + ) : null} </main> <Footer locale={locale} /> </div> diff --git a/apps/web/components/site/NewsRail.tsx b/apps/web/components/site/NewsRail.tsx new file mode 100644 index 0000000..63c8835 --- /dev/null +++ b/apps/web/components/site/NewsRail.tsx @@ -0,0 +1,106 @@ +// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com> +// SPDX-License-Identifier: AGPL-3.0-or-later + +"use client"; + +import { + useCallback, + useEffect, + useRef, + useState, + type ReactNode, +} from "react"; + +interface NewsRailProps { + /** The name of the rail for assistive technology, such as "Latest news". */ + label: string; + /** The labels of the two buttons. */ + previous: string; + next: string; + children: ReactNode; +} + +/** + * A row of article cards that scrolls sideways: by swiping or with a wheel or a + * trackpad, card by card, and with two buttons that move one card at a time + * and turn off at either end; when every card fits, there are no buttons. + * Without script the row still scrolls. + */ +export function NewsRail({ label, previous, next, children }: NewsRailProps) { + const track = useRef<HTMLUListElement>(null); + const [atStart, setAtStart] = useState(true); + const [atEnd, setAtEnd] = useState(true); + + const measure = useCallback(() => { + const element = track.current; + if (!element) return; + const max = element.scrollWidth - element.clientWidth; + // The direction of a right-to-left page makes scrollLeft negative. + const position = Math.abs(element.scrollLeft); + setAtStart(position <= 2); + setAtEnd(position >= max - 2); + }, []); + + useEffect(() => { + const element = track.current; + if (!element) return; + measure(); + element.addEventListener("scroll", measure, { passive: true }); + const resize = new ResizeObserver(measure); + resize.observe(element); + return () => { + element.removeEventListener("scroll", measure); + resize.disconnect(); + }; + }, [measure]); + + const move = (direction: 1 | -1) => { + const element = track.current; + const card = element?.firstElementChild as HTMLElement | null; + if (!element || !card) return; + const gap = Number.parseFloat(getComputedStyle(element).columnGap) || 0; + const rtl = getComputedStyle(element).direction === "rtl" ? -1 : 1; + const reduce = window.matchMedia( + "(prefers-reduced-motion: reduce)", + ).matches; + element.scrollBy({ + left: direction * rtl * (card.offsetWidth + gap), + behavior: reduce ? "auto" : "smooth", + }); + }; + + return ( + <div className="pm-news-rail"> + <div className="pm-news-rail-head"> + <h2 className="pm-serif">{label}</h2> + {atStart && atEnd ? null : ( + <div className="pm-news-rail-buttons"> + <button + type="button" + aria-label={previous} + disabled={atStart} + onClick={() => move(-1)} + > + <svg viewBox="0 0 24 24" aria-hidden="true"> + <path d="M15 5l-7 7 7 7" /> + </svg> + </button> + <button + type="button" + aria-label={next} + disabled={atEnd} + onClick={() => move(1)} + > + <svg viewBox="0 0 24 24" aria-hidden="true"> + <path d="M9 5l7 7-7 7" /> + </svg> + </button> + </div> + )} + </div> + <ul className="pm-news-rail-track" ref={track} aria-label={label}> + {children} + </ul> + </div> + ); +} diff --git a/apps/web/lib/news.ts b/apps/web/lib/news.ts index a78ac8f..4139f8e 100644 --- a/apps/web/lib/news.ts +++ b/apps/web/lib/news.ts @@ -16,6 +16,11 @@ interface ArticleSource { product: ProductSlug; /** The release the article announces, when it announces one. */ release?: string; + /** + * Set on the article that matters most: news.progmasoft.com shows it large + * above the others. Of several, the newest; of none, the newest article. + */ + lead?: true; text: Record<Locale, ArticleText>; } @@ -40,6 +45,7 @@ const sources: ArticleSource[] = [ { date: "2026-11-27", product: "tazel", + lead: true, release: "0.2.0", text: { "en-US": { @@ -185,6 +191,17 @@ export const articles: Article[] = sources .map((source) => ({ ...source, slug: slugOf(source.text["en-US"].title) })) .sort((a, b) => b.date.localeCompare(a.date)); +/** The article news.progmasoft.com shows large: the newest one marked lead, or else the newest. */ +export function leadArticle(): Article | undefined { + return articles.find((article) => article.lead) ?? articles[0]; +} + +/** Every article but the lead, newest first: the rail under it. */ +export function sideArticles(): Article[] { + const lead = leadArticle(); + return articles.filter((article) => article !== lead); +} + export function findArticle(slug: string): Article | undefined { return articles.find((article) => article.slug === slug); } @@ -205,6 +222,9 @@ interface NewsMessages { title: string; description: string; latest: string; + /** The buttons of the rail of articles. */ + previous: string; + next: string; back: string; notes: string; product: string; @@ -216,6 +236,8 @@ const newsMessages: Record<Locale, NewsMessages> = { title: "News", description: "Releases and announcements from Progmasoft.", latest: "Latest news", + previous: "Previous articles", + next: "Next articles", back: "All news", notes: "Release notes", product: "About {name}", @@ -225,6 +247,8 @@ const newsMessages: Record<Locale, NewsMessages> = { title: "Neuigkeiten", description: "Versionen und Ankündigungen von Progmasoft.", latest: "Neueste Meldungen", + previous: "Vorherige Meldungen", + next: "Nächste Meldungen", back: "Alle Neuigkeiten", notes: "Versionshinweise", product: "Über {name}", @@ -234,6 +258,8 @@ const newsMessages: Record<Locale, NewsMessages> = { title: "Новости", description: "Выпуски и объявления Progmasoft.", latest: "Последние новости", + previous: "Предыдущие новости", + next: "Следующие новости", back: "Все новости", notes: "Примечания к выпуску", product: "О {name}", @@ -243,6 +269,8 @@ const newsMessages: Record<Locale, NewsMessages> = { title: "Actualités", description: "Versions et annonces de Progmasoft.", latest: "Dernières actualités", + previous: "Actualités précédentes", + next: "Actualités suivantes", back: "Toutes les actualités", notes: "Notes de version", product: "À propos de {name}", diff --git a/apps/web/tests/news.test.mjs b/apps/web/tests/news.test.mjs index 280f87c..888559d 100644 --- a/apps/web/tests/news.test.mjs +++ b/apps/web/tests/news.test.mjs @@ -73,3 +73,23 @@ test("news.progmasoft.com serves the list and each article", () => { expect(newsRoute("/Tazel")).toBe(null); expect(findArticle(first.slug)).toBe(first); }); + +test("the lead is the newest article marked lead, and the rail holds the rest", async () => { + const { leadArticle, sideArticles } = await import("../lib/news.ts"); + const lead = leadArticle(); + const marked = articles.filter((article) => article.lead); + expect(lead).toBe(marked.length > 0 ? marked[0] : articles[0]); + const side = sideArticles(); + expect(side).not.toContain(lead); + expect(side.length).toBe(articles.length - 1); + expect([...side].sort((a, b) => b.date.localeCompare(a.date))).toEqual(side); +}); + +test("the rail's buttons are named in every language", () => { + for (const locale of supportedLocales) { + const news = getNewsMessages(locale); + expect(news.previous.length).toBeGreaterThan(0); + expect(news.next.length).toBeGreaterThan(0); + expect(news.previous).not.toBe(news.next); + } +});