Resolve "datenbank schmiert ab wenn schnell 20~ einträge eingetragen werden"
This commit is contained in:
parent
32de9bf1f1
commit
417204b4c1
13 changed files with 124 additions and 89 deletions
29
hooks/useFetch.ts
Normal file
29
hooks/useFetch.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import { executeQuery } from "../services/database";
|
||||
|
||||
const useFetch = () => {
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [data, setData] = useState<{[column: string]: any;}[]>([]);
|
||||
|
||||
const reFetch = () => {
|
||||
setIsLoading(true);
|
||||
executeQuery("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;").then((result) => {
|
||||
if("rows" in result[0]) {
|
||||
setData(result[0]["rows"]);
|
||||
}
|
||||
}).catch((error: any) => {
|
||||
console.error("Fetching data from database has failed: ", error);
|
||||
}).finally(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
reFetch();
|
||||
}, [])
|
||||
|
||||
return {data, isLoading, reFetch};
|
||||
}
|
||||
|
||||
export default useFetch;
|
||||
|
|
@ -1,7 +1,11 @@
|
|||
import { useColorScheme } from "react-native";
|
||||
import colors from "../constants/colors"
|
||||
import colors from "../constants/colors";
|
||||
|
||||
export function useThemeColor(colorName: keyof typeof colors.light & keyof typeof colors.dark): string {
|
||||
const theme = useColorScheme() ?? "light";
|
||||
return colors[theme][colorName];
|
||||
}
|
||||
|
||||
export function useUpdateData() {
|
||||
|
||||
}
|
||||
Reference in a new issue