From ddfcda6dd57534b40c7a168dad5818635930e8b0 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 19 Jul 2020 18:20:06 -0400 Subject: [PATCH] Alphabetically sort the forms in the select list. --- src/TaxReturnView.tsx | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/TaxReturnView.tsx b/src/TaxReturnView.tsx index c8e3291..ece241c 100644 --- a/src/TaxReturnView.tsx +++ b/src/TaxReturnView.tsx @@ -22,15 +22,25 @@ export default function TaxReturnView(props: Props) { setState({ form: props.tr.forms[e.target.value] }); }; - const formIndexToName = createMemo(() => props.tr.forms.map((form, i) => { - let name = form.name; - const person = form.person(); - if (person !== undefined) { - const personName = person === Person.joint ? 'Joint' : person.name; - name += ` (${personName})`; - } - return [i, name]; - })); + const formIndexToName = createMemo(() => { + let forms = props.tr.forms.map((form, i) => { + let name = form.name; + const person = form.person(); + if (person !== undefined) { + const personName = person === Person.joint ? 'Joint' : person.name; + name += ` (${personName})`; + } + return [i, name]; + }); + forms.sort((a, b) => { + if (a[1] < b[1]) + return -1; + if (a[1] > b[1]) + return 1; + return 0; + }); + return forms; + }); const formSelector = (