diff --git a/app/(tabs)/budget/index.tsx b/app/(tabs)/budget/index.tsx index 0230b1d..acaa212 100644 --- a/app/(tabs)/budget/index.tsx +++ b/app/(tabs)/budget/index.tsx @@ -26,12 +26,15 @@ export default function Page() { const {data, isLoading, reFetch} = useFetch({sql: "SELECT guid as category_guid, name as category_name, color as category_color FROM category WHERE type = ?", args: selectedPage === "expenses" ? ["expense"] : selectedPage === "savings" ? ["saving"] : []}); useEffect(() => { + console.log("reFetch()"); reFetch(); }, [selectedPage]); const handlePageSelection = (page: string) => { - setSelectedPage(page); - AsyncStorage.setItem("currentBudgetPage", page); + if(page !== selectedPage) { + setSelectedPage(page); + AsyncStorage.setItem("currentBudgetPage", page); + } }; return ( @@ -40,14 +43,13 @@ export default function Page() { {isLoading ? () : ( } + renderItem = {({item}) => } keyExtractor={item => item.category_guid} ItemSeparatorComponent={() => { return (); }} /> )} - {/* */} ); } diff --git a/components/budget/categoryItem.tsx b/components/budget/categoryItem.tsx index af32907..55804ae 100644 --- a/components/budget/categoryItem.tsx +++ b/components/budget/categoryItem.tsx @@ -1,33 +1,30 @@ import { ColorValue, StyleSheet, Text, View } from "react-native"; -import { useThemeColor } from "../../hooks/useThemeColor"; +import { useTheme } from "../../app/contexts/ThemeContext"; import CustomCard from "../common/CustomCard"; export type CategoryItemProps = { category: string, color: ColorValue, - allocated_account: number, + allocated_ammount: number, + category_guid: string, } const CategoryItem = (properties: CategoryItemProps) => { + + const { colors } = useTheme(); - const textColor = useThemeColor("primaryText"); - const backgroundColor = useThemeColor("backgroundColor"); + const subText = `${calculateSumOfExpenses(properties.category_guid)} / ${properties.allocated_ammount} €`; return ( - + - + {properties.category} - - - - - - 10/100$ - {/* {properties.allocated_account} */} - + + {subText} + ); @@ -42,22 +39,27 @@ const styles = StyleSheet.create({ borderBottomLeftRadius: 10, }, textViewStyle: { + flex: 2, + flexDirection: "column", paddingVertical: 5, - paddingLeft: 10, + paddingHorizontal: 10, alignSelf: "stretch", }, - textViewTextStyle: { + categoryNameStyle: { fontSize: 30, fontWeight: "bold", }, - valueViewStyle: { - alignSelf: "stretch", - flex: 1, - flexDirection: "row-reverse", - alignItems: "center", - paddingHorizontal: 10, - }, - valueViewTextStyle: { - fontSize: 20, + subTextStyle: { + fontSize: 17.5, } - }) \ No newline at end of file + }) + +const calculateSumOfExpenses = (category_guid: string) => { + // const { data } = useFetch({sql: "SELECT amount FROM expense WHERE category_guid = ?", args: [category_guid]}); + + // let sum: number = 0; + // console.log(data); + + console.log("render"); + return 0; +} diff --git a/hooks/useFetch.ts b/hooks/useFetch.ts index c878441..496beba 100644 --- a/hooks/useFetch.ts +++ b/hooks/useFetch.ts @@ -8,7 +8,6 @@ const useFetch = (query: Query) => { const [data, setData] = useState<{[column: string]: any;}[]>([]); const reFetch = () => { - setIsLoading(true); executeQuery(query).then((result) => { if("rows" in result[0]) { @@ -16,7 +15,7 @@ const useFetch = (query: Query) => { } }).catch((error: any) => { console.error("Fetching data from database has failed: ", error); - }).finally(() => { + }).then(() => { setIsLoading(false); }); }