mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 16:34:54 +00:00
- Fixed issue with grocery edit not closing, reverted to the category resolving solution(fuzzy search categories), added check button for saving the grocery after editing, made code improvemnets around the groceries page
This commit is contained in:
@ -6,6 +6,7 @@ import { Dropdown } from "react-native-element-dropdown";
|
|||||||
import CloseXIcon from "@/assets/svgs/CloseXIcon";
|
import CloseXIcon from "@/assets/svgs/CloseXIcon";
|
||||||
import { StyleSheet } from "react-native";
|
import { StyleSheet } from "react-native";
|
||||||
import DropdownIcon from "@/assets/svgs/DropdownIcon";
|
import DropdownIcon from "@/assets/svgs/DropdownIcon";
|
||||||
|
import {AntDesign} from "@expo/vector-icons";
|
||||||
|
|
||||||
interface IEditGrocery {
|
interface IEditGrocery {
|
||||||
id?: string;
|
id?: string;
|
||||||
@ -14,7 +15,7 @@ interface IEditGrocery {
|
|||||||
setTitle: (value: string) => void;
|
setTitle: (value: string) => void;
|
||||||
setCategory?: (category: GroceryCategory) => void;
|
setCategory?: (category: GroceryCategory) => void;
|
||||||
setSubmit?: (value: boolean) => void;
|
setSubmit?: (value: boolean) => void;
|
||||||
closeEdit?: (value: boolean) => void;
|
closeEdit?: () => void;
|
||||||
handleEditSubmit?: Function;
|
handleEditSubmit?: Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,8 +57,22 @@ const EditGroceryItem = ({ editGrocery }: { editGrocery: IEditGrocery }) => {
|
|||||||
value={editGrocery.title}
|
value={editGrocery.title}
|
||||||
onChangeText={(value) => {
|
onChangeText={(value) => {
|
||||||
editGrocery.setTitle(value);
|
editGrocery.setTitle(value);
|
||||||
|
let groceryCategory = fuzzyMatchGroceryCategory(value);
|
||||||
|
if (editGrocery.setCategory) {
|
||||||
|
editGrocery.setCategory(groceryCategory);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onSubmitEditing={() => {
|
maxLength={25}
|
||||||
|
/>
|
||||||
|
<View row centerV>
|
||||||
|
<AntDesign
|
||||||
|
name="check"
|
||||||
|
size={24}
|
||||||
|
style={{
|
||||||
|
color: "green",
|
||||||
|
marginRight: 15,
|
||||||
|
}}
|
||||||
|
onPress={() => {
|
||||||
if (editGrocery.setSubmit) {
|
if (editGrocery.setSubmit) {
|
||||||
editGrocery.setSubmit(true);
|
editGrocery.setSubmit(true);
|
||||||
}
|
}
|
||||||
@ -69,17 +84,19 @@ const EditGroceryItem = ({ editGrocery }: { editGrocery: IEditGrocery }) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (editGrocery.closeEdit) {
|
if (editGrocery.closeEdit) {
|
||||||
editGrocery.closeEdit(false);
|
editGrocery.closeEdit();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
maxLength={25}
|
|
||||||
/>
|
/>
|
||||||
<CloseXIcon
|
<CloseXIcon
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (editGrocery.closeEdit) editGrocery.closeEdit(false);
|
if (editGrocery.closeEdit) {
|
||||||
|
editGrocery.closeEdit();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
</View>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
style={{marginTop: 15}}
|
style={{marginTop: 15}}
|
||||||
data={groceryCategoryOptions}
|
data={groceryCategoryOptions}
|
||||||
@ -88,9 +105,7 @@ const EditGroceryItem = ({ editGrocery }: { editGrocery: IEditGrocery }) => {
|
|||||||
labelField="label"
|
labelField="label"
|
||||||
valueField="value"
|
valueField="value"
|
||||||
value={
|
value={
|
||||||
editGrocery.category == GroceryCategory.None
|
editGrocery.category
|
||||||
? null
|
|
||||||
: editGrocery.category
|
|
||||||
}
|
}
|
||||||
iconColor="white"
|
iconColor="white"
|
||||||
activeColor={"#fd1775"}
|
activeColor={"#fd1775"}
|
||||||
@ -114,8 +129,7 @@ const EditGroceryItem = ({ editGrocery }: { editGrocery: IEditGrocery }) => {
|
|||||||
id: editGrocery.id,
|
id: editGrocery.id,
|
||||||
category: item.value,
|
category: item.value,
|
||||||
});
|
});
|
||||||
console.log("kategorija vo diropdown: " + item.value);
|
if (editGrocery.closeEdit) editGrocery.closeEdit();
|
||||||
if (editGrocery.closeEdit) editGrocery.closeEdit(false);
|
|
||||||
} else {
|
} else {
|
||||||
if (editGrocery.setCategory) {
|
if (editGrocery.setCategory) {
|
||||||
editGrocery.setCategory(item.value);
|
editGrocery.setCategory(item.value);
|
||||||
|
|||||||
@ -23,12 +23,14 @@ const GroceryItem = ({
|
|||||||
|
|
||||||
const [openFreqEdit, setOpenFreqEdit] = useState<boolean>(false);
|
const [openFreqEdit, setOpenFreqEdit] = useState<boolean>(false);
|
||||||
const [isEditingTitle, setIsEditingTitle] = useState<boolean>(false);
|
const [isEditingTitle, setIsEditingTitle] = useState<boolean>(false);
|
||||||
const [newTitle, setNewTitle] = useState<string>("");
|
const [newTitle, setNewTitle] = useState<string>(item.title ?? "");
|
||||||
const [category, setCategory] = useState<GroceryCategory>(
|
const [category, setCategory] = useState<GroceryCategory>(item.category ?? GroceryCategory.None);
|
||||||
GroceryCategory.None
|
|
||||||
);
|
|
||||||
const [itemCreator, setItemCreator] = useState<UserProfile>(null);
|
const [itemCreator, setItemCreator] = useState<UserProfile>(null);
|
||||||
|
|
||||||
|
const closeEdit = () => {
|
||||||
|
setIsEditingTitle(false);
|
||||||
|
}
|
||||||
|
|
||||||
const handleTitleChange = (newTitle: string) => {
|
const handleTitleChange = (newTitle: string) => {
|
||||||
updateGroceryItem({ id: item?.id, title: newTitle });
|
updateGroceryItem({ id: item?.id, title: newTitle });
|
||||||
};
|
};
|
||||||
@ -38,7 +40,6 @@ const GroceryItem = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setNewTitle(item.title);
|
|
||||||
console.log(item);
|
console.log(item);
|
||||||
getItemCreator(item?.creatorId);
|
getItemCreator(item?.creatorId);
|
||||||
}, []);
|
}, []);
|
||||||
@ -81,9 +82,21 @@ const GroceryItem = ({
|
|||||||
setOpenFreqEdit(false);
|
setOpenFreqEdit(false);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{!isEditingTitle ? (
|
{isEditingTitle ?
|
||||||
|
<EditGroceryItem
|
||||||
|
editGrocery={{
|
||||||
|
id: item.id,
|
||||||
|
title: newTitle,
|
||||||
|
category: category,
|
||||||
|
setTitle: setNewTitle,
|
||||||
|
setCategory: setCategory,
|
||||||
|
closeEdit: closeEdit,
|
||||||
|
handleEditSubmit: updateGroceryItem,
|
||||||
|
}}
|
||||||
|
/> :
|
||||||
<View>
|
<View>
|
||||||
{ isParent ? <TouchableOpacity onPress={() => setIsEditingTitle(true)}>
|
{isParent ?
|
||||||
|
<TouchableOpacity onPress={() => setIsEditingTitle(true)}>
|
||||||
<Text text70T black style={styles.title}>
|
<Text text70T black style={styles.title}>
|
||||||
{item.title}
|
{item.title}
|
||||||
</Text>
|
</Text>
|
||||||
@ -93,40 +106,27 @@ const GroceryItem = ({
|
|||||||
</Text>
|
</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
) : (
|
}
|
||||||
<EditGroceryItem
|
|
||||||
editGrocery={{
|
|
||||||
id: item.id,
|
|
||||||
title: newTitle,
|
|
||||||
category: item.category,
|
|
||||||
setTitle: setNewTitle,
|
|
||||||
setCategory: setCategory,
|
|
||||||
closeEdit: setIsEditingTitle,
|
|
||||||
handleEditSubmit: updateGroceryItem,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{!item.approved ? (
|
{!item.approved ? (
|
||||||
<View row centerV marginB-10>
|
<View row centerV marginB-10>
|
||||||
{isParent && <><AntDesign
|
{isParent &&
|
||||||
|
<>
|
||||||
|
<AntDesign
|
||||||
name="check"
|
name="check"
|
||||||
size={24}
|
size={24}
|
||||||
style={{
|
style={{
|
||||||
color: "green",
|
color: "green",
|
||||||
marginRight: 15,
|
marginRight: 15,
|
||||||
}}
|
}}
|
||||||
onPress={() => {
|
onPress={isParent ? () => handleItemApproved(item.id, { approved: true }) : null}
|
||||||
isParent ? handleItemApproved(item.id, { approved: true }) : null
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<AntDesign
|
<AntDesign
|
||||||
name="close"
|
name="close"
|
||||||
size={24}
|
size={24}
|
||||||
style={{ color: "red" }}
|
style={{ color: "red" }}
|
||||||
onPress={() => {
|
onPress={isParent ? () => handleItemApproved(item.id, { approved: false }) : null}
|
||||||
isParent ? handleItemApproved(item.id, { approved: false }) : null
|
/>
|
||||||
}}
|
</>}
|
||||||
/> </>}
|
|
||||||
</View>
|
</View>
|
||||||
) : (
|
) : (
|
||||||
!isEditingTitle && (
|
!isEditingTitle && (
|
||||||
@ -158,7 +158,8 @@ const GroceryItem = ({
|
|||||||
borderRadius: 22,
|
borderRadius: 22,
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
}}
|
}}
|
||||||
/> : <View
|
/> :
|
||||||
|
<View
|
||||||
style={{
|
style={{
|
||||||
position: "relative",
|
position: "relative",
|
||||||
width: 24.64,
|
width: 24.64,
|
||||||
|
|||||||
Reference in New Issue
Block a user