mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
Fixed issue with groceries update
This commit is contained in:
@ -1,17 +1,17 @@
|
||||
import {Text, View} from "react-native";
|
||||
import React, {useEffect, useRef} from "react";
|
||||
import {TextField, TextFieldRef} from "react-native-ui-lib";
|
||||
import {GroceryCategory, IGrocery, useGroceryContext,} from "@/contexts/GroceryContext";
|
||||
import {GroceryCategory, useGroceryContext,} from "@/contexts/GroceryContext";
|
||||
|
||||
interface IEditGrocery {
|
||||
id?: number;
|
||||
id?: string;
|
||||
title: string;
|
||||
category: GroceryCategory;
|
||||
setTitle: (value: string) => void;
|
||||
setCategory?: (category: GroceryCategory) => void;
|
||||
category: GroceryCategory;
|
||||
setSubmit?: (value: boolean) => void;
|
||||
updateCategory?: (id: number, changes: Partial<IGrocery>) => void;
|
||||
closeEdit?: (value: boolean) => void;
|
||||
handleEditSubmit?: Function
|
||||
}
|
||||
|
||||
const EditGroceryItem = ({editGrocery}: { editGrocery: IEditGrocery }) => {
|
||||
@ -49,12 +49,18 @@ const EditGroceryItem = ({editGrocery}: { editGrocery: IEditGrocery }) => {
|
||||
editGrocery.setTitle(value);
|
||||
}}
|
||||
onSubmitEditing={() => {
|
||||
if (editGrocery.setSubmit) editGrocery.setSubmit(true);
|
||||
if (editGrocery.closeEdit) editGrocery.closeEdit(false);
|
||||
if (editGrocery.updateCategory && editGrocery.id)
|
||||
editGrocery.updateCategory(editGrocery.id, {
|
||||
category: fuzzyMatchGroceryCategory(editGrocery.title), title: editGrocery.title
|
||||
});
|
||||
if (editGrocery.setSubmit) {
|
||||
editGrocery.setSubmit(true);
|
||||
}
|
||||
if (editGrocery.setCategory) {
|
||||
editGrocery.setCategory(fuzzyMatchGroceryCategory(editGrocery.title));
|
||||
}
|
||||
if (editGrocery.handleEditSubmit) {
|
||||
editGrocery.handleEditSubmit({id: editGrocery.id, title: editGrocery.title, category: editGrocery.category});
|
||||
}
|
||||
if (editGrocery.closeEdit) {
|
||||
editGrocery.closeEdit(false);
|
||||
}
|
||||
}}
|
||||
maxLength={25}
|
||||
/>
|
||||
|
||||
@ -80,15 +80,15 @@ const GroceryItem = ({
|
||||
</View>
|
||||
) : (
|
||||
<EditGroceryItem
|
||||
editGrocery={{
|
||||
id: item.id,
|
||||
title: newTitle,
|
||||
setTitle: setNewTitle,
|
||||
category: category,
|
||||
updateCategory: updateGroceryItem,
|
||||
closeEdit: setIsEditingTitle,
|
||||
setCategory: setCategory,
|
||||
}}
|
||||
editGrocery={{
|
||||
id: item.id,
|
||||
title: newTitle,
|
||||
category: category,
|
||||
setTitle: setNewTitle,
|
||||
setCategory: setCategory,
|
||||
closeEdit: setIsEditingTitle,
|
||||
handleEditSubmit: updateGroceryItem
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{!item.approved ? (
|
||||
|
||||
Reference in New Issue
Block a user