Resolve "Implement and Split edit Category from add Category"

This commit is contained in:
Thomas Schleicher 2024-01-05 16:45:25 +00:00 committed by jastornig
parent bf939fb807
commit d3b7c61c67
8 changed files with 146 additions and 21 deletions

View file

@ -7,12 +7,14 @@ import { useTheme } from "../../contexts/ThemeContext";
export default function Page() {
const {colors} = useTheme();
const {category_guid, category_name} = useLocalSearchParams();
const {category_guid} = useLocalSearchParams();
const {category_amount, category_color, category_name, category_type} = fetchCategoryInformation(category_guid.toString());
const {data, isLoading, reFetch} = useFetch({sql: "SELECT e.guid AS expense_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 FROM expense e JOIN category c ON e.category_guid = c.guid WHERE c.guid = ? ORDER BY expense_datetime desc;", args: [category_guid]});
const handleEditCategory = () => {
console.log("edit category");
router.push({pathname: "./(tabs)/budget/editCategory", params: {category_guid: category_guid, category_color: category_color, category_amount: category_amount, category_name: category_name, category_type: category_type}});
}
const handleBackButton = () => {
@ -54,6 +56,25 @@ export default function Page() {
);
}
const fetchCategoryInformation = (guid: string) => {
const {data} = useFetch({sql: "SELECT * FROM category WHERE guid = ?", args: [guid]});
let category_name = "";
let category_color = "";
let category_amount = 0;
let category_type = "";
if (data && data[0]) {
if ("name" in data[0]) category_name = data[0].name as string;
if ("color" in data[0]) category_color = data[0].color as string;
if ("allocated_amount" in data[0]) category_amount = data[0].allocated_amount as number;
if ("type" in data[0]) category_type = data[0].type as string;
}
return {category_name, category_color, category_amount, category_type};
}
const styles = StyleSheet.create({
safeAreaView: {
flex: 1,