format: format with biome

This commit is contained in:
Max Koon
2025-11-24 22:20:40 -05:00
parent 01edded95a
commit 6fd531d9c3
41 changed files with 1025 additions and 667 deletions

View File

@@ -1,5 +1,5 @@
import { useQuery, useZero } from "@rocicorp/zero/react";
import { queries, type Mutators, type Schema } from '@money/shared';
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";
@@ -9,8 +9,12 @@ 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() },
{ name: "name", label: "Name" },
{
name: "createdAt",
label: "Added At",
render: (n) => new Date(n).toLocaleString(),
},
];
export function Accounts() {
@@ -21,75 +25,89 @@ export function Accounts() {
const z = useZero<Schema, Mutators>();
// 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);
if (!deleting) return;
const accountIds = deleting.map((account) => account.id);
z.mutate.link.deleteAccounts({ accountIds });
setDeleting([]);
}
};
const addAccount = () => {
setIsAddOpen(true);
}
};
return (
<>
<Dialog.Provider visible={!deleting} close={() => setDeleting([])}>
<Dialog.Provider
visible={deleting.length > 0}
close={() => setDeleting([])}
>
<Dialog.Content>
<Text style={{ fontFamily: 'mono' }}>Delete Account</Text>
<Text style={{ fontFamily: 'mono' }}> </Text>
<Text style={{ fontFamily: 'mono' }}>You are about to delete the following accounts:</Text>
<Text style={{ fontFamily: "mono" }}>Delete Account</Text>
<Text style={{ fontFamily: "mono" }}> </Text>
<Text style={{ fontFamily: "mono" }}>
You are about to delete the following accounts:
</Text>
<View>
{deleting.map(account => <Text style={{ fontFamily: 'mono' }}>- {account.name}</Text>)}
{deleting.map((account) => (
<Text style={{ fontFamily: "mono" }}>- {account.name}</Text>
))}
</View>
<Text style={{ fontFamily: 'mono' }}> </Text>
<Text style={{ fontFamily: "mono" }}> </Text>
<View style={{ flexDirection: 'row' }}>
<Button variant="secondary" onPress={() => { setDeleting([]); }}>Cancel (n)</Button>
<View style={{ flexDirection: "row" }}>
<Button
variant="secondary"
onPress={() => {
setDeleting([]);
}}
shortcut="n"
>
Cancel
</Button>
<Text style={{ fontFamily: 'mono' }}> </Text>
<Text style={{ fontFamily: "mono" }}> </Text>
<Button variant="destructive" onPress={() => {
<Button
variant="destructive"
onPress={() => {
onDelete();
}}>Delete (y)</Button>
}}
shortcut="y"
>
Delete
</Button>
</View>
</Dialog.Content>
</Dialog.Provider>
<Dialog.Provider visible={isAddOpen} close={() => setIsAddOpen(false)}>
<Dialog.Content>
<Text style={{ fontFamily: 'mono' }}>Add Account</Text>
<Text style={{ fontFamily: "mono" }}>Add Account</Text>
<AddAccount />
</Dialog.Content>
</Dialog.Provider>
<View style={{ padding: 10 }}>
<View style={{ alignSelf: "flex-start" }}>
<Button shortcut="a" onPress={addAccount}>Add Account</Button>
<Button shortcut="a" onPress={addAccount}>
Add Account
</Button>
</View>
<Text style={{ fontFamily: 'mono' }}> </Text>
<Text style={{ fontFamily: "mono" }}> </Text>
<Table.Provider columns={COLUMNS} data={items} onKey={(key, selected) => {
if (key.name == 'd') {
setDeleting(selected);
}
}}>
<Table.Provider
columns={COLUMNS}
data={items}
onKey={(key, selected) => {
if (key.name == "d") {
setDeleting(selected);
}
}}
>
<Table.Body />
</Table.Provider>
</View>
@@ -97,34 +115,53 @@ export function Accounts() {
);
}
function AddAccount() {
const { auth } = use(RouterContext);
const [link, details] = useQuery(queries.getPlaidLink(auth));
const { close } = use(Dialog.Context);
const openLink = () => {
if (!link) return
if (!link) return;
Linking.openURL(link.link);
}
};
const z = useZero<Schema, Mutators>();
useEffect(() => {
console.log(link, details);
if (details.type != "complete") return;
if (link != undefined) return;
if (link != undefined) {
if (!link.completeAt) {
const timer = setInterval(() => {
console.log("Checking for link");
z.mutate.link.get({ link_token: link.token });
}, 1000 * 5);
return () => clearInterval(timer);
} else {
if (close) close();
return;
}
}
console.log("Creating new link");
z.mutate.link.create();
}, [link, details]);
return (
<>
{link ? <>
<Text style={{ fontFamily: 'mono' }}>Please click the button to complete setup.</Text>
<Button onPress={() => close && close()}>close</Button>
{link ? (
<>
<Text style={{ fontFamily: "mono" }}>
Please click the button to complete setup.
</Text>
<Button shortcut="return" onPress={openLink}>Open Plaid</Button>
</> : <Text style={{ fontFamily: 'mono' }}>Loading Plaid Link</Text>}
<Button shortcut="return" onPress={openLink}>
Open Plaid
</Button>
</>
) : (
<Text style={{ fontFamily: "mono" }}>Loading Plaid Link</Text>
)}
</>
);
}