MM-48339 - Gekidou Alert box for Advanced Settings (#6758)
* added the alert box * MM-48339 - Adds Alert box to confirm data deletion * MM-48339 - update en.json * corrections from PR review * i18n id clean up * i18n id clean up * update i18n * remove t()
This commit is contained in:
parent
c8ccbeffb1
commit
95af1afe6b
3 changed files with 33 additions and 11 deletions
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import {useIntl} from 'react-intl';
|
||||
import {TouchableOpacity} from 'react-native';
|
||||
import {Alert, TouchableOpacity} from 'react-native';
|
||||
|
||||
import {useServerUrl} from '@context/server';
|
||||
import {useTheme} from '@context/theme';
|
||||
|
|
@ -32,17 +32,17 @@ const EMPTY_FILES: ReadDirItem[] = [];
|
|||
|
||||
type AdvancedSettingsProps = {
|
||||
componentId: string;
|
||||
}
|
||||
};
|
||||
const AdvancedSettings = ({componentId}: AdvancedSettingsProps) => {
|
||||
const theme = useTheme();
|
||||
const intl = useIntl();
|
||||
const serverUrl = useServerUrl();
|
||||
const [dataSize, setDataSize] = useState<number|undefined>(0);
|
||||
const [dataSize, setDataSize] = useState<number | undefined>(0);
|
||||
const [files, setFiles] = useState<ReadDirItem[]>(EMPTY_FILES);
|
||||
const styles = getStyleSheet(theme);
|
||||
|
||||
const getAllCachedFiles = async () => {
|
||||
const {totalSize, files: cachedFiles} = await getAllFilesInCachesDirectory(serverUrl);
|
||||
const {totalSize = 0, files: cachedFiles} = await getAllFilesInCachesDirectory(serverUrl);
|
||||
setDataSize(totalSize);
|
||||
setFiles(cachedFiles || EMPTY_FILES);
|
||||
};
|
||||
|
|
@ -50,8 +50,27 @@ const AdvancedSettings = ({componentId}: AdvancedSettingsProps) => {
|
|||
const onPressDeleteData = preventDoubleTap(async () => {
|
||||
try {
|
||||
if (files.length > 0) {
|
||||
await deleteFileCache(serverUrl);
|
||||
await getAllCachedFiles();
|
||||
const {formatMessage} = intl;
|
||||
|
||||
Alert.alert(
|
||||
formatMessage({id: 'settings.advanced.delete_data', defaultMessage: 'Delete local files'}),
|
||||
formatMessage({
|
||||
id: 'settings.advanced.delete_message.confirmation',
|
||||
defaultMessage: '\nThis will delete all files downloaded through the app for this server. Please confirm to proceed.\n',
|
||||
}),
|
||||
[
|
||||
{text: formatMessage({id: 'settings.advanced.cancel', defaultMessage: 'Cancel'}), style: 'cancel'},
|
||||
{
|
||||
text: formatMessage({id: 'settings.advanced.delete', defaultMessage: 'Delete'}),
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
await deleteFileCache(serverUrl);
|
||||
await getAllCachedFiles();
|
||||
},
|
||||
},
|
||||
],
|
||||
{cancelable: false},
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
//do nothing
|
||||
|
|
@ -65,7 +84,7 @@ const AdvancedSettings = ({componentId}: AdvancedSettingsProps) => {
|
|||
const close = () => popTopScreen(componentId);
|
||||
useAndroidHardwareBackHandler(componentId, close);
|
||||
|
||||
const hasData = Boolean(dataSize && (dataSize > 0));
|
||||
const hasData = Boolean(dataSize && dataSize > 0);
|
||||
|
||||
return (
|
||||
<SettingContainer testID='advanced_settings'>
|
||||
|
|
@ -79,8 +98,8 @@ const AdvancedSettings = ({componentId}: AdvancedSettingsProps) => {
|
|||
destructive={true}
|
||||
icon='trash-can-outline'
|
||||
info={getFormattedFileSize(dataSize || 0)}
|
||||
label={intl.formatMessage({id: 'advanced_settings.delete_data', defaultMessage: 'Delete Documents & Data'})}
|
||||
testID='advanced_settings.delete_data.option'
|
||||
label={intl.formatMessage({id: 'settings.advanced.delete_data', defaultMessage: 'Delete local files'})}
|
||||
testID='settings.advanced.delete_data.option'
|
||||
type='none'
|
||||
/>
|
||||
<SettingSeparator/>
|
||||
|
|
|
|||
|
|
@ -535,7 +535,6 @@ export const getAllFilesInCachesDirectory = async (serverUrl: string) => {
|
|||
totalSize,
|
||||
};
|
||||
} catch (error) {
|
||||
logError('Failed getAllFilesInCachesDirectory', error);
|
||||
return {error};
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
"account.settings": "Settings",
|
||||
"account.user_status.title": "User Presence",
|
||||
"account.your_profile": "Your Profile",
|
||||
"advanced_settings.delete_data": "Delete Documents & Data",
|
||||
"alert.channel_deleted.description": "The channel {displayName} has been archived.",
|
||||
"alert.channel_deleted.title": "Archived channel",
|
||||
"alert.push_proxy_error.description": "Due to the configuration for this server, notifications cannot be received in the mobile app. Contact your system admin for more information.",
|
||||
|
|
@ -394,6 +393,7 @@
|
|||
"mobile.calls_ok": "OK",
|
||||
"mobile.calls_participant_limit_title": "Participant limit reached",
|
||||
"mobile.calls_raise_hand": "Raise hand",
|
||||
"mobile.calls_react": "React",
|
||||
"mobile.calls_see_logs": "See server logs",
|
||||
"mobile.calls_speaker": "Speaker",
|
||||
"mobile.calls_start_call": "Start Call",
|
||||
|
|
@ -802,6 +802,10 @@
|
|||
"settings.about.serverVersionNoBuild": "{version}",
|
||||
"settings.about.version": "App Version:",
|
||||
"settings.advanced_settings": "Advanced Settings",
|
||||
"settings.advanced.cancel": "Cancel",
|
||||
"settings.advanced.delete": "Delete",
|
||||
"settings.advanced.delete_data": "Delete local files",
|
||||
"settings.advanced.delete_message.confirmation": "\nThis will delete all files downloaded through the app for this server. Please confirm to proceed.\n",
|
||||
"settings.display": "Display",
|
||||
"settings.link.error.text": "Unable to open the link.",
|
||||
"settings.link.error.title": "Error",
|
||||
|
|
|
|||
Loading…
Reference in a new issue