feat(cycle): choose how the calendar feed draws a forecast (#1350)

A forecast period was one all-day event over every day it might fall on,
so a period of a few days showed up as a week-long estimate next to the
logged ones. Each feed now carries a forecast style:

- EXACT: the calculated period only, from the most likely start for the
  predicted number of bleeding days.
- MARGIN: that event, plus separate "possible" events for the days it may
  start earlier and the days it may still run on, each only where the
  band reaches that side. Discreet titles use an open dot for them.
- BAND: the single range, unchanged.

Migration 0495 adds the column with BAND as its default, so every live
feed keeps the events it serves. A feed turned on from now on starts on
MARGIN, set by the mint route. PATCH changes it, rotate copies it, the
status and the audit diff carry it, and the settings card offers it with
a one-line explanation of the chosen style. The horizon and its stop rule
are the same in every style, and the period event keeps its UID across
styles so a calendar updates it in place.
This commit is contained in:
Marc-André Bombeck committed 2026-11-09 10:59:18 +01:00
1 parent f86a7a61e1
commit 546b9b2569
30 files changed
+647 -36

No files matched your search

@@ -30,6 +30,7 @@ const FEED = {
historyCycles: 0,
includeFertile: false,
titleMode: "DISCREET" as const,
forecastStyle: "MARGIN" as const,
};
describe("<CycleCalendarFeedCard>", () => {
@@ -58,6 +59,30 @@ describe("<CycleCalendarFeedCard>", () => {
expect(html).not.toContain("Fertile window");
});
it("offers the three forecast styles and explains the chosen one", () => {
const html = render({
feed: FEED,
projectionState: "OK",
fertileAvailable: false,
});
expect(html).toContain("How forecasts look");
for (const value of ["EXACT", "MARGIN", "BAND"]) {
expect(html).toContain(`value="${value}"`);
}
expect(html).toContain('aria-describedby="cycle-feed-forecast-hint"');
expect(html).toMatch(
/data-slot="cycle-feed-forecast-hint"[^>]*>Expected days, with the days it may start earlier or later as separate entries\.</,
);
const band = render({
feed: { ...FEED, forecastStyle: "BAND" },
projectionState: "OK",
fertileAvailable: false,
});
expect(band).toContain("One entry covering every day it may fall on.");
expect(band).not.toContain("as separate entries");
});
it("explains a shorter feed in the muted tone", () => {
const html = render({
feed: FEED,
@@ -28,6 +28,7 @@ import {
type CycleFeedMinted,
type CycleFeedOptionsPatch,
type CycleFeedStatus,
type FeedForecastStyle,
type FeedTitleMode,
} from "./use-cycle-feed";
@@ -44,6 +45,7 @@ import {
const HORIZONS = [1, 3, 6] as const;
const HISTORIES = [0, 3, 6, 12] as const;
const TITLE_MODES: FeedTitleMode[] = ["DISCREET", "DESCRIPTIVE"];
const FORECAST_STYLES: FeedForecastStyle[] = ["EXACT", "MARGIN", "BAND"];
/** A long URL with its middle elided, so both ends stay recognisable. */
function middleTruncate(url: string, keep = 28): string {
@@ -352,6 +354,31 @@ function FeedOptions({ status }: { status: CycleFeedStatus }) {
</NativeSelect>
</div>
</div>
<div className="space-y-1.5">
<Label htmlFor="cycle-feed-forecast">{t("cycle.feed.forecasts")}</Label>
<NativeSelect
id="cycle-feed-forecast"
value={feed.forecastStyle}
disabled={update.isPending}
aria-describedby="cycle-feed-forecast-hint"
onChange={(e) =>
save({ forecastStyle: e.target.value as FeedForecastStyle })
}
>
{FORECAST_STYLES.map((s) => (
<option key={s} value={s}>
{t(`cycle.feed.forecastStyle.${s}`)}
</option>
))}
</NativeSelect>
<p
id="cycle-feed-forecast-hint"
className="text-muted-foreground text-sm"
data-slot="cycle-feed-forecast-hint"
>
{t(`cycle.feed.forecastStyleHint.${feed.forecastStyle}`)}
</p>
</div>
{status.fertileAvailable ? (
<div className="flex items-start justify-between gap-4">
<div className="space-y-0.5">
+7 -1
View File
@@ -17,6 +17,7 @@ import { queryKeys } from "@/lib/query-keys";
import type { ProjectionState } from "./types";
export type FeedTitleMode = "DISCREET" | "DESCRIPTIVE";
export type FeedForecastStyle = "EXACT" | "MARGIN" | "BAND";
export type FeedFetcher = "GOOGLE" | "APPLE" | "MICROSOFT" | "OTHER";
export interface CycleFeedSummary {
@@ -29,6 +30,7 @@ export interface CycleFeedSummary {
historyCycles: number;
includeFertile: boolean;
titleMode: FeedTitleMode;
forecastStyle: FeedForecastStyle;
}
export interface CycleFeedStatus {
@@ -46,7 +48,11 @@ export interface CycleFeedMinted {
export type CycleFeedOptionsPatch = Partial<
Pick<
CycleFeedSummary,
"horizonCycles" | "historyCycles" | "includeFertile" | "titleMode"
| "horizonCycles"
| "historyCycles"
| "includeFertile"
| "titleMode"
| "forecastStyle"
>
>;