diff --git a/src/screens/SettingsScreen.tsx b/src/screens/SettingsScreen.tsx new file mode 100644 index 0000000..2467cc5 --- /dev/null +++ b/src/screens/SettingsScreen.tsx @@ -0,0 +1,133 @@ +import React, { useEffect, useState } from 'react' +import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, ScrollView } from 'react-native' +import * as SecureStore from 'expo-secure-store' +import { WebDAVConfig } from '../types' + +const CONFIG_KEY = 'weegschaal_webdav_config' + +async function loadConfig(): Promise { + try { + const json = await SecureStore.getItemAsync(CONFIG_KEY) + return json ? JSON.parse(json) : null + } catch { + return null + } +} + +async function saveConfig(config: WebDAVConfig): Promise { + await SecureStore.setItemAsync(CONFIG_KEY, JSON.stringify(config)) +} + +async function deleteConfig(): Promise { + await SecureStore.deleteItemAsync(CONFIG_KEY) +} + +export async function getWebDAVConfig(): Promise { + return loadConfig() +} + +export default function SettingsScreen() { + const [url, setUrl] = useState('') + const [username, setUsername] = useState('') + const [password, setPassword] = useState('') + const [syncing, setSyncing] = useState(false) + + useEffect(() => { + loadConfig().then(c => { + if (c) { + setUrl(c.url) + setUsername(c.username) + setPassword(c.password) + } + }) + }, []) + + const handleSave = async () => { + await saveConfig({ url, username, password }) + Alert.alert('Opgeslagen', 'WebDAV instellingen zijn opgeslagen') + } + + const handleClear = async () => { + await deleteConfig() + setUrl('') + setUsername('') + setPassword('') + Alert.alert('Verwijderd', 'WebDAV instellingen zijn gewist') + } + + const handleSync = async () => { + setSyncing(true) + try { + const { syncAll } = await import('../sync/syncService') + const result = await syncAll() + Alert.alert('Sync voltooid', `Lokaal: ${result.local}, WebDAV: ${result.remote}, samengevoegd: ${result.merged}`) + } catch (e: any) { + Alert.alert('Sync fout', e?.message ?? 'Onbekende fout') + } finally { + setSyncing(false) + } + } + + return ( + + WebDAV (Nextcloud) + + URL + + + Gebruikersnaam + + + Wachtwoord + + + + Instellingen opslaan + + + + Instellingen wissen + + + + {syncing ? 'Bezig met sync...' : 'Nu synchroniseren'} + + + ) +} + +const styles = StyleSheet.create({ + container: { flex: 1, backgroundColor: '#f5f5f5' }, + content: { padding: 16 }, + sectionTitle: { fontSize: 18, fontWeight: '700', marginBottom: 16 }, + label: { fontSize: 14, fontWeight: '600', color: '#333', marginBottom: 4, marginTop: 12 }, + input: { backgroundColor: '#fff', borderRadius: 8, padding: 12, fontSize: 16, borderWidth: 1, borderColor: '#ddd' }, + saveButton: { backgroundColor: '#4CAF50', padding: 14, borderRadius: 8, alignItems: 'center', marginTop: 24 }, + clearButton: { padding: 14, alignItems: 'center', marginTop: 8 }, + clearButtonText: { color: '#e53935', fontSize: 14 }, + syncButton: { backgroundColor: '#2196F3', padding: 14, borderRadius: 8, alignItems: 'center', marginTop: 24 }, + syncButtonDisabled: { opacity: 0.6 }, + buttonText: { color: '#fff', fontSize: 16, fontWeight: '700' }, +})