settings: vervang WebDAV configuratie door REST API configuratie
This commit is contained in:
parent
4b7b7e3d5c
commit
23db445366
1 changed files with 33 additions and 48 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, ScrollView } from 'react-native'
|
import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, ScrollView } from 'react-native'
|
||||||
import * as SecureStore from 'expo-secure-store'
|
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 {
|
try {
|
||||||
const json = await SecureStore.getItemAsync(CONFIG_KEY)
|
const json = await SecureStore.getItemAsync(CONFIG_KEY)
|
||||||
return json ? JSON.parse(json) : null
|
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))
|
await SecureStore.setItemAsync(CONFIG_KEY, JSON.stringify(config))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,50 +22,43 @@ async function deleteConfig(): Promise<void> {
|
||||||
await SecureStore.deleteItemAsync(CONFIG_KEY)
|
await SecureStore.deleteItemAsync(CONFIG_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getWebDAVConfig(): Promise<WebDAVConfig | null> {
|
export async function getApiConfig(): Promise<ApiConfig | null> {
|
||||||
return loadConfig()
|
return loadConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function SettingsScreen() {
|
export default function SettingsScreen() {
|
||||||
const [url, setUrl] = useState('https://nextcloud.eddydevink.nl/remote.php/dav/files/eddy')
|
const [url, setUrl] = useState('https://weegschaal.eddydevink.nl')
|
||||||
const [username, setUsername] = useState('')
|
const [token, setToken] = useState('')
|
||||||
const [password, setPassword] = useState('')
|
const [showToken, setShowToken] = useState(false)
|
||||||
const [showPassword, setShowPassword] = useState(false)
|
|
||||||
const [syncing, setSyncing] = useState(false)
|
const [syncing, setSyncing] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadConfig().then(c => {
|
loadConfig().then(c => {
|
||||||
if (c) {
|
if (c) {
|
||||||
setUrl(c.url)
|
setUrl(c.url)
|
||||||
setUsername(c.username)
|
setToken(c.token)
|
||||||
setPassword(c.password)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
await saveConfig({ url, username, password })
|
await saveConfig({ url, token })
|
||||||
Alert.alert('Opgeslagen', 'WebDAV instellingen zijn opgeslagen')
|
Alert.alert('Opgeslagen', 'API instellingen zijn opgeslagen')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClear = () => {
|
const handleClear = () => {
|
||||||
Alert.alert(
|
Alert.alert('Instellingen wissen?', 'API configuratie definitief verwijderen?', [
|
||||||
'Instellingen wissen?',
|
{ text: 'Annuleren', style: 'cancel' },
|
||||||
'WebDAV configuratie definitief verwijderen? Je kunt deze later opnieuw invoeren.',
|
{
|
||||||
[
|
text: 'Ja, wissen',
|
||||||
{ text: 'Annuleren', style: 'cancel' },
|
style: 'destructive',
|
||||||
{
|
onPress: async () => {
|
||||||
text: 'Ja, wissen',
|
await deleteConfig()
|
||||||
style: 'destructive',
|
setUrl('')
|
||||||
onPress: async () => {
|
setToken('')
|
||||||
await deleteConfig()
|
|
||||||
setUrl('')
|
|
||||||
setUsername('')
|
|
||||||
setPassword('')
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
]
|
},
|
||||||
)
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSync = async () => {
|
const handleSync = async () => {
|
||||||
|
|
@ -73,7 +66,7 @@ export default function SettingsScreen() {
|
||||||
try {
|
try {
|
||||||
const { syncAll } = await import('../sync/syncService')
|
const { syncAll } = await import('../sync/syncService')
|
||||||
const result = await syncAll()
|
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) {
|
} catch (e: any) {
|
||||||
Alert.alert('Sync fout', e?.message ?? 'Onbekende fout')
|
Alert.alert('Sync fout', e?.message ?? 'Onbekende fout')
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -83,38 +76,30 @@ export default function SettingsScreen() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
|
<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
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
value={url}
|
value={url}
|
||||||
onChangeText={setUrl}
|
onChangeText={setUrl}
|
||||||
placeholder="https://nextcloud.eddydevink.nl/remote.php/dav/files/gebruiker/"
|
placeholder="https://weegschaal.eddydevink.nl"
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
autoCorrect={false}
|
autoCorrect={false}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Text style={styles.label}>Gebruikersnaam</Text>
|
<Text style={styles.label}>Token</Text>
|
||||||
<TextInput
|
|
||||||
style={styles.input}
|
|
||||||
value={username}
|
|
||||||
onChangeText={setUsername}
|
|
||||||
autoCapitalize="none"
|
|
||||||
autoCorrect={false}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Text style={styles.label}>Wachtwoord</Text>
|
|
||||||
<View style={styles.passwordRow}>
|
<View style={styles.passwordRow}>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.passwordInput}
|
style={styles.passwordInput}
|
||||||
value={password}
|
value={token}
|
||||||
onChangeText={setPassword}
|
onChangeText={setToken}
|
||||||
secureTextEntry={!showPassword}
|
secureTextEntry={!showToken}
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
|
autoCorrect={false}
|
||||||
/>
|
/>
|
||||||
<TouchableOpacity style={styles.eyeButton} onPress={() => setShowPassword(!showPassword)}>
|
<TouchableOpacity style={styles.eyeButton} onPress={() => setShowToken(!showToken)}>
|
||||||
<Text style={styles.eyeIcon}>{showPassword ? '👁' : '👁🗨'}</Text>
|
<Text style={styles.eyeIcon}>{showToken ? 'O' : 'O'}</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue