Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
198 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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, | ||
restoreAccount, | ||
updateCategory, | ||
} from "../../../../../lib/account"; | ||
import { createEvent, getEvents } from "../../../../../lib/api"; | ||
|
||
function Inner(): JSX.Element { | ||
const params = useSearchParams(); | ||
const accountId = `${params.id}`; | ||
const nameDefault = decodeURIComponent(`${params.name}`); | ||
const categoryId = `${params.categoryId}`; | ||
const insets = useSafeAreaInsets(); | ||
const [account, setAccount] = useState<Account | null>(null); | ||
const [name, setName] = useState<string>(nameDefault); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
getEvents(accountId) | ||
.then((events) => restoreAccount(events)) | ||
.then((account) => setAccount(account)); | ||
}, []); | ||
|
||
const onClickOk = () => { | ||
if (account === null) return; | ||
const [_, event] = updateCategory(account, categoryId, name); | ||
createEvent(event).then((_) => { | ||
router.back(); | ||
}); | ||
}; | ||
|
||
return ( | ||
<View | ||
style={[ | ||
styles.container, | ||
{ | ||
paddingTop: insets.top, | ||
}, | ||
]} | ||
> | ||
<StatusBar style="auto" /> | ||
<Stack.Screen | ||
options={{ | ||
title: "Edit 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, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.