mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 20:17:09 +00:00
refactor(folio-spec): gate addAccount and addTxn with whenRoute
This commit is contained in:
1 parent
cd6bc0e86f
commit
5697dfb0c0
1 file changed
+15
-22
@@ -9,6 +9,7 @@ import {
|
|||||||
next,
|
next,
|
||||||
now,
|
now,
|
||||||
weighted,
|
weighted,
|
||||||
|
whenRoute,
|
||||||
} from "@sanderling/spec";
|
} from "@sanderling/spec";
|
||||||
|
|
||||||
interface Account {
|
interface Account {
|
||||||
@@ -131,27 +132,22 @@ const login = actions(() => {
|
|||||||
|
|
||||||
const accountNames = from(["Checking", "Savings", "Travel", "Emergency Fund", "Investments"]);
|
const accountNames = from(["Checking", "Savings", "Travel", "Emergency Fund", "Investments"]);
|
||||||
|
|
||||||
const addAccount = actions(() => {
|
const addAccount = whenRoute(route, ["home", "add-account"], () => {
|
||||||
if (!loggedIn.current) return [];
|
|
||||||
if (route.current === "home") {
|
if (route.current === "home") {
|
||||||
const btn = addAccountButton.current;
|
const btn = addAccountButton.current;
|
||||||
return btn ? [Tap({ on: btn })] : [];
|
return btn ? [Tap({ on: btn })] : [];
|
||||||
}
|
}
|
||||||
if (route.current === "add-account") {
|
const field = accountNameField.current;
|
||||||
const field = accountNameField.current;
|
const submit = addAccountSubmit.current;
|
||||||
const submit = addAccountSubmit.current;
|
const opts = [];
|
||||||
const opts = [];
|
if (field) opts.push(InputText({ into: field, text: accountNames.generate() }));
|
||||||
if (field) opts.push(InputText({ into: field, text: accountNames.generate() }));
|
if (submit) opts.push(Tap({ on: submit }));
|
||||||
if (submit) opts.push(Tap({ on: submit }));
|
return opts;
|
||||||
return opts;
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const amounts = from(["10", "50", "25", "100", "5"]);
|
const amounts = from(["10", "50", "25", "100", "5"]);
|
||||||
|
|
||||||
const addTxn = actions(() => {
|
const addTxn = whenRoute(route, ["home", "ledger", "add-transaction"], () => {
|
||||||
if (!loggedIn.current) return [];
|
|
||||||
if (route.current === "home") {
|
if (route.current === "home") {
|
||||||
const cards = accountCards.current;
|
const cards = accountCards.current;
|
||||||
if (cards.length === 0) return [];
|
if (cards.length === 0) return [];
|
||||||
@@ -161,15 +157,12 @@ const addTxn = actions(() => {
|
|||||||
const btn = addTxnButton.current;
|
const btn = addTxnButton.current;
|
||||||
return btn ? [Tap({ on: btn })] : [];
|
return btn ? [Tap({ on: btn })] : [];
|
||||||
}
|
}
|
||||||
if (route.current === "add-transaction") {
|
const field = txnAmountField.current;
|
||||||
const field = txnAmountField.current;
|
const submit = txnSubmit.current;
|
||||||
const submit = txnSubmit.current;
|
const opts = [];
|
||||||
const opts = [];
|
if (field) opts.push(InputText({ into: field, text: amounts.generate() }));
|
||||||
if (field) opts.push(InputText({ into: field, text: amounts.generate() }));
|
if (submit) opts.push(Tap({ on: submit }));
|
||||||
if (submit) opts.push(Tap({ on: submit }));
|
return opts;
|
||||||
return opts;
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const back = actions(() => {
|
const back = actions(() => {
|
||||||
|
|||||||
Reference in new issue
Block a user