'use client' import { useState } from 'react' import { SettingsNav, SettingsSection, SettingToggle, SettingInput } from '@/components/settings' import { Button } from '@/components/ui/button' import { Download, Upload, Trash2, Loader2, Check } from 'lucide-react' import { toast } from 'sonner' export default function DataSettingsPage() { const [isExporting, setIsExporting] = useState(false) const [isImporting, setIsImporting] = useState(false) const [isDeleting, setIsDeleting] = useState(false) const [exportUrl, setExportUrl] = useState('') const handleExport = async () => { setIsExporting(true) try { const response = await fetch('/api/notes/export') if (response.ok) { const blob = await response.blob() const url = window.URL.createObjectURL(blob) const a = document.createElement('a') a.href = url a.download = `keep-notes-export-${new Date().toISOString().split('T')[0]}.json` document.body.appendChild(a) a.click() document.body.removeChild(a) window.URL.revokeObjectURL(url) toast.success('Notes exported successfully') } } catch (error) { console.error('Export error:', error) toast.error('Failed to export notes') } finally { setIsExporting(false) } } const handleImport = async (event: React.ChangeEvent) => { const file = event.target.files?.[0] if (!file) return setIsImporting(true) try { const formData = new FormData() formData.append('file', file) const response = await fetch('/api/notes/import', { method: 'POST', body: formData }) if (response.ok) { const result = await response.json() toast.success(`Imported ${result.count} notes`) // Refresh the page to show imported notes window.location.reload() } else { throw new Error('Import failed') } } catch (error) { console.error('Import error:', error) toast.error('Failed to import notes') } finally { setIsImporting(false) // Reset input event.target.value = '' } } const handleDeleteAll = async () => { if (!confirm('Are you sure you want to delete all notes? This action cannot be undone.')) { return } setIsDeleting(true) try { const response = await fetch('/api/notes/delete-all', { method: 'POST' }) if (response.ok) { toast.success('All notes deleted') window.location.reload() } } catch (error) { console.error('Delete error:', error) toast.error('Failed to delete notes') } finally { setIsDeleting(false) } } return (

Data Management

Export, import, or manage your data

💾} description="Download your notes as a JSON file" >

Export All Notes

Download all your notes in JSON format

📥} description="Import notes from a JSON file" >

Import Notes

Upload a JSON file to import notes

⚠️} description="Permanently delete your data" >

Delete All Notes

This action cannot be undone

) }