navigation finished and debug menu in stats expanded
This commit is contained in:
parent
9706fc0a51
commit
6cf8fc29a2
3 changed files with 41 additions and 25 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { SafeAreaView, StyleSheet, View } from 'react-native';
|
import { StyleSheet, View } from 'react-native';
|
||||||
import { FlatList } from 'react-native-gesture-handler';
|
import { FlatList } from 'react-native-gesture-handler';
|
||||||
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||||
import { BudgetHeader, LoadingSymbol } from '../../../components';
|
import { BudgetHeader, LoadingSymbol } from '../../../components';
|
||||||
import CategoryItem from '../../../components/budget/categoryItem';
|
import CategoryItem from '../../../components/budget/categoryItem';
|
||||||
import useFetch from '../../../hooks/useFetch';
|
import useFetch from '../../../hooks/useFetch';
|
||||||
|
|
@ -10,41 +11,43 @@ import { useThemeColor } from '../../../hooks/useThemeColor';
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const containerColor = useThemeColor("containerColor");
|
const containerColor = useThemeColor("containerColor");
|
||||||
|
|
||||||
const {data, isLoading, reFetch} = useFetch({sql: "SELECT guid as category_guid, name as category_name, color as category_color FROM category", args: []});
|
const [selectedPage, setSelectedPage] = useState("noPageLoaded");
|
||||||
|
|
||||||
const [selectedPage, setSelectedPage] = useState("expenses");
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadSelectedPage = async () => {
|
AsyncStorage.getItem("currentBudgetPage").then((page) => {
|
||||||
try {
|
if(page === "expenses" || page === "savings") {
|
||||||
// const storedPage =
|
setSelectedPage(page);
|
||||||
} catch(error) {
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}).catch((error) => {
|
||||||
|
console.log("Error fetching previous page from Async Storage:", error);
|
||||||
|
})
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
AsyncStorage.setItem
|
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(() => {
|
||||||
|
reFetch();
|
||||||
|
}, [selectedPage]);
|
||||||
|
|
||||||
const handlePageSelection = (page: string) => {
|
const handlePageSelection = (page: string) => {
|
||||||
setSelectedPage(page);
|
setSelectedPage(page);
|
||||||
|
AsyncStorage.setItem("currentBudgetPage", page);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={[styles.safeAreaViewStyle, {backgroundColor: containerColor}]}>
|
<SafeAreaView style={[styles.safeAreaViewStyle, {backgroundColor: containerColor}]}>
|
||||||
<BudgetHeader selectedPage={selectedPage} handlePageSelection={handlePageSelection}/>
|
<BudgetHeader selectedPage={selectedPage} handlePageSelection={handlePageSelection}/>
|
||||||
{isLoading && <LoadingSymbol/>}
|
{isLoading ? (<LoadingSymbol/>) : (
|
||||||
|
<FlatList
|
||||||
<FlatList
|
data={data}
|
||||||
data={data}
|
renderItem = {({item}) => <CategoryItem category={item.category_name} allocated_account={100} color={item.category_color}/>}
|
||||||
renderItem = {({item}) => <CategoryItem category={item.category_name} allocated_account={100} color={item.category_color}/>}
|
keyExtractor={item => item.category_guid}
|
||||||
keyExtractor={item => item.category_guid}
|
ItemSeparatorComponent={() => {
|
||||||
ItemSeparatorComponent={() => {
|
return (<View style={styles.itemSeperatorStyle}/>);
|
||||||
return (<View style={styles.itemSeperatorStyle}/>);
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
)}
|
||||||
|
{/* <LoadingSymbol/> */}
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ export default function Page() {
|
||||||
}}>Init Database</Text>
|
}}>Init Database</Text>
|
||||||
|
|
||||||
<Text style={styles.text} onPress={() => {
|
<Text style={styles.text} onPress={() => {
|
||||||
addCategory("Test", "blue", "budget").then(() => {
|
addCategory("Expense Category", "green", "expense").then(() => {
|
||||||
const getCategoryQuery: Query = {sql: "SELECT guid FROM category", args: []};
|
const getCategoryQuery: Query = {sql: "SELECT guid FROM category", args: []};
|
||||||
executeQuery(getCategoryQuery).then((result) => {
|
executeQuery(getCategoryQuery).then((result) => {
|
||||||
if("rows" in result[0]) {
|
if("rows" in result[0]) {
|
||||||
|
|
@ -46,6 +46,18 @@ export default function Page() {
|
||||||
})
|
})
|
||||||
console.log("Category added with success!");
|
console.log("Category added with success!");
|
||||||
})
|
})
|
||||||
}}>Add Category</Text>
|
}}>Add new Category Expense</Text>
|
||||||
|
|
||||||
|
<Text style={styles.text} onPress={() => {
|
||||||
|
addCategory("Savings Category", "yellow", "saving").then(() => {
|
||||||
|
const getCategoryQuery: Query = {sql: "SELECT guid FROM category", args: []};
|
||||||
|
executeQuery(getCategoryQuery).then((result) => {
|
||||||
|
if("rows" in result[0]) {
|
||||||
|
console.log(result[0]["rows"]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log("Category added with success!");
|
||||||
|
})
|
||||||
|
}}>Add new Category Savings</Text>
|
||||||
</View>);
|
</View>);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ const useFetch = (query: Query) => {
|
||||||
const [data, setData] = useState<{[column: string]: any;}[]>([]);
|
const [data, setData] = useState<{[column: string]: any;}[]>([]);
|
||||||
|
|
||||||
const reFetch = () => {
|
const reFetch = () => {
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
executeQuery(query).then((result) => {
|
executeQuery(query).then((result) => {
|
||||||
if("rows" in result[0]) {
|
if("rows" in result[0]) {
|
||||||
|
|
|
||||||
Reference in a new issue