Resolve "addButton (for demo)"
This commit is contained in:
parent
54b2b41ed2
commit
60712e8397
7 changed files with 210 additions and 25 deletions
|
|
@ -1,21 +1,27 @@
|
|||
import { useEffect } from 'react';
|
||||
import { Text } from 'react-native';
|
||||
import { executeQuery, initDatabase, addCategory } from '../../../services/database';
|
||||
import { StyleSheet, Text, View } from 'react-native';
|
||||
import { deleteExpenses } from '../../../services/database';
|
||||
|
||||
export default function Page() {
|
||||
|
||||
useEffect(() => {
|
||||
initDatabase().then();
|
||||
addCategory("Test Category 2", "FFFFFF", "budget").then();
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.text} onPress={() => {
|
||||
deleteExpenses().then(() => {
|
||||
console.log("Expenses Deleted!");
|
||||
})
|
||||
}}>Reset Expenses</Text>
|
||||
</View>);
|
||||
}
|
||||
|
||||
executeQuery("SELECT * FROM category").then((res) => {
|
||||
console.log(res);
|
||||
});;
|
||||
|
||||
//deleteDatabase();
|
||||
});
|
||||
|
||||
|
||||
|
||||
return <Text>Budget Page</Text>;
|
||||
}
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
text: {
|
||||
textAlign: 'center',
|
||||
fontSize: 40,
|
||||
color: "red",
|
||||
}
|
||||
});
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
import { useRouter } from "expo-router";
|
||||
import { useFocusEffect, useRouter } from "expo-router";
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { NativeScrollEvent, NativeSyntheticEvent, StyleSheet, View } from 'react-native';
|
||||
import { FlatList } from 'react-native-gesture-handler';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import { ExpenseItem, Plus, SearchBar, Welcome } from '../../../components';
|
||||
import { useThemeColor } from "../../../hooks/hooks";
|
||||
import { executeQuery } from "../../../services/database";
|
||||
import { addCategory, addExpense, executeQuery } from "../../../services/database";
|
||||
import { useAuth } from '../../contexts/AuthContext';
|
||||
|
||||
export default function Page() {
|
||||
|
|
@ -39,20 +39,39 @@ export default function Page() {
|
|||
|
||||
const [data, setData] = useState<{[column: string]: any;}[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
executeQuery("SELECT e.guid AS expense_guid, e.name AS expense_name, c.name AS category_name, e.datetime AS expense_datetime, e.amount AS expense_amount, c.color AS category_color FROM expense e JOIN category c ON e.category_guid = c.guid;").then((result) => {
|
||||
//only for demonstration during phase 1, delete later
|
||||
useEffect(() => {
|
||||
addCategory("Test Category", "red", "budget");
|
||||
update();
|
||||
}, []);
|
||||
|
||||
useFocusEffect(() => {
|
||||
update();
|
||||
});
|
||||
|
||||
const update = () => {
|
||||
executeQuery("SELECT e.guid AS expense_guid, e.name AS expense_name, c.name AS category_name, e.datetime AS expense_datetime, e.amount AS expense_amount, c.color AS category_color FROM expense e JOIN category c ON e.category_guid = c.guid;").then((result) => {
|
||||
if(result === undefined) return;
|
||||
setData(result);
|
||||
}).catch((error) => {
|
||||
throw error;
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={{flex: 1, backgroundColor: backgroundColor}}>
|
||||
{plusShow && <Plus onPress={()=>{
|
||||
router.push("/(tabs)/home/addItem")
|
||||
// router.push("/(tabs)/home/addItem");
|
||||
|
||||
executeQuery("SELECT guid FROM category").then((result) => {
|
||||
if(result === undefined) return;
|
||||
addExpense("Random Expense", result[0]["guid"], "12.08.2023", 1).then(() => {
|
||||
update();
|
||||
});
|
||||
}).catch((error) => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
}}/>}
|
||||
|
||||
<FlatList
|
||||
|
|
|
|||
Reference in a new issue