"use client"; import { useEffect, useState } from "react"; import { useToast } from "@/lib/toast"; import type { Destination } from "@/lib/types"; const STORAGE_KEY = "nomadro-city-notes"; interface Props { destinations: Destination[]; } export default function CityNotes({ destinations }: Props) { const { toast } = useToast(); const [slug, setSlug] = useState(destinations[0]?.slug || "bali"); const [notes, setNotes] = useState>({}); const [text, setText] = useState(""); const [ready, setReady] = useState(false); const dest = destinations.find((d) => d.slug === slug); useEffect(() => { try { const raw = localStorage.getItem(STORAGE_KEY); if (raw) setNotes(JSON.parse(raw)); } catch { /* ignore */ } setReady(true); }, []); useEffect(() => { if (!ready) return; setText(notes[slug] || ""); }, [slug, notes, ready]); const save = () => { const next = { ...notes, [slug]: text }; setNotes(next); localStorage.setItem(STORAGE_KEY, JSON.stringify(next)); toast(`${dest?.emoji || ""} 笔记已保存`); }; const clear = () => { const next = { ...notes }; delete next[slug]; setNotes(next); setText(""); localStorage.setItem(STORAGE_KEY, JSON.stringify(next)); toast("已清空该城笔记", "info"); }; const filled = Object.keys(notes).filter((k) => notes[k]?.trim()).length; return (
📝 NOTES

城市旅居笔记

记录咖啡馆坐标、房东微信、避坑心得——只存在你的浏览器里

{destinations.map((d) => ( ))}

已记录 {filled} 座城市

{dest?.emoji} {dest?.name}