Resolve an occurrence back to the rule behind it
The detail sheet looked its record up by the row's id. For an occurrence that id carries a #date suffix and is not a key in the store, so `own` came back undefined and the edit and delete buttons vanished on every recurring row — and a save would have reached editEvent with an id it could not find and quietly done nothing. The suffix is deliberate: marks key off the occurrence so each time round carries its own completion. There is still only one record to edit. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
4f53b7e153
commit
60041134ee
+16
-12
@@ -19,7 +19,7 @@ import { useProgress } from "./state/useProgress.ts";
|
||||
import { useDailyLog, type DailyLogMap } from "./state/useDailyLog.ts";
|
||||
import { adoptNewLanes, usePrefs } from "./state/usePrefs.ts";
|
||||
import { snapDayWidth } from "./state/zoom.ts";
|
||||
import { useCustom } from "./state/useCustom.ts";
|
||||
import { useCustom, type EventDraft } from "./state/useCustom.ts";
|
||||
import { compareRows, SORT_MODES, type Activity, type SortMode } from "./state/sort.ts";
|
||||
import {
|
||||
advanceFocus,
|
||||
@@ -34,6 +34,7 @@ import { orderGames } from "./state/gameOrder.ts";
|
||||
import { GameMetaProvider, type MetaResolver } from "./state/gameMeta.tsx";
|
||||
import { metaOnTheme, useTheme } from "./state/theme.ts";
|
||||
import {
|
||||
recordFor,
|
||||
type CustomEvents,
|
||||
type CustomGames,
|
||||
type LaneId,
|
||||
@@ -692,17 +693,20 @@ export function App() {
|
||||
onNote={prog.setNote}
|
||||
onIgnore={(id) => toggleIgnored(id, openRow.event.title)}
|
||||
onClose={() => setOpenId(null)}
|
||||
own={
|
||||
custom.events[openRow.event.id] === undefined
|
||||
? undefined
|
||||
: {
|
||||
record: custom.events[openRow.event.id]!,
|
||||
lanes: games,
|
||||
games: custom.games,
|
||||
onSave: custom.editEvent,
|
||||
onDelete: custom.removeEvent,
|
||||
}
|
||||
}
|
||||
own={(() => {
|
||||
// The row may be one occurrence of a rule. Marks key off the
|
||||
// occurrence; the record to edit is the rule behind it.
|
||||
const record = recordFor(custom.events, openRow.event.id);
|
||||
if (record === undefined) return undefined;
|
||||
return {
|
||||
record,
|
||||
lanes: games,
|
||||
games: custom.games,
|
||||
onSave: (_id: string, draft: EventDraft) =>
|
||||
custom.editEvent(record.id, draft),
|
||||
onDelete: () => custom.removeEvent(record.id),
|
||||
};
|
||||
})()}
|
||||
/>
|
||||
)}
|
||||
</Shell>
|
||||
|
||||
+19
-1
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { comesRoundEarly, Repeat } from "./recurrence.ts";
|
||||
import { comesRoundEarly, Repeat, ruleIdOf } from "./recurrence.ts";
|
||||
import type { Occurrence } from "./recurrence.ts";
|
||||
import { EventType, GachaEvent, Precision, slugify } from "./schema.ts";
|
||||
|
||||
@@ -271,3 +271,21 @@ export function asOccurrenceEvent(
|
||||
endPrecision: occurrence.endPrecision,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The stored record a row belongs to, whichever kind of id it carries.
|
||||
*
|
||||
* A row may be one occurrence of a rule, whose id carries a `#` suffix and is
|
||||
* deliberately not a key in the store. Marks, ignores and ticks key off that
|
||||
* suffixed id — each time round has its own completion — but there is only ever
|
||||
* one record to edit, and it is the rule.
|
||||
*
|
||||
* Total, and safe for a feed id: `ruleIdOf` returns anything without a
|
||||
* separator unchanged, and a feed id is simply not in this store.
|
||||
*/
|
||||
export function recordFor(
|
||||
events: CustomEvents,
|
||||
rowId: string,
|
||||
): CustomEvent | undefined {
|
||||
return events[ruleIdOf(rowId)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user