fix(settings): count tasks in the Your own summary

A reader whose only own items were tasks was told they had none yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Lucas Winther
2026-10-13 14:13:18 +02:00
co-authored by Claude Opus 5.5
parent 624c725cbf
commit 08269b5d5c
2 changed files with 18 additions and 5 deletions
+8 -4
View File
@@ -290,7 +290,7 @@ export function Controls({
</div>
</Group>
<Group name="Your own games and events" state={ownState(ownGames, ownEvents)}>
<Group name="Your own games and events" state={ownState(ownGames, ownEvents, own.tasks?.length ?? 0)}>
<YourOwn {...own} />
</Group>
@@ -387,11 +387,15 @@ function visibilityState(
return also.length === 0 ? "live deadlines only" : `plus ${also.join(", ")}`;
}
function ownState(games: number, events: number): string {
if (games === 0 && events === 0) return "none yet";
/** The Your own group's summary line. Exported so its counting is tested directly. */
export function ownState(games: number, events: number, tasks = 0): string {
if (games === 0 && events === 0 && tasks === 0) return "none yet";
const plural = (n: number, word: string) =>
`${n} ${word}${n === 1 ? "" : "s"}`;
return `${plural(games, "game")} · ${plural(events, "event")}`;
const parts =
games === 0 && events === 0 ? [] : [plural(games, "game"), plural(events, "event")];
if (tasks > 0) parts.push(plural(tasks, "task"));
return parts.join(" · ");
}
/**
+10 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { renderToStaticMarkup } from "react-dom/server";
import { Controls } from "../src/client/components/Controls.tsx";
import { Controls, ownState } from "../src/client/components/Controls.tsx";
import { GameMetaProvider } from "../src/client/state/gameMeta.tsx";
import { metaFor } from "../src/shared/games.ts";
import type { Prefs } from "../src/client/state/usePrefs.ts";
@@ -316,3 +316,12 @@ describe("Controls: built-in weekly tasks", () => {
expect(render(PREFS)).not.toContain("Built-in weekly tasks");
});
});
describe("Controls: the Your own summary counts tasks", () => {
test("a reader with only tasks is not told they have none", () => {
expect(ownState(0, 0, 1)).toBe("1 task");
expect(ownState(1, 2, 0)).toBe("1 game · 2 events");
expect(ownState(1, 0, 2)).toBe("1 game · 0 events · 2 tasks");
expect(ownState(0, 0, 0)).toBe("none yet");
});
});