mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
changes to grocery, todos
This commit is contained in:
@ -54,8 +54,8 @@ interface IGroceryContext {
|
||||
groceries: IGrocery[];
|
||||
iconMapping: { [key in GroceryCategory]: MaterialIconNames };
|
||||
updateGroceryItem: (id: number, changes: Partial<IGrocery>) => void;
|
||||
isShopping: boolean;
|
||||
setIsShopping: (value: boolean) => void;
|
||||
isAddingGrocery: boolean;
|
||||
setIsAddingGrocery: (value: boolean) => void;
|
||||
}
|
||||
|
||||
const GroceryContext = createContext<IGroceryContext | undefined>(undefined);
|
||||
@ -63,7 +63,7 @@ const GroceryContext = createContext<IGroceryContext | undefined>(undefined);
|
||||
export const GroceryProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
children,
|
||||
}) => {
|
||||
const [isShopping, setIsShopping] = useState<boolean>(false);
|
||||
const [isAddingGrocery, setIsAddingGrocery] = useState<boolean>(false);
|
||||
const [groceries, setGroceries] = useState<IGrocery[]>([
|
||||
{
|
||||
id: 0,
|
||||
@ -113,7 +113,7 @@ export const GroceryProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
|
||||
return (
|
||||
<GroceryContext.Provider
|
||||
value={{ groceries, iconMapping, updateGroceryItem, isShopping, setIsShopping }}
|
||||
value={{ groceries, iconMapping, updateGroceryItem, isAddingGrocery, setIsAddingGrocery }}
|
||||
>
|
||||
{children}
|
||||
</GroceryContext.Provider>
|
||||
|
||||
@ -5,10 +5,12 @@ export interface IToDo {
|
||||
done: boolean;
|
||||
date: Date;
|
||||
points?: number;
|
||||
rotate: boolean;
|
||||
}
|
||||
interface IToDosContext {
|
||||
toDos: IToDo[];
|
||||
updateToDo: (id: number, changes: Partial<IToDo>) => void;
|
||||
addToDo: (newToDo: IToDo) => void;
|
||||
}
|
||||
|
||||
const ToDosContext = createContext<IToDosContext>(undefined!);
|
||||
@ -17,40 +19,76 @@ export const ToDosContextProvider: FC<{ children: ReactNode }> = ({
|
||||
children,
|
||||
}) => {
|
||||
const [toDos, setToDos] = useState<IToDo[]>([
|
||||
{ id: 0, title: "Pay: Credit card", done: false, date: new Date() },
|
||||
{ id: 1, title: "Monthly Log story", done: false, date: new Date() },
|
||||
{ id: 2, title: "Write: Arcade Highlights", done: false, date: new Date() },
|
||||
{
|
||||
id: 0,
|
||||
title: "Pay: Credit card",
|
||||
done: false,
|
||||
date: new Date(),
|
||||
rotate: true,
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
title: "Monthly Log story",
|
||||
done: false,
|
||||
date: new Date(),
|
||||
rotate: false,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: "Write: Arcade Highlights",
|
||||
done: false,
|
||||
date: new Date(),
|
||||
rotate: true,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: "Dressup: Cat",
|
||||
done: false,
|
||||
date: new Date(Date.now() + 86400000),
|
||||
points: 40,
|
||||
rotate: false,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: "Trim: Nails",
|
||||
done: false,
|
||||
date: new Date(Date.now() + 86400000),
|
||||
rotate: false,
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
title: "Monthly Log",
|
||||
done: false,
|
||||
date: new Date(Date.now() + 2 * 86400000),
|
||||
rotate: true,
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
title: "Do it",
|
||||
done: false,
|
||||
date: new Date(Date.now() + 3 * 86400000),
|
||||
rotate: false,
|
||||
},
|
||||
]);
|
||||
|
||||
const updateToDo = (id: number, changes: Partial<IToDo>) => {};
|
||||
const updateToDo = (id: number, changes: Partial<IToDo>) => {
|
||||
setToDos((prevToDos) =>
|
||||
prevToDos.map((toDo) => (toDo.id === id ? { ...toDo, ...changes } : toDo))
|
||||
);
|
||||
};
|
||||
|
||||
const addToDo = (newToDo: IToDo) => {
|
||||
setToDos((prevToDos) => [
|
||||
...prevToDos,
|
||||
{
|
||||
...newToDo,
|
||||
id: prevToDos.length ? prevToDos[prevToDos.length - 1].id + 1 : 0,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<ToDosContext.Provider value={{ toDos, updateToDo }}>
|
||||
<ToDosContext.Provider value={{ toDos, updateToDo, addToDo }}>
|
||||
{children}
|
||||
</ToDosContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user