Resolve "addButton (for demo)"
This commit is contained in:
parent
54b2b41ed2
commit
60712e8397
7 changed files with 210 additions and 25 deletions
|
|
@ -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