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