"use client"; import { useState } from "react"; import { useLiveQuery } from "dexie-react-hooks"; import { v4 as uuidv4 } from "uuid"; import { analyzeJournalWithLocalAI } from "@/lib/ai"; import { db } from "@/lib/db"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; const moods = [ { id: "happy", label: "Mutlu", emoji: "😊" }, { id: "neutral", label: "Nötr", emoji: "😐" }, { id: "sad", label: "Üzgün", emoji: "😔" }, { id: "angry", label: "Sinirli", emoji: "😠" }, ]; export default function JournalPage() { const [content, setContent] = useState(""); const [mood, setMood] = useState("happy"); const [energy, setEnergy] = useState("3"); const [isSubmitting, setIsSubmitting] = useState(false); // Dexie.js üzerinden günlükleri tarih sırasına göre çekiyoruz (en yeni en üstte). const journals = useLiveQuery(() => db.journals.orderBy("date").reverse().toArray(), ); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); if (!content.trim()) return; setIsSubmitting(true); const now = new Date().toISOString(); const entryId = uuidv4(); const currentContent = content; try { // Veriyi önce kaydet, AI analizini daha sonra arka planda tamamla. await db.journals.add({ id: entryId, date: now.split("T")[0], mood, energy: parseInt(energy, 10), content: currentContent, created_at: now, updated_at: now, }); setContent(""); setEnergy("3"); setMood("happy"); try { const aiResult = await analyzeJournalWithLocalAI(currentContent); if (aiResult) { await db.journals.update(entryId, { ai_tags: aiResult.ai_tags, ai_sentiment_score: aiResult.ai_sentiment_score, ai_summary: aiResult.ai_summary, }); if (aiResult.suggested_tasks?.length) { for (const taskTitle of aiResult.suggested_tasks) { await db.tasks.add({ id: uuidv4(), journal_id: entryId, title: `AI Önerisi: ${taskTitle}`, status: "todo", ai_generated: true, date: now.split("T")[0], created_at: now, }); } } } } catch (aiError) { console.error("Arka plan AI analizi hatası:", aiError); } } catch (error) { console.error("Günlük kaydedilemedi:", error); } finally { setIsSubmitting(false); } }; const handleDelete = async (id: string) => { if (confirm("Bu günlüğü silmek istediğinden emin misin?")) { await db.journals.delete(id); } }; return (

Günlük

Zihnini boşalt, hislerini kaydet. Verilerin sadece cihazında kalır.

Yeni Kayıt Bugün nasıl hissediyorsun?
{moods.map((currentMood) => ( ))}
setEnergy(event.target.value)} className="w-full" />