import { useAtom } from "jotai"; import type { NextPage } from "next"; import { SyntheticEvent, useState } from "react"; import { Form } from "react-bootstrap"; import NumberEditBox from "../components/NumberEditBox"; import ReceiptItem from "../components/ReceiptItem"; import { moneyFormatter } from "../lib/formatter"; import { ParsedInputDisplay } from "../lib/parseInput"; import { addLine, receiptAtom, receiptTotalAtom, totalAtom, } from "../lib/state"; const Home: NextPage = () => { const [receipt, setReceipt] = useAtom(receiptAtom); const [input, setInput] = useState(""); const [total] = useAtom(totalAtom); const [calculated] = useAtom(receiptTotalAtom); const formatter = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }); const add = (e: SyntheticEvent) => { e.preventDefault(); addLine(input, receipt, setReceipt); setInput(""); return false; }; return (

Items

setInput(e.currentTarget.value)} value={input} style={{ padding: "8px 16px", fontSize: "1.5em" }} /> {receipt.map((itemAtom, i) => { return ; })}
Receipt Total:

{calculated.totalMap.size > 0 && ( <>

Weighted Breakdown

    {[...calculated.totalMap.entries()].map(([person, value], i) => (
  • {person}: {formatter.format(value)}
  • ))}
)}
); }; export default Home;