mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
add To Dos
This commit is contained in:
59
contexts/ToDosContext.tsx
Normal file
59
contexts/ToDosContext.tsx
Normal file
@ -0,0 +1,59 @@
|
||||
import { createContext, FC, ReactNode, useContext, useState } from "react";
|
||||
export interface IToDo {
|
||||
id: number;
|
||||
title: string;
|
||||
done: boolean;
|
||||
date: Date;
|
||||
points?: number;
|
||||
}
|
||||
interface IToDosContext {
|
||||
toDos: IToDo[];
|
||||
updateToDo: (id: number, changes: Partial<IToDo>) => void;
|
||||
}
|
||||
|
||||
const ToDosContext = createContext<IToDosContext>(undefined!);
|
||||
|
||||
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: 3,
|
||||
title: "Dressup: Cat",
|
||||
done: false,
|
||||
date: new Date(Date.now() + 86400000),
|
||||
points: 40,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: "Trim: Nails",
|
||||
done: false,
|
||||
date: new Date(Date.now() + 86400000),
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
title: "Monthly Log",
|
||||
done: false,
|
||||
date: new Date(Date.now() + 2 * 86400000),
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
title: "Do it",
|
||||
done: false,
|
||||
date: new Date(Date.now() + 3 * 86400000),
|
||||
},
|
||||
]);
|
||||
|
||||
const updateToDo = (id: number, changes: Partial<IToDo>) => {};
|
||||
|
||||
return (
|
||||
<ToDosContext.Provider value={{ toDos, updateToDo }}>
|
||||
{children}
|
||||
</ToDosContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useToDosContext = () => useContext(ToDosContext)!;
|
||||
Reference in New Issue
Block a user