-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.tsx
85 lines (79 loc) · 1.96 KB
/
new.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Stack, useRouter, useSearchParams } from "expo-router";
import { StatusBar } from "expo-status-bar";
import React, { useEffect, useState } from "react";
import { StyleSheet, View } from "react-native";
import { IconButton, TextInput } from "react-native-paper";
import {
SafeAreaProvider,
useSafeAreaInsets,
} from "react-native-safe-area-context";
import {
Account,
createCategory,
restoreAccount,
} from "../../../../lib/account";
import { createEvent, getEvents } from "../../../../lib/api";
function Inner(): JSX.Element {
const params = useSearchParams();
const accountId = `${params.id}`;
const insets = useSafeAreaInsets();
const [account, setAccount] = useState<Account | null>(null);
const [name, setName] = useState<string>("");
const router = useRouter();
useEffect(() => {
getEvents(accountId)
.then((events) => restoreAccount(events))
.then((account) => setAccount(account));
}, []);
const onClickOk = () => {
if (account === null) return;
const [_, event] = createCategory(account, name);
createEvent(event).then((_) => {
router.back();
});
};
return (
<View
style={[
styles.container,
{
paddingTop: insets.top,
},
]}
>
<StatusBar style="auto" />
<Stack.Screen
options={{
title: "Add Category",
headerRight: () => <IconButton icon="check" onPress={onClickOk} />,
}}
/>
<View style={{ flex: 1, width: "100%" }}>
<TextInput
label="Name"
mode="outlined"
onChangeText={setName}
style={styles.input}
value={name}
/>
</View>
</View>
);
}
export default function AccountNew() {
return (
<SafeAreaProvider>
<Inner />
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
container: {
alignItems: "center",
flex: 1,
justifyContent: "center",
},
input: {
margin: 16,
},
});