Replace the UI with the Organic design handoff #124

Merged
steve merged 4 commits from feat/organic-ui into main 2026-08-22 23:40:23 +00:00
Showing only changes of commit 2af79012e4 - Show all commits
+10 -3
View File
@@ -1,4 +1,5 @@
import { useCallback } from 'react'
import { toast } from '@/components/ui/toast'
import { totalChanges, useGardenHistory, useUndo, type ChangeSet } from '@/lib/history'
/** The newest change set still in effect — not already reverted, and not itself
@@ -23,10 +24,16 @@ export function useUndoLast(gardenId: number, enabled: boolean) {
const undoLast = useCallback(async () => {
const fresh = await history.refetch()
const list = fresh.data?.pages.flatMap((p) => p.changeSets) ?? sets
const t = latestUndoable(list)
// A failed refetch keeps the STALE pages in `data` (react-query doesn't
// clear them), so falling through here would pick the step before the one
// just made. Undoing nothing is the only safe answer until it can be read.
if (fresh.status !== 'success') {
toast.error("Couldn't re-read the history, so nothing was undone — try again.")
return
}
const t = latestUndoable(fresh.data.pages.flatMap((p) => p.changeSets))
if (t) undo.undo(t)
}, [history, undo, sets])
}, [history, undo])
return {
history,