settings: vervang WebDAV configuratie door REST API configuratie

This commit is contained in:
eddy 2026-07-20 17:00:21 +02:00
commit 23db445366

View file

@ -1,11 +1,11 @@
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'
import { ApiConfig } from '../types'
const CONFIG_KEY = 'weegschaal_webdav_config'
const CONFIG_KEY = 'weegschaal_api_config'
async function loadConfig(): Promise<WebDAVConfig | null> {
async function loadConfig(): Promise<ApiConfig | null> {
try {
const json = await SecureStore.getItemAsync(CONFIG_KEY)
return json ? JSON.parse(json) : null
@ -14,7 +14,7 @@ async function loadConfig(): Promise<WebDAVConfig | null> {
}
}
async function saveConfig(config: WebDAVConfig): Promise<void> {
async function saveConfig(config: ApiConfig): Promise<void> {
await SecureStore.setItemAsync(CONFIG_KEY, JSON.stringify(config))
}
@ -22,50 +22,43 @@ async function deleteConfig(): Promise<void> {
await SecureStore.deleteItemAsync(CONFIG_KEY)
}
export async function getWebDAVConfig(): Promise<WebDAVConfig | null> {
export async function getApiConfig(): Promise<ApiConfig | null> {
return loadConfig()
}
export default function SettingsScreen() {
const [url, setUrl] = useState('https://nextcloud.eddydevink.nl/remote.php/dav/files/eddy')
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [showPassword, setShowPassword] = useState(false)
const [url, setUrl] = useState('https://weegschaal.eddydevink.nl')
const [token, setToken] = useState('')
const [showToken, setShowToken] = useState(false)
const [syncing, setSyncing] = useState(false)
useEffect(() => {
loadConfig().then(c => {
if (c) {
setUrl(c.url)
setUsername(c.username)
setPassword(c.password)
setToken(c.token)
}
})
}, [])
const handleSave = async () => {
await saveConfig({ url, username, password })
Alert.alert('Opgeslagen', 'WebDAV instellingen zijn opgeslagen')
await saveConfig({ url, token })
Alert.alert('Opgeslagen', 'API instellingen zijn opgeslagen')
}
const handleClear = () => {
Alert.alert(
'Instellingen wissen?',
'WebDAV configuratie definitief verwijderen? Je kunt deze later opnieuw invoeren.',
[
{ text: 'Annuleren', style: 'cancel' },
{
text: 'Ja, wissen',
style: 'destructive',
onPress: async () => {
await deleteConfig()
setUrl('')
setUsername('')
setPassword('')
},
Alert.alert('Instellingen wissen?', 'API configuratie definitief verwijderen?', [
{ text: 'Annuleren', style: 'cancel' },
{
text: 'Ja, wissen',
style: 'destructive',
onPress: async () => {
await deleteConfig()
setUrl('')
setToken('')
},
]
)
},
])
}
const handleSync = async () => {
@ -73,7 +66,7 @@ export default function SettingsScreen() {
try {
const { syncAll } = await import('../sync/syncService')
const result = await syncAll()
Alert.alert('Sync voltooid', `Lokaal: ${result.local}, WebDAV: ${result.remote}, samengevoegd: ${result.merged}`)
Alert.alert('Sync voltooid', `Opgehaald: ${result.pulled}, gepusht: ${result.pushed}, verwijderd: ${result.deleted}`)
} catch (e: any) {
Alert.alert('Sync fout', e?.message ?? 'Onbekende fout')
} finally {
@ -83,38 +76,30 @@ export default function SettingsScreen() {
return (
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
<Text style={styles.sectionTitle}>WebDAV (Nextcloud)</Text>
<Text style={styles.sectionTitle}>REST API</Text>
<Text style={styles.label}>URL</Text>
<Text style={styles.label}>API URL</Text>
<TextInput
style={styles.input}
value={url}
onChangeText={setUrl}
placeholder="https://nextcloud.eddydevink.nl/remote.php/dav/files/gebruiker/"
placeholder="https://weegschaal.eddydevink.nl"
autoCapitalize="none"
autoCorrect={false}
/>
<Text style={styles.label}>Gebruikersnaam</Text>
<TextInput
style={styles.input}
value={username}
onChangeText={setUsername}
autoCapitalize="none"
autoCorrect={false}
/>
<Text style={styles.label}>Wachtwoord</Text>
<Text style={styles.label}>Token</Text>
<View style={styles.passwordRow}>
<TextInput
style={styles.passwordInput}
value={password}
onChangeText={setPassword}
secureTextEntry={!showPassword}
value={token}
onChangeText={setToken}
secureTextEntry={!showToken}
autoCapitalize="none"
autoCorrect={false}
/>
<TouchableOpacity style={styles.eyeButton} onPress={() => setShowPassword(!showPassword)}>
<Text style={styles.eyeIcon}>{showPassword ? '👁' : '👁‍🗨'}</Text>
<TouchableOpacity style={styles.eyeButton} onPress={() => setShowToken(!showToken)}>
<Text style={styles.eyeIcon}>{showToken ? 'O' : 'O'}</Text>
</TouchableOpacity>
</View>