correct display of budget used
This commit is contained in:
parent
6ee1c01d6a
commit
87640420ec
6 changed files with 14 additions and 24 deletions
|
|
@ -8,7 +8,9 @@ export default function _Layout() {
|
|||
headerShown: false
|
||||
}}>
|
||||
<Stack.Screen name="index"/>
|
||||
<Stack.Screen name="addCategory"/>
|
||||
<Stack.Screen
|
||||
name="addCategory"
|
||||
options={{presentation: "modal"}}/>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
|
@ -24,10 +24,9 @@ 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"] : []});
|
||||
const {data, isLoading, reFetch} = useFetch({sql: "SELECT c.guid AS category_guid, c.name AS category_name, c.color AS category_color, c.type AS category_type, SUM(e.amount) as total_expenses, c.allocated_amount as allocated_amount FROM expense e RIGHT JOIN category c ON e.category_guid = c.guid WHERE c.type = ? GROUP BY c.guid", args: selectedPage === "expenses" ? ["expense"] : selectedPage === "savings" ? ["saving"] : []});
|
||||
|
||||
useEffect(() => {
|
||||
console.log("reFetch()"); //REFETCH LOG
|
||||
reFetch();
|
||||
}, [selectedPage]);
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ export default function Page() {
|
|||
{isLoading ? (<LoadingSymbol/>) : (
|
||||
<FlatList
|
||||
data={data}
|
||||
renderItem = {({item}) => <CategoryItem category={item.category_name} allocated_ammount={100} color={item.category_color} category_guid={item.category_guid} total_expenses={calculateSumOfCategory(item.guid, data)}/>}
|
||||
renderItem = {({item}) => <CategoryItem category={item.category_name} allocated_amount={item.allocated_amount ?? 0} color={item.category_color} category_guid={item.category_guid} total_expenses={item.total_expenses ?? 0}/>}
|
||||
keyExtractor={item => item.category_guid}
|
||||
ItemSeparatorComponent={() => {
|
||||
return (<View style={styles.itemSeperatorStyle}/>);
|
||||
|
|
@ -60,15 +59,6 @@ export default function Page() {
|
|||
);
|
||||
}
|
||||
|
||||
const calculateSumOfCategory = (guid: string, data: {[column: string]: any;}[]): number => {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return 10;
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safeAreaViewStyle: {
|
||||
flex: 1,
|
||||
|
|
|
|||
Reference in a new issue