diff --git a/app/api/notes/route.ts b/app/api/notes/route.ts new file mode 100644 index 0000000..a070752 --- /dev/null +++ b/app/api/notes/route.ts @@ -0,0 +1,76 @@ +export const dynamic = 'force-dynamic' +import { NextResponse } from 'next/server' +import * as fs from 'fs' + +const NOTES_PATH = '/tmp/tablet-notes.json' + +interface Note { + id: string + type: 'note' | 'shopping' + title: string + items?: { id: string; text: string; done: boolean }[] + text?: string + color: string + createdAt: string + updatedAt: string +} + +function loadNotes(): Note[] { + try { + if (fs.existsSync(NOTES_PATH)) { + return JSON.parse(fs.readFileSync(NOTES_PATH, 'utf-8')) + } + } catch {} + return [] +} + +function saveNotes(notes: Note[]) { + fs.writeFileSync(NOTES_PATH, JSON.stringify(notes, null, 2)) +} + +export async function GET() { + return NextResponse.json({ notes: loadNotes() }) +} + +export async function POST(req: Request) { + const body = await req.json() + const notes = loadNotes() + const note: Note = { + id: Date.now().toString(36) + Math.random().toString(36).slice(2, 6), + type: body.type || 'note', + title: body.title || '', + items: body.type === 'shopping' ? [] : undefined, + text: body.type === 'note' ? '' : undefined, + color: body.color || '#6366f1', + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + } + notes.unshift(note) + saveNotes(notes) + return NextResponse.json({ note }) +} + +export async function PUT(req: Request) { + const body = await req.json() + const { id, ...updates } = body + if (!id) return NextResponse.json({ error: 'id required' }, { status: 400 }) + + const notes = loadNotes() + const idx = notes.findIndex(n => n.id === id) + if (idx === -1) return NextResponse.json({ error: 'not found' }, { status: 404 }) + + notes[idx] = { ...notes[idx], ...updates, updatedAt: new Date().toISOString() } + saveNotes(notes) + return NextResponse.json({ note: notes[idx] }) +} + +export async function DELETE(req: Request) { + const { searchParams } = new URL(req.url) + const id = searchParams.get('id') + if (!id) return NextResponse.json({ error: 'id required' }, { status: 400 }) + + const notes = loadNotes() + const filtered = notes.filter(n => n.id !== id) + saveNotes(filtered) + return NextResponse.json({ success: true }) +} diff --git a/app/page.tsx b/app/page.tsx index 67ffc0a..16c7397 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -8,9 +8,10 @@ import TopBar from '@/components/TopBar' import RoomTabs from '@/components/RoomTabs' import DeviceCard from '@/components/DeviceCard' import CalendarTab from '@/components/CalendarTab' +import NotesTab from '@/components/NotesTab' import WeatherAnimation from '@/components/WeatherAnimation' -type Tab = 'home' | 'devices' | 'calendar' | 'settings' +type Tab = 'home' | 'devices' | 'calendar' | 'notes' | 'settings' interface WeatherData { temp: string @@ -333,15 +334,23 @@ function HomeTab({ weather, sensors }: { weather: WeatherData | null; sensors: S {weather.forecast && weather.forecast.length > 0 && ( -