fix(folio-web): keep submit live for 400ms after saving

Defers the navigation back so the button is tappable while the label
reads Saved, widening the double-submit window the counting property
is there to catch.
This commit is contained in:
pj committed 2026-08-17 23:27:37 +05:30
1 parent bc0f286e29
commit 8c8e87761d
1 file changed
+21 -2
@@ -9,6 +9,8 @@ import { parseCents } from '../format'
import { back, navigate } from '../router' import { back, navigate } from '../router'
import { BackButton, Header, Screen } from '../components/Screen' import { BackButton, Header, Screen } from '../components/Screen'
const SAVED_NOTICE_MILLIS = 400
export function AddTransactionPage(props: { export function AddTransactionPage(props: {
accountId: string accountId: string
onCreated: () => void onCreated: () => void
@@ -19,6 +21,7 @@ export function AddTransactionPage(props: {
const [note, setNote] = useState('') const [note, setNote] = useState('')
const [err, setErr] = useState<string | null>(null) const [err, setErr] = useState<string | null>(null)
const [busy, setBusy] = useState(false) const [busy, setBusy] = useState(false)
const [saved, setSaved] = useState(false)
useEffect(() => { useEffect(() => {
let alive = true let alive = true
@@ -30,6 +33,15 @@ export function AddTransactionPage(props: {
} }
}, [props.accountId]) }, [props.accountId])
useEffect(() => {
if (!saved) return
const timer = window.setTimeout(
() => back(`/accounts/${props.accountId}`),
SAVED_NOTICE_MILLIS,
)
return () => window.clearTimeout(timer)
}, [saved, props.accountId])
async function onSubmit(e: FormEvent) { async function onSubmit(e: FormEvent) {
e.preventDefault() e.preventDefault()
if (busy) return if (busy) return
@@ -51,7 +63,7 @@ export function AddTransactionPage(props: {
note, note,
}) })
props.onCreated() props.onCreated()
back(`/accounts/${props.accountId}`) setSaved(true)
} catch (e) { } catch (e) {
setErr(e instanceof Error ? e.message : 'Could not save transaction') setErr(e instanceof Error ? e.message : 'Could not save transaction')
} finally { } finally {
@@ -85,6 +97,13 @@ export function AddTransactionPage(props: {
} }
const submitDisabled = busy || amount.trim() === '' const submitDisabled = busy || amount.trim() === ''
const submitLabel = busy
? 'Saving…'
: saved
? 'Saved'
: type === 'credit'
? 'Add credit'
: 'Add debit'
return ( return (
<Screen <Screen
@@ -107,7 +126,7 @@ export function AddTransactionPage(props: {
form="add-txn-form" form="add-txn-form"
disabled={submitDisabled} disabled={submitDisabled}
> >
{busy ? 'Saving…' : type === 'credit' ? 'Add credit' : 'Add debit'} {submitLabel}
</button> </button>
} }
> >