From 94691f12ab7d11780575182e5809deb6b1ebdea9 Mon Sep 17 00:00:00 2001 From: duffyduck Date: Sun, 29 Mar 2026 13:01:26 +0200 Subject: [PATCH] added folder select dialog, fixed chat loading --- android/src/screens/ChatScreen.tsx | 22 +++++++++++------- android/src/screens/SettingsScreen.tsx | 31 +++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/android/src/screens/ChatScreen.tsx b/android/src/screens/ChatScreen.tsx index 3428c19..78fffb6 100644 --- a/android/src/screens/ChatScreen.tsx +++ b/android/src/screens/ChatScreen.tsx @@ -101,22 +101,28 @@ const ChatScreen: React.FC = () => { }; // Chat-Verlauf aus AsyncStorage laden + const isInitialLoad = useRef(true); useEffect(() => { const loadMessages = async () => { try { const stored = await AsyncStorage.getItem(CHAT_STORAGE_KEY); + console.log('[Chat] AsyncStorage geladen:', stored ? `${stored.length} Bytes` : 'leer'); if (stored) { const parsed: ChatMessage[] = JSON.parse(stored); - setMessages(parsed); - // ID-Counter auf hoechsten Wert setzen um Kollisionen zu vermeiden - const maxId = parsed.reduce((max, msg) => { - const num = parseInt(msg.id.split('_').pop() || '0', 10); - return num > max ? num : max; - }, 0); - messageIdCounter.current = maxId; + if (Array.isArray(parsed) && parsed.length > 0) { + console.log('[Chat] ${parsed.length} Nachrichten geladen'); + setMessages(parsed); + const maxId = parsed.reduce((max, msg) => { + const num = parseInt(msg.id.split('_').pop() || '0', 10); + return num > max ? num : max; + }, 0); + messageIdCounter.current = maxId; + } } } catch (err) { console.error('[Chat] Fehler beim Laden des Verlaufs:', err); + } finally { + isInitialLoad.current = false; } }; loadMessages(); @@ -278,7 +284,7 @@ const ChatScreen: React.FC = () => { // Chat-Verlauf in AsyncStorage speichern (letzte N Nachrichten) useEffect(() => { - if (messages.length === 0) return; + if (messages.length === 0 || isInitialLoad.current) return; // Nur file:// URIs speichern, data: URIs rausfiltern (zu gross) const toStore = messages.slice(-MAX_STORED_MESSAGES).map(msg => ({ ...msg, diff --git a/android/src/screens/SettingsScreen.tsx b/android/src/screens/SettingsScreen.tsx index 10a7479..55295b5 100644 --- a/android/src/screens/SettingsScreen.tsx +++ b/android/src/screens/SettingsScreen.tsx @@ -115,6 +115,35 @@ const SettingsScreen: React.FC = () => { Alert.alert('Gespeichert', `Neuer Speicherort:\n${clean}\n\nWird ab der naechsten Nachricht verwendet.`); }, []); + const storagePaths = [ + { label: 'App-intern (Standard)', path: DEFAULT_STORAGE_PATH }, + { label: 'Externer Speicher', path: '/storage/emulated/0/ARIA/attachments' }, + { label: 'SD-Karte', path: '/storage/sdcard1/ARIA/attachments' }, + { label: 'Downloads', path: '/storage/emulated/0/Download/ARIA' }, + ]; + + const showPathPicker = useCallback(() => { + const options = storagePaths.map(p => p.label); + options.push('Eigenen Pfad eingeben'); + options.push('Abbrechen'); + + Alert.alert( + 'Speicherort waehlen', + 'Wo sollen Anhaenge gespeichert werden?', + [ + ...storagePaths.map(p => ({ + text: p.label, + onPress: () => saveStoragePath(p.path), + })), + { + text: 'Eigenen Pfad eingeben', + onPress: () => { setTempPath(storagePath); setEditingPath(true); }, + }, + { text: 'Abbrechen', style: 'cancel' as const }, + ], + ); + }, [storagePath]); + const clearStorageCache = useCallback(async () => { Alert.alert( 'Cache loeschen', @@ -438,7 +467,7 @@ const SettingsScreen: React.FC = () => { { setTempPath(storagePath); setEditingPath(true); }} + onPress={showPathPicker} > Pfad aendern