'use client'; import { redirect } from "next/navigation"; import { Separator } from "@/components/ui/separator"; import { ZDay } from "@lifetracker/shared/types/days"; import { EditableHourCode } from "../hours/EditableHourCode"; import { getHourFromTime } from "@lifetracker/shared/utils/hours"; import Link from "next/link"; import { cn } from "@/lib/utils"; import { ArrowLeftSquare, ArrowRightSquare } from "lucide-react"; import spacetime from "spacetime"; import EditableHour from "@/components/dashboard/hours/EditableHour"; import { useUpdateHour } from "@lifetracker/shared-react/hooks/days"; import { useState } from "react"; export default function TimelineView({ days: initialDays, }: { days: ZDay[]; }) { // Hacky, but it works // Remove "container" class from parent div const parent = document.querySelector(".container"); if (parent) { parent.classList.remove("container"); } const [days, setDays] = useState(initialDays); const { mutate: updateHour, isPending } = useUpdateHour({ onSuccess: (res, req, meta) => { const hourDay = days.find(day => day.date === req.date); // Replace the relevant hour within hourDay hourDay.hours[req.i] = res; // Place the new hourDay within the days array setDays([...days]); }, }); return ( <>
DATE
DAY
{Array.from({ length: 24 }, (_, i) => (
{getHourFromTime(i, "all")}
))}
{ days.map((day, index) => (
0 ? "bg-white text-black" : "" )}> {spacetime(day.date).format("{iso-month}/{date-pad}")}
0 ? "bg-white text-black" : "" )}> {spacetime(day.date).format("{day-short}")}
{day.hours.map((hour, i) => ( //
// {hour.categoryCode ?? "_"} //
))}
)) } ); }