diff --git a/app/(tabs)/(budget)/addCategory.tsx b/app/(tabs)/(budget)/addCategory.tsx index bdc1a86..a6c53b6 100644 --- a/app/(tabs)/(budget)/addCategory.tsx +++ b/app/(tabs)/(budget)/addCategory.tsx @@ -51,8 +51,7 @@ export default function Page() { router.back(); }}/> { - addCategory(categoryName, categoryColor, selectedType, amount); - router.back(); + addCategory(categoryName, categoryColor, selectedType, amount).then(() => router.back()); }}/> diff --git a/app/(tabs)/(budget)/index.tsx b/app/(tabs)/(budget)/index.tsx index b03fc12..0e42958 100644 --- a/app/(tabs)/(budget)/index.tsx +++ b/app/(tabs)/(budget)/index.tsx @@ -1,12 +1,13 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; import { router, useNavigation } from 'expo-router'; -import { useEffect, useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { StyleSheet, View } from 'react-native'; import { FlatList } from 'react-native-gesture-handler'; import { SafeAreaView } from 'react-native-safe-area-context'; import { BudgetHeader, CategoryItem, LoadingSymbol, Plus } from '../../../components'; import useFetch from '../../../hooks/useFetch'; import { useTheme } from '../../contexts/ThemeContext'; +import { useFocusEffect } from 'expo-router/src/useFocusEffect'; export default function Page() { const {colors} = useTheme() @@ -30,6 +31,14 @@ export default function Page() { reFetch() }, [selectedPage]); + useEffect(() => { + const unsubscribe = navigation.addListener("focus", () => { + reFetch(); + }) + return unsubscribe; + + }, [navigation]) + const handlePageSelection = (page: string) => { if(page !== selectedPage) { diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index 4c74a39..103e5ac 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -34,7 +34,7 @@ export default function Layout() { } return ( - + {itemProps.value} + }} numberOfLines={1}>{itemProps.value + " €"} diff --git a/hooks/useFetch.ts b/hooks/useFetch.ts index e089750..a828d31 100644 --- a/hooks/useFetch.ts +++ b/hooks/useFetch.ts @@ -28,7 +28,6 @@ const useFetch = (query: Query) => { const reFetch = () => { - console.log("refetch called") setIsLoading(true); executeQuery(query).then((result) => { if("rows" in result[0]) { @@ -36,7 +35,6 @@ const useFetch = (query: Query) => { if(result[0]["rows"].length == 0){ setIsEmptyResult(true); } - console.log("len", result[0]["rows"].length) } }).catch((error: any) => { console.error("Fetching data from database has failed: ", error);