import { useQuery, useZero } from "@rocicorp/zero/react"; import { queries, type Mutators, type Schema } from '@money/shared'; import { use, useEffect, useState } from "react"; import { RouterContext } from ".."; import { View, Text, Linking } from "react-native"; import { useKeyboard } from "../useKeyboard"; import { Button } from "../../components/Button"; import * as Table from "../../components/Table"; import * as Dialog from "../../components/Dialog"; const COLUMNS: Table.Column[] = [ { name: 'name', label: 'Name' }, { name: 'createdAt', label: 'Added At', render: (n) => new Date(n).toLocaleString() }, ]; export function Accounts() { const { auth } = use(RouterContext); const [items] = useQuery(queries.getItems(auth)); const [deleting, setDeleting] = useState([]); const [isAddOpen, setIsAddOpen] = useState(false); const z = useZero(); // useKeyboard((key) => { // if (key.name == 'n') { // setDeleting([]); // } else if (key.name == 'y') { // onDelete(); // } // }, [deleting]); const onDelete = () => { if (!deleting) return const accountIds = deleting.map(account => account.id); z.mutate.link.deleteAccounts({ accountIds }); setDeleting([]); } const addAccount = () => { setIsAddOpen(true); } return ( <> setDeleting([])}> Delete Account You are about to delete the following accounts: {deleting.map(account => - {account.name})} setIsAddOpen(false)}> Add Account { if (key.name == 'd') { setDeleting(selected); } }}> ); } function AddAccount() { const { auth } = use(RouterContext); const [link, details] = useQuery(queries.getPlaidLink(auth)); const openLink = () => { if (!link) return Linking.openURL(link.link); } const z = useZero(); useEffect(() => { console.log(link, details); if (details.type != "complete") return; if (link != undefined) return; console.log("Creating new link"); z.mutate.link.create(); }, [link, details]); return ( <> {link ? <> Please click the button to complete setup. : Loading Plaid Link} ); }