Resolve "Budget"

This commit is contained in:
Thomas Schleicher 2024-01-02 12:49:13 +00:00 committed by jastornig
parent 645b805aa7
commit 69610de100
17 changed files with 346 additions and 121 deletions

View file

@ -5,7 +5,8 @@ import { FlatList } from 'react-native-gesture-handler';
import { SafeAreaView } from 'react-native-safe-area-context';
import { ExpenseItem, LoadingSymbol, Plus, SearchBar, Welcome } from '../../../components';
import useFetch from '../../../hooks/useFetch';
import { addExpense } from "../../../services/database";
import { addExpense, executeQuery } from "../../../services/database";
import { useAuth } from '../../contexts/AuthContext';
import { useRouter } from "expo-router";
import { SimpleDate } from '../../../util/SimpleDate';
@ -37,26 +38,7 @@ const constructMarkedDates = (data : {[column: string]: any}) => {
export default function Page() {
const { colors, theme } = useTheme()
//Styles
const styles = StyleSheet.create({
safeAreaViewStyle: {
flex: 1,
backgroundColor: colors.backgroundColor
},
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
text: {
color: colors.primaryText,
fontSize: 70,
fontWeight: "bold"
},
loading: {
color: "red",
}
});
const router = useRouter();
const [plusShow, setPlusShow] = useState(true);
@ -81,7 +63,7 @@ export default function Page() {
}
}
const {data, isLoading, reFetch} = useFetch();
const {data, isLoading, reFetch} = useFetch({sql: "SELECT e.guid AS expense_guid, c.guid AS category_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, c.type AS category_type FROM expense e JOIN category c ON e.category_guid = c.guid;", args: []});
const expenseDates = useMemo(()=>
constructMarkedDates(data)
@ -90,15 +72,20 @@ export default function Page() {
return (
<SafeAreaView edges={["left", "right", "top"]} style={styles.safeAreaViewStyle}>
<SafeAreaView edges={["left", "right", "top"]} style={[styles.safeAreaViewStyle, {backgroundColor: colors.containerColor}]}>
{plusShow && <Plus onPress={()=>{
// router.push("/(tabs)/home/addItem");
newExpense("Test Title", "3b33b8ac-5fc1-43e5-81fc-cf61628861f7", "69.69.1234", 100).then(() => {
reFetch();
});
executeQuery({sql: "SELECT guid FROM category", args: []}).then((result) => {
if("rows" in result[0]) {
newExpense("Test Title", result[0]["rows"][0]["guid"], "69.69.1234", 100).then(() => {
reFetch();
});
}
})
}}/>}
{isLoading && <LoadingSymbol></LoadingSymbol>}
{isLoading && <LoadingSymbol/>}
<FlatList
data={data}
@ -122,13 +109,23 @@ export default function Page() {
<SearchBar placeholder='Type to Search...'></SearchBar>
</>
}
renderItem = {({item}) => <ExpenseItem category={item.category_name} color={item.category_color} date={item.expense_datetime} title={item.expense_name} value={"10,00$"}/>}
renderItem = {({item}) => <ExpenseItem category={item.category_name} color={item.category_color} date={item.expense_datetime} title={item.expense_name} value={item.expense_amount}/>}
keyExtractor={item => item.expense_guid}
ItemSeparatorComponent={()=><View style={{marginVertical: 5}}></View>}
ItemSeparatorComponent={() => {
return (<View style={styles.itemSeperatorStyle}/>);
}}
onScroll={handleScroll}
scrollEventThrottle={20}
>
</FlatList>
/>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
safeAreaViewStyle: {
flex: 1,
},
itemSeperatorStyle: {
marginVertical: 5,
}
});