mirror of
https://github.com/urosran/cally.git
synced 2025-08-25 13:49:39 +00:00
fix groceries, todo, calendar
This commit is contained in:
@ -51,7 +51,7 @@ export const AddEventDialog = () => {
|
||||
}}
|
||||
onPress={handleOpenManualInputModal}
|
||||
>
|
||||
<Text style={{color: "white"}}>Manually Input</Text>
|
||||
<Text style={{color: "white"}}>Create New</Text>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
@ -62,7 +62,7 @@ export const AddEventDialog = () => {
|
||||
}}
|
||||
disabled
|
||||
>
|
||||
<Text style={{color: "white"}}>Scan an Image</Text>
|
||||
<Text style={{color: "white"}}>Event</Text>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
@ -73,7 +73,18 @@ export const AddEventDialog = () => {
|
||||
}}
|
||||
disabled
|
||||
>
|
||||
<Text style={{color: "white"}}>Paste in text</Text>
|
||||
<Text style={{color: "white"}}>To Do</Text>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
style={{
|
||||
marginBottom: 10,
|
||||
backgroundColor: "#007bff",
|
||||
opacity: 0.5
|
||||
}}
|
||||
disabled
|
||||
>
|
||||
<Text style={{color: "white"}}>Upload Image</Text>
|
||||
</Button>
|
||||
</View>
|
||||
|
||||
|
@ -1,260 +1,320 @@
|
||||
import {
|
||||
Avatar,
|
||||
Colors,
|
||||
DateTimePicker,
|
||||
LoaderScreen,
|
||||
Modal,
|
||||
Picker,
|
||||
Switch,
|
||||
Text,
|
||||
TextField,
|
||||
View
|
||||
Avatar,
|
||||
Colors,
|
||||
DateTimePicker,
|
||||
LoaderScreen,
|
||||
Modal,
|
||||
Picker,
|
||||
Switch,
|
||||
Text,
|
||||
TextField,
|
||||
View,
|
||||
} from "react-native-ui-lib";
|
||||
import {ScrollView, TouchableOpacity} from "react-native-gesture-handler";
|
||||
import {useSafeAreaInsets} from "react-native-safe-area-context";
|
||||
import {useState} from "react";
|
||||
import {MaterialIcons} from "@expo/vector-icons";
|
||||
import {PickerMultiValue} from "react-native-ui-lib/src/components/picker/types";
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import {useCreateEvent} from "@/hooks/firebase/useCreateEvent";
|
||||
import {EventData} from "@/hooks/firebase/types/eventData";
|
||||
import { ScrollView, TouchableOpacity } from "react-native-gesture-handler";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { useState } from "react";
|
||||
import { MaterialIcons } from "@expo/vector-icons";
|
||||
import { PickerMultiValue } from "react-native-ui-lib/src/components/picker/types";
|
||||
import { useAuthContext } from "@/contexts/AuthContext";
|
||||
import { useCreateEvent } from "@/hooks/firebase/useCreateEvent";
|
||||
import { EventData } from "@/hooks/firebase/types/eventData";
|
||||
|
||||
const daysOfWeek = [
|
||||
{label: "Monday", value: "monday"},
|
||||
{label: "Tuesday", value: "tuesday"},
|
||||
{label: "Wednesday", value: "wednesday"},
|
||||
{label: "Thursday", value: "thursday"},
|
||||
{label: "Friday", value: "friday"},
|
||||
{label: "Saturday", value: "saturday"},
|
||||
{label: "Sunday", value: "sunday"},
|
||||
{ label: "Monday", value: "monday" },
|
||||
{ label: "Tuesday", value: "tuesday" },
|
||||
{ label: "Wednesday", value: "wednesday" },
|
||||
{ label: "Thursday", value: "thursday" },
|
||||
{ label: "Friday", value: "friday" },
|
||||
{ label: "Saturday", value: "saturday" },
|
||||
{ label: "Sunday", value: "sunday" },
|
||||
];
|
||||
|
||||
export const ManuallyAddEventModal = ({show, close}: { show: boolean, close: () => void }) => {
|
||||
const {user} = useAuthContext()
|
||||
const insets = useSafeAreaInsets();
|
||||
export const ManuallyAddEventModal = ({
|
||||
show,
|
||||
close,
|
||||
}: {
|
||||
show: boolean;
|
||||
close: () => void;
|
||||
}) => {
|
||||
const { user } = useAuthContext();
|
||||
const insets = useSafeAreaInsets();
|
||||
|
||||
const [title, setTitle] = useState<string>("");
|
||||
const [title, setTitle] = useState<string>("");
|
||||
|
||||
const [isAllDay, setIsAllDay] = useState(false);
|
||||
const [startTime, setStartTime] = useState(new Date());
|
||||
const [endTime, setEndTime] = useState(new Date())
|
||||
const [isAllDay, setIsAllDay] = useState(false);
|
||||
const [startTime, setStartTime] = useState(new Date());
|
||||
const [endTime, setEndTime] = useState(new Date());
|
||||
|
||||
const [startDate, setStartDate] = useState(new Date());
|
||||
const [endDate, setEndDate] = useState(new Date())
|
||||
const [startDate, setStartDate] = useState(new Date());
|
||||
const [endDate, setEndDate] = useState(new Date());
|
||||
|
||||
const [repeatInterval, setRepeatInterval] = useState<PickerMultiValue>([]);
|
||||
const [repeatInterval, setRepeatInterval] = useState<PickerMultiValue>([]);
|
||||
|
||||
const {mutateAsync: createEvent, isLoading, isError} = useCreateEvent()
|
||||
const { mutateAsync: createEvent, isLoading, isError } = useCreateEvent();
|
||||
|
||||
const formatDateTime = (date: Date) => {
|
||||
return date.toLocaleDateString('en-US', {
|
||||
weekday: 'long',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
});
|
||||
};
|
||||
const formatDateTime = (date: Date) => {
|
||||
return date.toLocaleDateString("en-US", {
|
||||
weekday: "long",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
});
|
||||
};
|
||||
|
||||
const combineDateAndTime = (date: Date, time: Date): Date => {
|
||||
const combined = new Date(date);
|
||||
combined.setHours(time.getHours());
|
||||
combined.setMinutes(time.getMinutes());
|
||||
combined.setSeconds(0);
|
||||
combined.setMilliseconds(0);
|
||||
return combined;
|
||||
};
|
||||
const combineDateAndTime = (date: Date, time: Date): Date => {
|
||||
const combined = new Date(date);
|
||||
combined.setHours(time.getHours());
|
||||
combined.setMinutes(time.getMinutes());
|
||||
combined.setSeconds(0);
|
||||
combined.setMilliseconds(0);
|
||||
return combined;
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
let finalStartDate: Date;
|
||||
let finalEndDate: Date;
|
||||
const handleSave = async () => {
|
||||
let finalStartDate: Date;
|
||||
let finalEndDate: Date;
|
||||
|
||||
if (isAllDay) {
|
||||
finalStartDate = new Date(startDate);
|
||||
finalStartDate.setHours(0, 0, 0, 0);
|
||||
if (isAllDay) {
|
||||
finalStartDate = new Date(startDate);
|
||||
finalStartDate.setHours(0, 0, 0, 0);
|
||||
|
||||
finalEndDate = new Date(startDate);
|
||||
finalEndDate.setHours(23, 59, 59, 999);
|
||||
} else {
|
||||
finalStartDate = combineDateAndTime(startDate, startTime);
|
||||
finalEndDate = combineDateAndTime(endDate, endTime);
|
||||
}
|
||||
|
||||
const eventData: Partial<EventData> = {
|
||||
title,
|
||||
startDate: finalStartDate,
|
||||
endDate: finalEndDate,
|
||||
repeatDays: repeatInterval.map(x => x.toString()),
|
||||
allDay: isAllDay
|
||||
};
|
||||
|
||||
await createEvent(eventData)
|
||||
|
||||
close();
|
||||
};
|
||||
|
||||
const getRepeatLabel = () => {
|
||||
const selectedDays = repeatInterval
|
||||
const allDays = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
||||
const workDays = ["monday", "tuesday", "wednesday", "thursday", "friday"];
|
||||
|
||||
const isEveryWorkDay = workDays.every(day => selectedDays.includes(day));
|
||||
|
||||
const isEveryDay = allDays.every(day => selectedDays.includes(day));
|
||||
|
||||
if (isEveryDay) {
|
||||
return "Every day";
|
||||
} else if (isEveryWorkDay && !selectedDays.includes("saturday") && !selectedDays.includes("sunday")) {
|
||||
return "Every work day";
|
||||
} else {
|
||||
return selectedDays
|
||||
.map(item => daysOfWeek.find(day => day.value === item)?.label)
|
||||
.join(", ");
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading && !isError) {
|
||||
return (
|
||||
<Modal
|
||||
visible={show}
|
||||
animationType="slide"
|
||||
onRequestClose={close}
|
||||
transparent={false}
|
||||
>
|
||||
<LoaderScreen message={'Saving event...'} color={Colors.grey40}/>
|
||||
</Modal>
|
||||
)
|
||||
finalEndDate = new Date(startDate);
|
||||
finalEndDate.setHours(23, 59, 59, 999);
|
||||
} else {
|
||||
finalStartDate = combineDateAndTime(startDate, startTime);
|
||||
finalEndDate = combineDateAndTime(endDate, endTime);
|
||||
}
|
||||
|
||||
const eventData: Partial<EventData> = {
|
||||
title,
|
||||
startDate: finalStartDate,
|
||||
endDate: finalEndDate,
|
||||
repeatDays: repeatInterval.map((x) => x.toString()),
|
||||
allDay: isAllDay,
|
||||
};
|
||||
|
||||
await createEvent(eventData);
|
||||
|
||||
close();
|
||||
};
|
||||
|
||||
const getRepeatLabel = () => {
|
||||
const selectedDays = repeatInterval;
|
||||
const allDays = [
|
||||
"sunday",
|
||||
"monday",
|
||||
"tuesday",
|
||||
"wednesday",
|
||||
"thursday",
|
||||
"friday",
|
||||
"saturday",
|
||||
];
|
||||
const workDays = ["monday", "tuesday", "wednesday", "thursday", "friday"];
|
||||
|
||||
const isEveryWorkDay = workDays.every((day) => selectedDays.includes(day));
|
||||
|
||||
const isEveryDay = allDays.every((day) => selectedDays.includes(day));
|
||||
|
||||
if (isEveryDay) {
|
||||
return "Every day";
|
||||
} else if (
|
||||
isEveryWorkDay &&
|
||||
!selectedDays.includes("saturday") &&
|
||||
!selectedDays.includes("sunday")
|
||||
) {
|
||||
return "Every work day";
|
||||
} else {
|
||||
return selectedDays
|
||||
.map((item) => daysOfWeek.find((day) => day.value === item)?.label)
|
||||
.join(", ");
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading && !isError) {
|
||||
return (
|
||||
<Modal
|
||||
visible={show}
|
||||
animationType="slide"
|
||||
onRequestClose={close}
|
||||
transparent={false}
|
||||
>
|
||||
<View style={{
|
||||
flex: 1,
|
||||
backgroundColor: "#fff",
|
||||
paddingTop: insets.top, // Safe area inset for top
|
||||
paddingBottom: insets.bottom, // Safe area inset for bottom
|
||||
paddingLeft: insets.left, // Safe area inset for left
|
||||
paddingRight: insets.right, // Safe area inset for right
|
||||
}}>
|
||||
<View style={{flexDirection: "row", justifyContent: "space-between", padding: 16}}>
|
||||
<TouchableOpacity onPress={close}>
|
||||
<Text style={{color: "#007bff"}}>Cancel</Text>
|
||||
</TouchableOpacity>
|
||||
<Text style={{fontWeight: "bold", fontSize: 16}}>Add event</Text>
|
||||
<TouchableOpacity onPress={handleSave}>
|
||||
<Text style={{color: "#007bff"}}>Save</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
<ScrollView contentContainerStyle={{paddingHorizontal: 16, paddingTop: 10}}>
|
||||
<View style={{marginVertical: 10}}>
|
||||
<TextField
|
||||
placeholder={'Title'}
|
||||
floatingPlaceholder
|
||||
value={title}
|
||||
onChangeText={setTitle}
|
||||
showCharCounter
|
||||
maxLength={200}
|
||||
fieldStyle={{
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: 'black',
|
||||
borderStyle: 'solid',
|
||||
}}
|
||||
/>
|
||||
|
||||
</View>
|
||||
|
||||
<View style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: 20
|
||||
}}>
|
||||
<View style={{flexDirection: "row", alignItems: "center"}}>
|
||||
<MaterialIcons name="schedule" size={24} color="gray"/>
|
||||
<Text style={{marginLeft: 10}}>All-day</Text>
|
||||
</View>
|
||||
<Switch
|
||||
value={isAllDay}
|
||||
onValueChange={(value) => setIsAllDay(value)}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: 20
|
||||
}}>
|
||||
<DateTimePicker
|
||||
mode="date"
|
||||
dateFormatter={formatDateTime}
|
||||
value={startDate}
|
||||
onChange={setStartDate}
|
||||
/>
|
||||
{!isAllDay && (
|
||||
<DateTimePicker
|
||||
mode="time"
|
||||
value={startTime}
|
||||
onChange={setStartTime}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{!isAllDay && (
|
||||
<View style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: 20
|
||||
}}>
|
||||
<DateTimePicker
|
||||
mode="date"
|
||||
dateFormatter={formatDateTime}
|
||||
value={endDate}
|
||||
onChange={setEndDate}
|
||||
/>
|
||||
<DateTimePicker
|
||||
mode="time"
|
||||
value={endTime}
|
||||
onChange={setEndTime}
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
|
||||
<View style={{flexDirection: "row", alignItems: "center", marginBottom: 20}}>
|
||||
<MaterialIcons name="repeat" size={24} color="gray"/>
|
||||
<Picker
|
||||
value={repeatInterval}
|
||||
//@ts-ignore
|
||||
onChange={(items: PickerMultiValue) => setRepeatInterval(items)}
|
||||
placeholder="Doest not repeat"
|
||||
style={{marginLeft: 10, flex: 1}}
|
||||
mode={Picker.modes.MULTI}
|
||||
getLabel={getRepeatLabel}
|
||||
|
||||
>
|
||||
{daysOfWeek.map((option) => (
|
||||
<Picker.Item key={option.value} label={option.label} value={option.value}/>
|
||||
))}
|
||||
</Picker>
|
||||
</View>
|
||||
|
||||
<View style={{flexDirection: "row", alignItems: "center", marginBottom: 20}}>
|
||||
<MaterialIcons name="person-add" size={24} color="gray"/>
|
||||
<TouchableOpacity style={{marginLeft: 10, flexDirection: "row", alignItems: "center", flex: 1}}>
|
||||
<Avatar size={40} backgroundColor={Colors.yellow10}/>
|
||||
<View style={{marginLeft: 10}}>
|
||||
<Text>Other</Text>
|
||||
<Text style={{color: "gray"}}>{user?.email}</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</View>
|
||||
</Modal>
|
||||
<Modal
|
||||
visible={show}
|
||||
animationType="slide"
|
||||
onRequestClose={close}
|
||||
transparent={false}
|
||||
>
|
||||
<LoaderScreen message={"Saving event..."} color={Colors.grey40} />
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={show}
|
||||
animationType="slide"
|
||||
onRequestClose={close}
|
||||
transparent={false}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
backgroundColor: "#fff",
|
||||
paddingTop: insets.top, // Safe area inset for top
|
||||
paddingBottom: insets.bottom, // Safe area inset for bottom
|
||||
paddingLeft: insets.left, // Safe area inset for left
|
||||
paddingRight: insets.right, // Safe area inset for right
|
||||
}}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
padding: 16,
|
||||
}}
|
||||
>
|
||||
<TouchableOpacity onPress={close}>
|
||||
<Text style={{ color: "#007bff" }}>Cancel</Text>
|
||||
</TouchableOpacity>
|
||||
<Text style={{ fontWeight: "bold", fontSize: 16 }}>Add event</Text>
|
||||
<TouchableOpacity onPress={handleSave}>
|
||||
<Text style={{ color: "#007bff" }}>Save</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
<ScrollView
|
||||
contentContainerStyle={{ paddingHorizontal: 16, paddingTop: 10 }}
|
||||
>
|
||||
<View style={{ marginVertical: 10 }}>
|
||||
<TextField
|
||||
placeholder={"Title"}
|
||||
floatingPlaceholder
|
||||
value={title}
|
||||
onChangeText={setTitle}
|
||||
showCharCounter
|
||||
maxLength={200}
|
||||
fieldStyle={{
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: "black",
|
||||
borderStyle: "solid",
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: 20,
|
||||
}}
|
||||
>
|
||||
<View style={{ flexDirection: "row", alignItems: "center" }}>
|
||||
<MaterialIcons name="schedule" size={24} color="gray" />
|
||||
<Text style={{ marginLeft: 10 }}>All-day</Text>
|
||||
</View>
|
||||
<Switch
|
||||
value={isAllDay}
|
||||
onValueChange={(value) => setIsAllDay(value)}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: 20,
|
||||
}}
|
||||
>
|
||||
<DateTimePicker
|
||||
mode="date"
|
||||
dateFormatter={formatDateTime}
|
||||
value={startDate}
|
||||
onChange={setStartDate}
|
||||
display="default"
|
||||
/>
|
||||
{!isAllDay && (
|
||||
<DateTimePicker
|
||||
mode="time"
|
||||
value={startTime}
|
||||
onChange={setStartTime}
|
||||
display="spinner"
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{!isAllDay && (
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: 20,
|
||||
}}
|
||||
>
|
||||
<DateTimePicker
|
||||
mode="date"
|
||||
dateFormatter={formatDateTime}
|
||||
value={endDate}
|
||||
onChange={setEndDate}
|
||||
display="default"
|
||||
/>
|
||||
<DateTimePicker
|
||||
mode="time"
|
||||
value={endTime}
|
||||
onChange={setEndTime}
|
||||
minuteInterval={1}
|
||||
display="spinner"
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
marginBottom: 20,
|
||||
}}
|
||||
>
|
||||
<MaterialIcons name="repeat" size={24} color="gray" />
|
||||
<Picker
|
||||
value={repeatInterval}
|
||||
//@ts-ignore
|
||||
onChange={(items: PickerMultiValue) => setRepeatInterval(items)}
|
||||
placeholder="Doest not repeat"
|
||||
style={{ marginLeft: 10, flex: 1 }}
|
||||
mode={Picker.modes.MULTI}
|
||||
getLabel={getRepeatLabel}
|
||||
>
|
||||
{daysOfWeek.map((option) => (
|
||||
<Picker.Item
|
||||
key={option.value}
|
||||
label={option.label}
|
||||
value={option.value}
|
||||
/>
|
||||
))}
|
||||
</Picker>
|
||||
</View>
|
||||
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
marginBottom: 20,
|
||||
}}
|
||||
>
|
||||
<MaterialIcons name="person-add" size={24} color="gray" />
|
||||
<TouchableOpacity
|
||||
style={{
|
||||
marginLeft: 10,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
<Avatar size={40} backgroundColor={Colors.yellow10} />
|
||||
<View style={{ marginLeft: 10 }}>
|
||||
<Text>Other</Text>
|
||||
<Text style={{ color: "gray" }}>{user?.email}</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</View>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
@ -1,28 +1,60 @@
|
||||
import { View, Text } from 'react-native'
|
||||
import React from 'react'
|
||||
import { TextField } from 'react-native-ui-lib'
|
||||
import CategoryDropdown from './CategoryDropdown'
|
||||
import { GroceryCategory } from '@/contexts/GroceryContext'
|
||||
import { View, Text } from "react-native";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { TextField } from "react-native-ui-lib";
|
||||
import {
|
||||
GroceryCategory,
|
||||
IGrocery,
|
||||
useGroceryContext,
|
||||
} from "@/contexts/GroceryContext";
|
||||
import { TouchableWithoutFeedback } from "react-native-gesture-handler";
|
||||
|
||||
const EditGroceryItem = (props: {title: string, setTitle: (value: string) => void, setCategory: (category: GroceryCategory) => void}) => {
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
backgroundColor: "white",
|
||||
width: "100%",
|
||||
borderRadius: 25,
|
||||
padding: 15,
|
||||
}}
|
||||
>
|
||||
<TextField
|
||||
placeholder="Grocery"
|
||||
value={props.title}
|
||||
onChangeText={(value) => props.setTitle(value)}
|
||||
maxLength={25}
|
||||
/>
|
||||
<CategoryDropdown setSelectedCategory={props.setCategory} />
|
||||
</View>
|
||||
)
|
||||
interface IEditGrocery {
|
||||
id?: number;
|
||||
title: string;
|
||||
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;
|
||||
}
|
||||
|
||||
export default EditGroceryItem
|
||||
const EditGroceryItem = ({ editGrocery }: { editGrocery: IEditGrocery }) => {
|
||||
const { fuzzyMatchGroceryCategory } = useGroceryContext();
|
||||
|
||||
useEffect(() => {
|
||||
if (editGrocery.setCategory)
|
||||
editGrocery.setCategory(fuzzyMatchGroceryCategory(editGrocery.title));
|
||||
}, [editGrocery.title]);
|
||||
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
backgroundColor: "white",
|
||||
width: "100%",
|
||||
borderRadius: 25,
|
||||
padding: 15,
|
||||
}}
|
||||
>
|
||||
<TextField
|
||||
placeholder="Grocery"
|
||||
value={editGrocery.title}
|
||||
onChangeText={(value) => {
|
||||
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
|
||||
});
|
||||
}}
|
||||
maxLength={25}
|
||||
/>
|
||||
<Text>{editGrocery.category}</Text>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default EditGroceryItem;
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
import EditGroceryFrequency from "./EditGroceryFrequency";
|
||||
import { TextInput } from "react-native";
|
||||
import EditGroceryItem from "./EditGroceryItem";
|
||||
import { TouchableWithoutFeedback } from "react-native-gesture-handler";
|
||||
|
||||
const GroceryItem = ({
|
||||
item,
|
||||
@ -31,6 +32,7 @@ const GroceryItem = ({
|
||||
const [openFreqEdit, setOpenFreqEdit] = useState<boolean>(false);
|
||||
const [isEditingTitle, setIsEditingTitle] = useState<boolean>(false);
|
||||
const [newTitle, setNewTitle] = useState<string>("");
|
||||
const [category, setCategory] = useState<GroceryCategory>(GroceryCategory.None);
|
||||
|
||||
const handleTitleChange = (newTitle: string) => {
|
||||
updateGroceryItem(item.id, { title: newTitle });
|
||||
@ -46,6 +48,7 @@ const GroceryItem = ({
|
||||
|
||||
return (
|
||||
<ListItem
|
||||
key={item.id}
|
||||
style={{ borderRadius: 50, marginVertical: 5, height: 55 }}
|
||||
backgroundColor="white"
|
||||
centerV
|
||||
@ -63,49 +66,24 @@ const GroceryItem = ({
|
||||
}}
|
||||
/>
|
||||
<ListItem.Part left containerStyle={{ flex: 1, paddingStart: 20 }}>
|
||||
{/* <View
|
||||
height={50}
|
||||
width={50}
|
||||
style={{ borderRadius: 15 }}
|
||||
backgroundColor="#e6f1ed"
|
||||
marginR-10
|
||||
children={
|
||||
<MaterialCommunityIcons
|
||||
name={iconMapping[item.category]}
|
||||
size={50}
|
||||
color="orange"
|
||||
/>
|
||||
}
|
||||
/>*/}
|
||||
{!isEditingTitle ? (
|
||||
<View>
|
||||
<TouchableOpacity onPress={() => setIsEditingTitle(true)}>
|
||||
<Text text70BL>{item.title}</Text>
|
||||
</TouchableOpacity>
|
||||
{ /*
|
||||
<TextInput
|
||||
value={item.title}
|
||||
onChangeText={handleTitleChange}
|
||||
onBlur={() => {
|
||||
setIsEditingTitle(false);
|
||||
console.log(groceries);
|
||||
}}
|
||||
autoFocus
|
||||
style={{
|
||||
fontSize: 16,
|
||||
padding: 0,
|
||||
margin: 0,
|
||||
fontWeight: "bold",
|
||||
}}
|
||||
/>
|
||||
*/}
|
||||
</View>
|
||||
) : (
|
||||
<EditGroceryItem
|
||||
title={item.title}
|
||||
setTitle={handleTitleChange}
|
||||
setCategory={handleCategoryChange}
|
||||
/>
|
||||
<EditGroceryItem
|
||||
editGrocery={{
|
||||
id: item.id,
|
||||
title: newTitle,
|
||||
setTitle: setNewTitle,
|
||||
category:category,
|
||||
updateCategory: updateGroceryItem,
|
||||
closeEdit: setIsEditingTitle,
|
||||
setCategory: setCategory,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</ListItem.Part>
|
||||
<ListItem.Part right containerStyle={{ paddingEnd: 20 }}>
|
||||
|
@ -31,6 +31,7 @@ const GroceryList = () => {
|
||||
GroceryCategory.Bakery
|
||||
);
|
||||
const [title, setTitle] = useState<string>("");
|
||||
const [submit, setSubmitted] = useState<boolean>(false);
|
||||
|
||||
// Group approved groceries by category
|
||||
const approvedGroceriesByCategory = approvedGroceries.reduce(
|
||||
@ -46,19 +47,27 @@ const GroceryList = () => {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (title?.length > 2 && title?.length <= 25) {
|
||||
addGrocery({
|
||||
id: 0,
|
||||
title: title,
|
||||
category: category,
|
||||
approved: false,
|
||||
recurring: false,
|
||||
frequency: GroceryFrequency.Never,
|
||||
bought: false,
|
||||
});
|
||||
|
||||
setIsAddingGrocery(false);
|
||||
if(submit){
|
||||
if (title?.length > 2 && title?.length <= 25) {
|
||||
addGrocery({
|
||||
id: 0,
|
||||
title: title,
|
||||
category: category,
|
||||
approved: false,
|
||||
recurring: false,
|
||||
frequency: GroceryFrequency.Never,
|
||||
bought: false,
|
||||
});
|
||||
|
||||
setIsAddingGrocery(false);
|
||||
setSubmitted(false);
|
||||
setTitle("");
|
||||
}
|
||||
}
|
||||
}, [submit]);
|
||||
|
||||
useEffect(() => {
|
||||
/**/
|
||||
}, [category]);
|
||||
|
||||
useEffect(() => {
|
||||
@ -67,7 +76,7 @@ const GroceryList = () => {
|
||||
}, [groceries]);
|
||||
|
||||
return (
|
||||
<View marginH-20>
|
||||
<View marginH-20 marginB-20>
|
||||
<HeaderTemplate
|
||||
message={"Welcome to your grocery list"}
|
||||
isWelcome={false}
|
||||
@ -101,8 +110,8 @@ const GroceryList = () => {
|
||||
</Text>
|
||||
</View>
|
||||
<Button
|
||||
backgroundColor='transparent'
|
||||
paddingH-10
|
||||
backgroundColor="transparent"
|
||||
paddingH-10
|
||||
iconSource={() => (
|
||||
<MaterialIcons name="person-add-alt" size={24} color="gray" />
|
||||
)}
|
||||
@ -157,7 +166,15 @@ const GroceryList = () => {
|
||||
</View>
|
||||
</View>
|
||||
{isAddingGrocery && (
|
||||
<EditGroceryItem title={title} setTitle={setTitle} setCategory={setCategory} />
|
||||
<EditGroceryItem
|
||||
editGrocery={{
|
||||
title: title,
|
||||
setCategory: setCategory,
|
||||
category: category,
|
||||
setTitle: setTitle,
|
||||
setSubmit: setSubmitted
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Render Approved Groceries Grouped by Category */}
|
||||
|
@ -1,7 +1,12 @@
|
||||
import { View, Text, TouchableOpacity } from "react-native-ui-lib";
|
||||
import React, { useState } from "react";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { ScrollView, StyleSheet } from "react-native";
|
||||
import {
|
||||
KeyboardAvoidingView,
|
||||
Platform,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
} from "react-native";
|
||||
import MyProfile from "./user_settings_views/MyProfile";
|
||||
import MyGroup from "./user_settings_views/MyGroup";
|
||||
import { useAuthContext } from "@/contexts/AuthContext";
|
||||
@ -9,51 +14,57 @@ import { useAuthContext } from "@/contexts/AuthContext";
|
||||
const UserSettings = (props: { setSelectedPage: (page: number) => void }) => {
|
||||
const [selectedView, setSelectedView] = useState<boolean>(true);
|
||||
return (
|
||||
<View>
|
||||
<ScrollView>
|
||||
<TouchableOpacity onPress={() => props.setSelectedPage(0)}>
|
||||
<View row marginT-20 marginL-20 marginB-35 centerV>
|
||||
<Ionicons name="chevron-back" size={22} color="#979797" />
|
||||
<Text text70 color="#979797">
|
||||
Return to main settings
|
||||
<ScrollView
|
||||
contentContainerStyle={{ flexGrow: 1 }}
|
||||
>
|
||||
<View style={{ flex: 1 }}>
|
||||
<TouchableOpacity onPress={() => props.setSelectedPage(0)}>
|
||||
<View row marginT-20 marginL-20 marginB-35 centerV>
|
||||
<Ionicons name="chevron-back" size={22} color="#979797" />
|
||||
<Text text70 color="#979797">
|
||||
Return to main settings
|
||||
</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
<View marginH-20>
|
||||
<Text text60R marginB-25>
|
||||
User Management
|
||||
</Text>
|
||||
<View style={styles.buttonSwitch} spread row>
|
||||
<TouchableOpacity
|
||||
onPress={() => setSelectedView(true)}
|
||||
centerV
|
||||
centerH
|
||||
style={
|
||||
selectedView == true ? styles.btnSelected : styles.btnNot
|
||||
}
|
||||
>
|
||||
<View>
|
||||
<Text text70 color={selectedView ? "white" : "black"}>
|
||||
My Profile
|
||||
</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
onPress={() => setSelectedView(false)}
|
||||
centerV
|
||||
centerH
|
||||
style={
|
||||
selectedView == false ? styles.btnSelected : styles.btnNot
|
||||
}
|
||||
>
|
||||
<View>
|
||||
<Text text70 color={!selectedView ? "white" : "black"}>
|
||||
My Group
|
||||
</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
{selectedView && <MyProfile />}
|
||||
{!selectedView && <MyGroup />}
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
<View marginH-20>
|
||||
<Text text60R marginB-25>
|
||||
User Management
|
||||
</Text>
|
||||
<View style={styles.buttonSwitch} spread row>
|
||||
<TouchableOpacity
|
||||
onPress={() => setSelectedView(true)}
|
||||
centerV
|
||||
centerH
|
||||
style={selectedView == true ? styles.btnSelected : styles.btnNot}
|
||||
>
|
||||
<View>
|
||||
<Text text70 color={selectedView ? "white" : "black"}>
|
||||
My Profile
|
||||
</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
onPress={() => setSelectedView(false)}
|
||||
centerV
|
||||
centerH
|
||||
style={selectedView == false ? styles.btnSelected : styles.btnNot}
|
||||
>
|
||||
<View>
|
||||
<Text text70 color={!selectedView ? "white" : "black"}>
|
||||
My Group
|
||||
</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
{selectedView && <MyProfile />}
|
||||
{!selectedView && <MyGroup />}
|
||||
</View>
|
||||
</ScrollView>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -2,8 +2,10 @@ import { View, Text, Button } from "react-native-ui-lib";
|
||||
import React from "react";
|
||||
import { Fontisto } from "@expo/vector-icons";
|
||||
import { ProgressBar } from "react-native-ui-lib/src/components/progressBar";
|
||||
import { useToDosContext } from "@/contexts/ToDosContext";
|
||||
|
||||
const ProgressCard = () => {
|
||||
const { maxPoints } = useToDosContext();
|
||||
return (
|
||||
<View
|
||||
backgroundColor="white"
|
||||
@ -30,12 +32,10 @@ const ProgressCard = () => {
|
||||
/>
|
||||
<View row spread>
|
||||
<Text color={"#868686"}>0</Text>
|
||||
<Text color={"#868686"}>1000</Text>
|
||||
<Text color={"#868686"}>{maxPoints}</Text>
|
||||
</View>
|
||||
<View centerV centerH>
|
||||
<Button
|
||||
backgroundColor="transparent"
|
||||
>
|
||||
<Button backgroundColor="transparent">
|
||||
<Text style={{ textDecorationLine: "underline", color: "#05a8b6" }}>
|
||||
View your full progress report here
|
||||
</Text>
|
||||
|
Reference in New Issue
Block a user