implemented delete button and fixed routing interaction with db
This commit is contained in:
parent
7a77b9ca79
commit
7fecf8c5d9
1 changed files with 23 additions and 3 deletions
|
|
@ -2,7 +2,8 @@ import { router, useLocalSearchParams } from "expo-router";
|
|||
import { useState } from "react";
|
||||
import { SafeAreaView, StyleSheet, Text, TextInput, View } from "react-native";
|
||||
import { AutoDecimalInput, CustomColorPicker, NavigationButton, TypeSelectorSwitch } from "../../../components";
|
||||
import { updateCategory } from "../../../services/database";
|
||||
import useFetch from "../../../hooks/useFetch";
|
||||
import { deleteCategory, deleteExpense, updateCategory } from "../../../services/database";
|
||||
import { useTheme } from "../../contexts/ThemeContext";
|
||||
|
||||
const addCategory = () => {
|
||||
|
|
@ -14,6 +15,8 @@ const addCategory = () => {
|
|||
const [selectedType, setSelectedType] = useState(category_type.toString());
|
||||
const [amount, setAmount] = useState(Number.parseFloat(category_amount.toString()));
|
||||
|
||||
const {data} = useFetch({sql: "SELECT * FROM expense WHERE category_guid = ?", args: [category_guid.toString()]});
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safeAreaViewStyle, {backgroundColor: colors.backgroundColor}]}>
|
||||
<Text style={[styles.headingTextStyle, {color: colors.primaryText}]}>Edit Category</Text>
|
||||
|
|
@ -44,13 +47,27 @@ const addCategory = () => {
|
|||
}}/>
|
||||
</View>
|
||||
|
||||
<View style={styles.deleteButtonView}>
|
||||
<NavigationButton text={"Delete Cateogry"} onPress={() => {
|
||||
for (let i = 0; i < data.length;) {
|
||||
deleteExpense(data[i].guid).then(() => {
|
||||
i++
|
||||
});
|
||||
}
|
||||
deleteCategory(category_guid.toString()).then(() => {
|
||||
router.push("/(tabs)/(budget)");
|
||||
});
|
||||
}}/>
|
||||
</View>
|
||||
|
||||
<View style={styles.navigationButtonViewStyle}>
|
||||
<NavigationButton text="Back" onPress={() => {
|
||||
router.back();
|
||||
}}/>
|
||||
<NavigationButton text="Save" onPress={() => {
|
||||
updateCategory(category_guid.toString(), categoryName, categoryColor, selectedType, amount);
|
||||
updateCategory(category_guid.toString(), categoryName, categoryColor, selectedType, amount).then(() => {
|
||||
router.back();
|
||||
});
|
||||
}}/>
|
||||
</View>
|
||||
</View>
|
||||
|
|
@ -61,6 +78,9 @@ const addCategory = () => {
|
|||
export default addCategory;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
deleteButtonView: {
|
||||
|
||||
},
|
||||
containerStyle: {
|
||||
flex: 1,
|
||||
margin: 10,
|
||||
|
|
|
|||
Reference in a new issue