feat: save tasks in localstorage
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import Task from "@/components/task";
|
import Task from "@/components/task";
|
||||||
|
|
||||||
import Button from "@/components/ui/Button";
|
import Button from "@/components/ui/Button";
|
||||||
import ModalWindow from "@/components/ui/Modal";
|
import ModalWindow from "@/components/ui/Modal";
|
||||||
import { withTitle } from "@/constructors/Component";
|
import { withTitle } from "@/constructors/Component";
|
||||||
@@ -14,7 +15,7 @@ import {
|
|||||||
PencilIcon,
|
PencilIcon,
|
||||||
} from "@heroicons/react/24/outline";
|
} from "@heroicons/react/24/outline";
|
||||||
import { FunctionComponent } from "preact";
|
import { FunctionComponent } from "preact";
|
||||||
import { useMemo, useRef, useState } from "preact/hooks";
|
import { useEffect, useMemo, useRef, useState } from "preact/hooks";
|
||||||
import { ITask } from "./profile_tasks.dto";
|
import { ITask } from "./profile_tasks.dto";
|
||||||
import classes from "./profile_tasks.module.scss";
|
import classes from "./profile_tasks.module.scss";
|
||||||
|
|
||||||
@@ -51,7 +52,16 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
const formatter = new Intl.DateTimeFormat("ru-RU", { month: "long", day: "numeric" });
|
const formatter = new Intl.DateTimeFormat("ru-RU", { month: "long", day: "numeric" });
|
||||||
return formatter.format(date);
|
return formatter.format(date);
|
||||||
}, []);
|
}, []);
|
||||||
const [tasks, setTasks] = useState(example_tasks);
|
const init_tasks: ITask[] = localStorage.getItem("tasks")
|
||||||
|
? JSON.parse(localStorage.getItem("tasks") as string)
|
||||||
|
: example_tasks;
|
||||||
|
init_tasks.forEach((task) => {
|
||||||
|
task.date = new Date(task.date);
|
||||||
|
});
|
||||||
|
const [tasks, setTasks] = useState<ITask[]>(init_tasks);
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem("tasks", JSON.stringify(tasks));
|
||||||
|
}, [tasks]);
|
||||||
const [openModal, setIsOpen] = useState(false);
|
const [openModal, setIsOpen] = useState(false);
|
||||||
const [isEdit, setIsEdit] = useState(false);
|
const [isEdit, setIsEdit] = useState(false);
|
||||||
const [isCreating, setIsCreating] = useState(false);
|
const [isCreating, setIsCreating] = useState(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user