changes to grocery, todos

This commit is contained in:
ivic00
2024-09-12 15:39:20 +02:00
parent 8d85cbdaad
commit 53f7118656
24 changed files with 643 additions and 208 deletions

View File

@ -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>

View File

@ -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>
);