"use client" import { useState, useEffect } from "react" import { JournalEntry, JournalEntryLists } from "@/lib/schema/journal" import { useAccount } from "@/lib/providers/jazz-provider" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { calendarFormatDate } from "@/lib/utils" import { Calendar } from "@/components/ui/calendar" export function JournalRoute() { const [date, setDate] = useState(new Date()) const { me } = useAccount({ root: { journalEntries: [] } }) const [newNote, setNewNote] = useState(null) const notes = me?.root?.journalEntries || (me ? JournalEntryLists.create([], { owner: me }) : []) useEffect(() => { console.log("me:", me) }, [me]) const selectDate = (selectedDate: Date | undefined) => { if (selectedDate) { setDate(selectedDate) } } const createNewNote = () => { if (me) { const newEntry = JournalEntry.create( { title: "", content: "", date: date, createdAt: new Date(), updatedAt: new Date() }, { owner: me._owner } ) setNewNote(newEntry) } } const handleNewNoteChange = (field: keyof JournalEntry, value: string) => { if (newNote) { setNewNote(prevNote => { if (prevNote) { return JournalEntry.create({ ...prevNote, [field]: value }, { owner: me!._owner }) } return prevNote }) } } const saveNewNote = () => { if (newNote && me?.root?.journalEntries) { me.root.journalEntries.push(newNote) setNewNote(null) } } return (
{newNote ? (
handleNewNoteChange("title", e.target.value)} className="mb-2 w-full text-xl font-semibold" />