added folder select dialog, fixed chat loading

This commit is contained in:
duffyduck 2026-03-29 13:01:26 +02:00
parent 5c8d11824e
commit 94691f12ab
2 changed files with 44 additions and 9 deletions

View File

@ -101,22 +101,28 @@ const ChatScreen: React.FC = () => {
}; };
// Chat-Verlauf aus AsyncStorage laden // Chat-Verlauf aus AsyncStorage laden
const isInitialLoad = useRef(true);
useEffect(() => { useEffect(() => {
const loadMessages = async () => { const loadMessages = async () => {
try { try {
const stored = await AsyncStorage.getItem(CHAT_STORAGE_KEY); const stored = await AsyncStorage.getItem(CHAT_STORAGE_KEY);
console.log('[Chat] AsyncStorage geladen:', stored ? `${stored.length} Bytes` : 'leer');
if (stored) { if (stored) {
const parsed: ChatMessage[] = JSON.parse(stored); const parsed: ChatMessage[] = JSON.parse(stored);
setMessages(parsed); if (Array.isArray(parsed) && parsed.length > 0) {
// ID-Counter auf hoechsten Wert setzen um Kollisionen zu vermeiden console.log('[Chat] ${parsed.length} Nachrichten geladen');
const maxId = parsed.reduce((max, msg) => { setMessages(parsed);
const num = parseInt(msg.id.split('_').pop() || '0', 10); const maxId = parsed.reduce((max, msg) => {
return num > max ? num : max; const num = parseInt(msg.id.split('_').pop() || '0', 10);
}, 0); return num > max ? num : max;
messageIdCounter.current = maxId; }, 0);
messageIdCounter.current = maxId;
}
} }
} catch (err) { } catch (err) {
console.error('[Chat] Fehler beim Laden des Verlaufs:', err); console.error('[Chat] Fehler beim Laden des Verlaufs:', err);
} finally {
isInitialLoad.current = false;
} }
}; };
loadMessages(); loadMessages();
@ -278,7 +284,7 @@ const ChatScreen: React.FC = () => {
// Chat-Verlauf in AsyncStorage speichern (letzte N Nachrichten) // Chat-Verlauf in AsyncStorage speichern (letzte N Nachrichten)
useEffect(() => { useEffect(() => {
if (messages.length === 0) return; if (messages.length === 0 || isInitialLoad.current) return;
// Nur file:// URIs speichern, data: URIs rausfiltern (zu gross) // Nur file:// URIs speichern, data: URIs rausfiltern (zu gross)
const toStore = messages.slice(-MAX_STORED_MESSAGES).map(msg => ({ const toStore = messages.slice(-MAX_STORED_MESSAGES).map(msg => ({
...msg, ...msg,

View File

@ -115,6 +115,35 @@ const SettingsScreen: React.FC = () => {
Alert.alert('Gespeichert', `Neuer Speicherort:\n${clean}\n\nWird ab der naechsten Nachricht verwendet.`); 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 () => { const clearStorageCache = useCallback(async () => {
Alert.alert( Alert.alert(
'Cache loeschen', 'Cache loeschen',
@ -438,7 +467,7 @@ const SettingsScreen: React.FC = () => {
<View style={{flexDirection: 'row', gap: 8, marginTop: 8}}> <View style={{flexDirection: 'row', gap: 8, marginTop: 8}}>
<TouchableOpacity <TouchableOpacity
style={[styles.clearButton, {flex: 1, marginTop: 0}]} style={[styles.clearButton, {flex: 1, marginTop: 0}]}
onPress={() => { setTempPath(storagePath); setEditingPath(true); }} onPress={showPathPicker}
> >
<Text style={styles.clearButtonText}>Pfad aendern</Text> <Text style={styles.clearButtonText}>Pfad aendern</Text>
</TouchableOpacity> </TouchableOpacity>