changed useFetch to take a Query parameter so It is easy to work with across the whole app
This commit is contained in:
parent
8009a6a090
commit
ef90c4ee1a
5 changed files with 51 additions and 27 deletions
|
|
@ -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 { useThemeColor } from "../../../hooks/useThemeColor";
|
||||
import { addExpense, executeQuery } from "../../../services/database";
|
||||
import { useAuth } from '../../contexts/AuthContext';
|
||||
import { useRouter } from "expo-router";
|
||||
import { SimpleDate } from '../../../util/SimpleDate';
|
||||
|
|
@ -81,7 +82,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)
|
||||
|
|
@ -93,9 +94,14 @@ export default function Page() {
|
|||
<SafeAreaView edges={["left", "right", "top"]} style={styles.safeAreaViewStyle}>
|
||||
{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>}
|
||||
|
|
|
|||
Reference in a new issue