fix(editor): Task 3 round 1, literal journey, pin, limits, notice

This commit is contained in:
bchanot committed 2026-11-13 20:38:04 +01:00
1 parent 8b42816270
commit 3bb3603115
9 files changed
+295 -97

No files matched your search

+12 -11
View File
@@ -57,7 +57,8 @@ function useOpening({ dispatch, mark }: LayerContext, held: RefObject<Opener>) {
}
/** The moves that take it away: a user close, and the replace that is no Back step. */
function useClosing({ dispatch, announce, guards, mark }: LayerContext) {
function useClosing(ctx: LayerContext) {
const { dispatch, announce, guards, mark } = ctx
const close = useCallback(
(forced = false) => {
if (!guards.ask('reference', forced).allowed) return false
@@ -82,17 +83,19 @@ function useClosing({ dispatch, announce, guards, mark }: LayerContext) {
}
/** A creation that succeeded: its entry becomes the reference's own, then it closes. */
function useCreated(
{ dispatch, mark }: LayerContext,
replace: ReferenceMoves['replace'],
) {
function useCreated(ctx: LayerContext, replace: ReferenceMoves['replace']) {
const { dispatch, mark } = ctx
const [added, setAdded] = useState<AddedReference | null>(null)
const created = useCallback(
(id: string) => {
replace(id)
setAdded((last) => ({ id, serial: (last?.serial ?? 0) + 1 }))
// After the commit that wrote the replace: the entry is the reference's own before
// the close goes back over it, so a Forward never reopens a creation.
// Precondition: the caller is a discrete event (the form's submit). React then
// renders the replace and runs the history effect before this microtask, so the
// entry is the reference's own before the close goes back over it and a Forward
// never reopens a creation. Called from anywhere else, the replace and the close
// would merge into one view change (a Back, and the entry keeps its creation).
// The microtask also keeps `mark()` from overwriting the replace hint early.
queueMicrotask(() => {
mark()
dispatch({ type: 'close_reference' })
@@ -104,10 +107,8 @@ function useCreated(
}
/** The filter's two moves: remove it by replace, return to the finding it names. */
function useFilter(
{ dispatch, announce, mark }: LayerContext,
trace: MoveTrace,
) {
function useFilter(ctx: LayerContext, trace: MoveTrace) {
const { dispatch, announce, mark } = ctx
const clearFilter = useCallback(
(text?: string) => {
if (text) announce(text)