import Button from "@/components/ui/Button"; import { withTitle } from "@/constructors/Component"; import { UrlsTitle } from "@/enums/urls"; import { useAppContext } from "@/providers/AuthProvider"; import { cn } from "@/utils/class-merge"; import { calculatePoints, getCurrentStatus } from "@/utils/status-system"; import { ArrowRightStartOnRectangleIcon, Cog8ToothIcon } from "@heroicons/react/24/outline"; import { FunctionComponent } from "preact"; import { useLocation } from "preact-iso"; import { useEffect, useState } from "preact/hooks"; import classes from "./profile_settings.module.scss"; const ProfileSettings: FunctionComponent = () => { const { isLoggedIn } = useAppContext(); const { route } = useLocation(); const [status, setStatus] = useState(0); const maxStatus = 100; useEffect(() => { const updateStatus = () => { const tasks = JSON.parse(localStorage.getItem("tasks") || "[]"); const completedTasks = tasks.filter((task: { checked: boolean }) => task.checked).length; const points = calculatePoints(completedTasks); setStatus(points); }; // Initial update updateStatus(); // Update when tasks change const handleStorage = (e: StorageEvent) => { if (e.key === "tasks") { updateStatus(); } }; window.addEventListener("storage", handleStorage); return () => window.removeEventListener("storage", handleStorage); }, []); return (
Никнейм
{getCurrentStatus(status)}