added folder select dialog, fixed chat loading
This commit is contained in:
parent
5c8d11824e
commit
94691f12ab
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 = () => {
|
|||
<View style={{flexDirection: 'row', gap: 8, marginTop: 8}}>
|
||||
<TouchableOpacity
|
||||
style={[styles.clearButton, {flex: 1, marginTop: 0}]}
|
||||
onPress={() => { setTempPath(storagePath); setEditingPath(true); }}
|
||||
onPress={showPathPicker}
|
||||
>
|
||||
<Text style={styles.clearButtonText}>Pfad aendern</Text>
|
||||
</TouchableOpacity>
|
||||
|
|
|
|||
Loading…
Reference in New Issue