import React, { useMemo, useState } from 'react'; import { IcNavBack, IcLock, IcMoreVert } from '../res/icons'; import { SIMULATOR_CONFIG } from '@/os/data'; const { statusBarHeight, bottomGestureHeight } = SIMULATOR_CONFIG.framework; import * as TimeService from '../../../os/TimeService'; import { useNotesStore, selectPrivateNotes } from '../state'; import { ActionSheet } from '../components/ActionSheet'; import { Toast } from '@/os/components/Toast'; import { colors } from '../res/colors'; import { strings } from '../res/strings'; import { stringsEn } from '../res/strings.en'; import { useAppStrings } from '../../../os/useAppStrings'; import type { Note } from '../types'; import { useNotesGestures } from '../hooks/useNotesGestures'; function formatListTime(timestamp: number, s: typeof strings) { const d = TimeService.fromTimestamp(timestamp); const y = d.getFullYear(); const m = d.getMonth() + 1; const day = d.getDate(); const now = TimeService.getDate(); if (y !== now.getFullYear()) return `${y}${s.date_suffix_year}${m}${s.date_suffix_month}${day}${s.date_suffix_day}`; const hh = d.getHours().toString().padStart(2, '0'); const mm = d.getMinutes().toString().padStart(2, '0'); return `${m}${s.date_suffix_month}${day}${s.date_suffix_day} ${hh}:${mm}`; } function snippet(text: string) { return (text || '').replace(/\s+/g, ' ').trim(); } const PrivateCard: React.FC<{ note: Note; onOpen: () => void; onActions: () => void; }> = ({ note, onOpen, onActions }) => { const s = useAppStrings(strings, stringsEn); const title = note.title.trim() || s.untitled; const content = snippet(note.content); return (
); }; export const PrivateNotesPage: React.FC = () => { const { go, bindBack } = useNotesGestures(); const privateNotes = useNotesStore(selectPrivateNotes); const unhideNote = useNotesStore(s => s.unhideNote); const deleteNote = useNotesStore(s => s.deleteNote); const s = useAppStrings(strings, stringsEn); const [active, setActive] = useState(null); const [toast, setToast] = useState({ message: '', visible: false }); const topPad = statusBarHeight + 18; const items = useMemo(() => { if (!active) return []; return [ { key: 'unhide', label: s.action_unset_private, onClick: () => { unhideNote(active.id); setActive(null); setToast({ message: s.toast_unset_private, visible: true }); window.setTimeout(() => setToast({ message: '', visible: false }), 1200); }, }, { key: 'delete', label: s.action_delete, danger: true, onClick: () => { deleteNote(active.id); setActive(null); setToast({ message: s.toast_moved_to_trash, visible: true }); window.setTimeout(() => setToast({ message: '', visible: false }), 1200); }, }, ]; }, [active, deleteNote, unhideNote, s]); return (
{/* Header */}
{s.private_notes}
{/* List */}
{privateNotes.length ? ( privateNotes.map(n => ( go('note.open', { id: n.id })} onActions={() => setActive(n)} /> )) ) : (
{s.empty_private}
)}
setActive(null)} />
); }; export default PrivateNotesPage;