diff --git a/apps/public-feature-board/src/components/common/navbar.tsx b/apps/public-feature-board/src/components/common/navbar.tsx index d1b618914..5b18d09cd 100644 --- a/apps/public-feature-board/src/components/common/navbar.tsx +++ b/apps/public-feature-board/src/components/common/navbar.tsx @@ -11,9 +11,24 @@ import { useSite } from "../../providers/site-provider"; import { LocaleSwitcher } from "./locale-switcher"; import { UserMenu } from "./user-menu"; -export function Navbar() { +export function Navbar({ + hasHelpCenterArticles, +}: { + /** + * Whether the help center has a page to open. + * + * The site's visibility switch alone is not enough: a public help center the + * workspace has not written anything into would get a tab that opens "No + * documentation yet". The embedded widget already hides its Help tab on the + * same condition, so the two surfaces agree about what exists. + */ + hasHelpCenterArticles: boolean; +}) { const site = useSite(); + const showHelpTab = + site.helpCenterVisibility === "PUBLIC" && hasHelpCenterArticles; + return (
) : null} - {site.helpCenterVisibility === "PUBLIC" ? ( + {showHelpTab ? ( ) : null} @@ -71,7 +86,7 @@ export function Navbar() { label={m.strong_loved_flamingo()} /> ) : null} - {site.helpCenterVisibility === "PUBLIC" ? ( + {showHelpTab ? ( ) : null} diff --git a/apps/public-feature-board/src/components/layout/public-board-shell.tsx b/apps/public-feature-board/src/components/layout/public-board-shell.tsx index 16a180ec6..8bf2dc3a9 100644 --- a/apps/public-feature-board/src/components/layout/public-board-shell.tsx +++ b/apps/public-feature-board/src/components/layout/public-board-shell.tsx @@ -22,7 +22,20 @@ import { useSite } from "../../providers/site-provider"; import { Navbar } from "../common/navbar"; import { PoweredByTag } from "./powered-by-tag"; -export function PublicBoardShell({ children }: { children: ReactNode }) { +export function PublicBoardShell({ + children, + hasHelpCenterArticles, +}: { + children: ReactNode; + /** + * Whether the board has help articles to open. + * + * Passed in rather than read here because it is a server-resolved fact about + * the workspace, like the site row: the shell renders the chrome for every + * board page and must not spend a request of its own on a tab. + */ + hasHelpCenterArticles: boolean; +}) { const site = useSite(); const authDialogStore = useAuthDialogContext(); const publicCollections = usePublicCollections(); @@ -107,7 +120,7 @@ export function PublicBoardShell({ children }: { children: ReactNode }) { className="bg-background text-foreground flex h-dvh flex-col overflow-hidden" data-board-shell="" > - +
{children}
diff --git a/apps/web/src/dashboard/features/help-center/components/help-center-section-page.tsx b/apps/web/src/dashboard/features/help-center/components/help-center-section-page.tsx index 775d3584a..973af2080 100644 --- a/apps/web/src/dashboard/features/help-center/components/help-center-section-page.tsx +++ b/apps/web/src/dashboard/features/help-center/components/help-center-section-page.tsx @@ -31,11 +31,17 @@ import { Plus, } from "@hugeicons/core-free-icons"; import { HugeiconsIcon } from "@hugeicons/react"; -import { and, eq, useLiveQuery } from "@tanstack/react-db"; +import { + and, + eq, + useLiveInfiniteQuery, + useLiveQuery, +} from "@tanstack/react-db"; import { Link, useNavigate } from "@tanstack/react-router"; import { useState } from "react"; import { m } from "@/paraglide/messages.js"; +import { HELP_CENTER_SECTION_ARTICLE_PAGE_SIZE } from "~/lib/collections"; import { useDashboardCollections } from "~/providers/dashboard-collections-provider"; import { HelpCenterArticleListView } from "./help-center-article-list-view"; @@ -101,14 +107,8 @@ export function HelpCenterSectionPage({ .orderBy(({ topic }) => topic.name, "asc"), }); - const articlesQuery = useLiveQuery({ - queryKey: [ - "help-center-section-articles", - topicArticles.id, - organizationId, - topicId, - ], - query: (q) => + const articlesQuery = useLiveInfiniteQuery( + (q) => q .from({ article: topicArticles }) .where(({ article }) => @@ -117,8 +117,21 @@ export function HelpCenterSectionPage({ eq(article.topicId, topicId) ) ) - .orderBy(({ article }) => article.updatedAt, "desc"), - }); + // The order the collection's `sort: "updated"` asks the server for. A + // window cut from one order and rendered in another would show rows the + // page after it also shows. + .orderBy(({ article }) => article.updatedAt, "desc") + .orderBy(({ article }) => article.id, "asc"), + { + pageSize: HELP_CENTER_SECTION_ARTICLE_PAGE_SIZE, + queryKey: [ + "help-center-section-articles", + topicArticles.id, + organizationId, + topicId, + ], + } + ); const topics = topicsQuery.data ?? []; @@ -363,10 +376,34 @@ export function HelpCenterSectionPage({ ) : null} ) : ( - + <> + + {articlesQuery.hasNextPage ? ( +
+ {/* A failed page load leaves the rows already on screen: the + load is additive, so the list stays and the control below + becomes the retry. */} + {articlesQuery.isSyncError ? ( +

+ {m.trite_aloof_lemming_prosper()} +

+ ) : null} + +
+ ) : null} + )} diff --git a/apps/web/src/dashboard/lib/collections.ts b/apps/web/src/dashboard/lib/collections.ts index 59f0dce5b..543a6f213 100644 --- a/apps/web/src/dashboard/lib/collections.ts +++ b/apps/web/src/dashboard/lib/collections.ts @@ -715,6 +715,16 @@ export function helpCenterArticlesQueryKey( return organizationScopedKey(organizationId, "help-center-article"); } +/** + * How many articles one section page loads at a time. + * + * The live query asks the server for one more than this — the peek row that + * says whether there is another page — and hides it. `Load more` widens the + * window rather than fetching after a cursor, so the request grows by this much + * per page; the list's own ceiling is what stops it. + */ +export const HELP_CENTER_SECTION_ARTICLE_PAGE_SIZE = 25; + /** * The query key for one section's articles. * @@ -722,6 +732,11 @@ export function helpCenterArticlesQueryKey( * name the same rows, so the key is derived here rather than spelled twice. A * drift between the two would leave the section page showing the article as it * was before the save. + * + * It is the section's prefix, not a page: the on-demand collection appends the + * `LoadSubsetOptions` it is asked for (the window and the filters) to this key, + * which is what gives each page its own cache entry while the editor can still + * invalidate every page of a section by its prefix. */ export function helpCenterArticleTopicQueryKey( organizationId: string | undefined, @@ -736,14 +751,19 @@ export function helpCenterArticleTopicQueryKey( } /** - * One section's articles. + * One section's articles, one page at a time. * * A section page lists one topic, and the workspace-wide * `helpCenterArticleCollection` stays for `useWorkspaceUsage` only. Scoping the * collection by topic is what lets the editor invalidate exactly the lists a * write could have changed, including both lists when an article moves - * sections. The operation filters by `topicId` on the server; the live query - * keeps its predicate as a second guard. + * sections. + * + * `on-demand` because the page asks for a window: the live query passes its + * `offset`/`limit` down to `queryFn`, and the server returns that page in the + * order `sort: "updated"` names. The section page must order by the same two + * columns the repository sorts by, or a window would be cut from one order and + * rendered in another. */ export function helpCenterTopicArticleCollection( scope: DashboardCollectionScope, @@ -758,8 +778,7 @@ export function helpCenterTopicArticleCollection( queryCollectionOptions({ id, queryClient: client.requireDependency("queryClient"), - queryKey: () => - helpCenterArticleTopicQueryKey(scope.organizationId, topicId), + queryKey: helpCenterArticleTopicQueryKey(scope.organizationId, topicId), queryFn: async (ctx) => { const organizationId = scope.organizationId; @@ -767,18 +786,38 @@ export function helpCenterTopicArticleCollection( return []; } - // The list operation filters by workspace and optionally one section; - // the section's live query keeps its predicate as a second guard, but - // the rows never leave the server. The workspace-wide collection stays - // for the plan-usage meter. + const window = ctx.meta?.loadSubsetOptions; + + // The page windows every read, and the operation refuses a + // section-scoped list without one: a demand that named no window would + // ask the server for the whole section, which is the read this + // collection exists to avoid. It fails there rather than quietly + // returning a page a windowless demander would take as complete. + // + // The list operation filters by workspace and section on the server; + // the live query keeps its predicate as a second guard. The + // workspace-wide collection stays for the plan-usage meter, which is + // the one caller allowed to read without a window. const data = await fetchRpc( - (rpc) => rpc.ListHelpCenterArticles({ organizationId, topicId }), + (rpc) => + rpc.ListHelpCenterArticles({ + organizationId, + sort: "updated", + topicId, + ...(window?.limit === undefined + ? undefined + : { limit: window.limit }), + ...(window?.offset === undefined + ? undefined + : { offset: window.offset }), + }), { signal: ctx.signal } ); return [...data]; }, getKey: (item) => item.id, + syncMode: "on-demand", }) ); } diff --git a/apps/web/src/dashboard/lib/preloads.ts b/apps/web/src/dashboard/lib/preloads.ts index 06fcd4461..c96be4126 100644 --- a/apps/web/src/dashboard/lib/preloads.ts +++ b/apps/web/src/dashboard/lib/preloads.ts @@ -167,12 +167,19 @@ export async function preloadHelpCenter(): Promise { await dashboardCollections.helpCenterTopicCollection.preload(); } -/** One section: its own row plus the articles it lists. */ -export async function preloadHelpCenterSection(topicId: string): Promise { - await Promise.all([ - dashboardCollections.helpCenterTopicCollection.preload(), - dashboardCollections.helpCenterTopicArticleCollection(topicId).preload(), - ]); +/** + * One section: its own row, which the header renders. + * + * The articles are deliberately not preloaded. The section page reads them + * through an on-demand collection, whose only load is the window the page's + * live query subscribes to — preloading the collection starts no load at all + * (on-demand collections have no full-source read), and forcing one would ask + * the server for every article in the section, which is the read the window + * exists to avoid. The first page therefore arrives after hydration, in the + * list's own skeleton, rather than with the server-rendered document. + */ +export async function preloadHelpCenterSection(): Promise { + await dashboardCollections.helpCenterTopicCollection.preload(); } /** The help center editor: the topic it can be moved into. */ diff --git a/apps/web/src/lib/public-board-data.ts b/apps/web/src/lib/public-board-data.ts index b56b53380..2016063be 100644 --- a/apps/web/src/lib/public-board-data.ts +++ b/apps/web/src/lib/public-board-data.ts @@ -41,6 +41,15 @@ export type PublicBoardPage = readonly post: TPost | null; readonly changelog: TChangelog | null; readonly helpArticle: THelpCenterArticlePublic | null; + /** + * Whether the workspace has an article a reader can open. + * + * The navbar draws its Help tab from this: a public help center with + * nothing in it is a tab that opens "No documentation yet", which is the + * rule the embedded widget already follows. Resolved with the document so + * the tab cannot appear and then vanish on hydration. + */ + readonly hasHelpCenterArticles: boolean; readonly canonicalUrl: string; readonly siteUrl: string; readonly ogImageUrl: string; @@ -202,6 +211,47 @@ export async function resolvePageContent( } } +/** + * How long the Help tab's existence read may add to a board document. + * + * The navbar draws the tab before the page settles, so this read is a + * decoration on a document that already has its own work to do: a slow or hung + * answer must not hold the response past the board's latency budget. It runs + * beside `resolvePageContent`, which is why the deadline is generous relative + * to a single indexed lookup. + */ +const HELP_CENTER_AVAILABILITY_TIMEOUT_MS = 1500; + +/** + * Whether the board's Help tab has a page behind it. + * + * One existence read, asked only when the help center is public at all (the tab + * is not drawn otherwise). The read carries its own deadline and abort signal, + * so a hung request is cancelled rather than awaited. A failure answers + * `true`: the flag is cosmetic, and hiding a working help center because one + * boolean could not be read is worse than showing a tab whose page can explain + * itself. + */ +async function resolveHasHelpCenterArticles(site: TSite): Promise { + if (site.helpCenterVisibility !== "PUBLIC") { + return false; + } + + try { + const availability = await fetchRpcServer( + (rpc) => + rpc.GetHelpCenterAvailabilityPublic({ + organizationId: site.organizationId, + }), + { signal: AbortSignal.timeout(HELP_CENTER_AVAILABILITY_TIMEOUT_MS) } + ); + + return availability.hasArticles; + } catch { + return true; + } +} + /** * The dashboard origin to send a lost visitor to. * @@ -265,7 +315,13 @@ export const getPublicBoardPage = createServerFn({ method: "GET" }) return notFound(null, subdomain); } - const detail = await resolvePageContent(url.pathname, site); + // Resolved together: the tab's flag is a second, independent read, and + // stacking it behind the page's content would add a round trip to every + // board page for a boolean the navbar draws before the page settles. + const [detail, hasHelpCenterArticles] = await Promise.all([ + resolvePageContent(url.pathname, site), + resolveHasHelpCenterArticles(site), + ]); if (detail.kind !== "found") { return detail.kind === "not-found" @@ -288,6 +344,7 @@ export const getPublicBoardPage = createServerFn({ method: "GET" }) post: detail.post, changelog: detail.changelog, helpArticle: detail.helpArticle, + hasHelpCenterArticles, canonicalUrl: new URL(url.pathname, url.origin).toString(), siteUrl: new URL("/", url.origin).toString(), ogImageUrl, diff --git a/apps/web/src/portal/help-center/content.test.ts b/apps/web/src/portal/help-center/content.test.ts index 8e736e189..e150f5e57 100644 --- a/apps/web/src/portal/help-center/content.test.ts +++ b/apps/web/src/portal/help-center/content.test.ts @@ -165,8 +165,20 @@ describe("formatHelpDate", () => { it("renders one date for both a Date and an ISO string", () => { const value = new Date("2026-03-04T00:00:00.000Z"); - expect(formatHelpDate(value)).toBe(formatHelpDate(value.toISOString())); - expect(formatHelpDate(value)).toContain("2026"); + expect(formatHelpDate(value, "en")).toBe( + formatHelpDate(value.toISOString(), "en") + ); + expect(formatHelpDate(value, "en")).toContain("2026"); + }); + + it("formats in the locale it is given", () => { + const value = new Date("2026-03-04T00:00:00.000Z"); + + // The month name is the part a reader sees translated; the day and year + // are digits in every catalog. + expect(formatHelpDate(value, "de")).toMatch(/März|M\./); + expect(formatHelpDate(value, "fr")).toMatch(/mars/); + expect(formatHelpDate(value, "en")).toMatch(/Mar/); }); }); diff --git a/apps/web/src/portal/help-center/content.ts b/apps/web/src/portal/help-center/content.ts index bd6bd9b7e..fbcc22de9 100644 --- a/apps/web/src/portal/help-center/content.ts +++ b/apps/web/src/portal/help-center/content.ts @@ -49,9 +49,12 @@ export type HelpCenterNavSection = { export function buildHelpCenterSections({ topics, articles, + unlistedName = "More articles", }: { readonly topics: ReadonlyArray; readonly articles: ReadonlyArray; + /** The localized label for the bucket of articles whose topic is not listed. */ + readonly unlistedName?: string | undefined; }): ReadonlyArray { const byTopic = new Map(); @@ -85,7 +88,7 @@ export function buildHelpCenterSections({ icon: null, isTopic: false, key: UNLISTED_SECTION_KEY, - name: "More articles", + name: unlistedName, }); } @@ -181,21 +184,48 @@ export function readingMinutes(content: string): number { } /** - * One formatter for every date on the page. + * The date style the page shows. * - * `toLocaleDateString()` with an options object builds a fresh - * `Intl.DateTimeFormat` per call, and an article page renders a date at least - * once. Hoisted so the work happens once per module load rather than once per - * render. + * The locale is not this module's to choose: the page renders in the reader's + * Paraglide locale, and a formatter created without one falls back to the host's + * default (`en-US` on a server, the browser's language on the client), which + * would print a different month and order than the copy around it. */ -const DATE_FORMAT = new Intl.DateTimeFormat(undefined, { +const DATE_FORMAT_OPTIONS: Intl.DateTimeFormatOptions = { day: "numeric", month: "short", year: "numeric", -}); +}; + +/** + * One formatter per locale, built on first use. + * + * `toLocaleDateString()` with an options object, and a formatter created per + * call, both rebuild the `Intl.DateTimeFormat`; an article page formats a date + * at least once per render. The map keeps one per locale — across a locale + * switch the reader gets a second formatter, not a new one per render — and the + * number of locales is bounded by the catalog. + */ +const DATE_FORMATS = new Map(); + +const dateFormatFor = (locale: string): Intl.DateTimeFormat => { + const existing = DATE_FORMATS.get(locale); + + if (existing !== undefined) { + return existing; + } + + const created = new Intl.DateTimeFormat(locale, DATE_FORMAT_OPTIONS); + + DATE_FORMATS.set(locale, created); + + return created; +}; -export function formatHelpDate(value: Date | string): string { - return DATE_FORMAT.format(value instanceof Date ? value : new Date(value)); +export function formatHelpDate(value: Date | string, locale: string): string { + return dateFormatFor(locale).format( + value instanceof Date ? value : new Date(value) + ); } /** diff --git a/apps/web/src/portal/help-center/help-center-article-actions.tsx b/apps/web/src/portal/help-center/help-center-article-actions.tsx index 51e925e43..50b6037bb 100644 --- a/apps/web/src/portal/help-center/help-center-article-actions.tsx +++ b/apps/web/src/portal/help-center/help-center-article-actions.tsx @@ -40,6 +40,7 @@ import { helpCenterMcpServerId, renderHelpCenterArticleMarkdown, } from "@/lib/help-center-agent"; +import { m } from "@/paraglide/messages.js"; /** * The article's actions, in the shape Blume gives a documentation page: a @@ -98,9 +99,7 @@ const CHAT_PROVIDERS = [ type MenuIcon = ComponentProps["icon"]; const PROMPT = (markdownUrl: string, title: string) => - encodeURIComponent( - `Read ${markdownUrl} so I can ask you questions about "${title}".` - ); + encodeURIComponent(m.active_salty_termite_stop({ title, url: markdownUrl })); /** Cursor's documented install deeplink carries a base64 JSON config. */ const cursorInstallUrl = (name: string, url: string) => { @@ -145,8 +144,8 @@ const notifyCopied = (title: string) => { const notifyCopyFailed = () => { toastManager.add({ - description: "Your browser did not allow the write.", - title: "Copy failed", + description: m.bald_level_koala_charm(), + title: m.lazy_lucky_puma_dig(), type: "error", }); }; @@ -219,7 +218,7 @@ function useMarkdownCopy(article: THelpCenterArticlePublic) { try { await writeClipboard(article.content); setCopied(true); - notifyCopied("Markdown copied"); + notifyCopied(m.formal_tame_carp_explore()); } catch { notifyCopyFailed(); } @@ -284,7 +283,9 @@ function CopyRow({ className="size-4 shrink-0" icon={copied ? Tick02Icon : Copy01Icon} /> - {copied ? "Copied" : "Copy as Markdown"} + + {copied ? m.least_sour_badger_quell() : m.less_true_ray_propel()} + ); } @@ -295,14 +296,14 @@ function ExportMenu({ readonly article: THelpCenterArticlePublic; }) { return ( - + downloadMarkdown(article)}> - Download Markdown + {m.deft_drab_gull_win()} window.print()}> - Print / Save as PDF + {m.grassy_pretty_blackbird_adore()} ); @@ -316,7 +317,7 @@ function ChatMenu({ readonly title: string; }) { return ( - + {CHAT_PROVIDERS.map((provider) => ( string) => { - void copyText(build(currentMcpUrl()), "Command copied"); + void copyText(build(currentMcpUrl()), m.kind_maroon_chipmunk_strive()); }; return ( - + { - void copyText(currentMcpUrl(), "MCP server URL copied"); + void copyText(currentMcpUrl(), m.tangy_fit_haddock_revive()); }} > - Copy server URL + {m.long_moving_dog_fall()} - Copy Claude Code command + {m.least_elegant_raven_achieve()} @@ -368,7 +373,7 @@ function McpMenu({ mcpName }: { readonly mcpName: string }) { } > - Copy Codex command + {m.gaudy_bright_opossum_succeed()} - Add to Cursor + {m.fun_dry_dolphin_kick()} - Add to VS Code + {m.maroon_yummy_pug_bask()} void copyMarkdown()} /> @@ -444,7 +449,7 @@ export function HelpCenterArticleActionsDisclosure({ )} > - Article actions + {m.salty_muddy_martin_bump()}
@@ -473,7 +489,7 @@ function SiblingLink({ icon={ArrowLeft02Icon} /> )} - {isNext ? "Next" : "Previous"} + {isNext ? m.sad_tasty_stingray_spark() : m.honest_quick_polecat_sew()} {isNext ? (