MM-13673 combine reset cache & delete files into one action (#2499)

This commit is contained in:
Elias Nahum 2019-01-28 11:35:34 -03:00 committed by Harrison Healey
parent aea4b096e4
commit 0cb7227d52
3 changed files with 26 additions and 63 deletions

View file

@ -43,56 +43,37 @@ class AdvancedSettings extends PureComponent {
}
clearOfflineCache = preventDoubleTap(() => {
const {actions, intl} = this.props;
const {formatMessage} = this.props.intl;
Alert.alert(
intl.formatMessage({id: 'mobile.advanced_settings.reset_title', defaultMessage: 'Reset Cache'}),
intl.formatMessage({id: 'mobile.advanced_settings.reset_message', defaultMessage: '\nThis will reset all offline data and restart the app. You will be automatically logged back in once the app restarts.\n'}),
formatMessage({id: 'mobile.advanced_settings.delete_title', defaultMessage: 'Delete Documents & Data'}),
formatMessage({id: 'mobile.advanced_settings.delete_message', defaultMessage: '\nThis will reset all offline data and restart the app. You will be automatically logged back in once the app restarts.\n'}),
[{
text: intl.formatMessage({id: 'mobile.advanced_settings.reset_button', defaultMessage: 'Reset'}),
onPress: () => actions.purgeOfflineStore(),
}, {
text: intl.formatMessage({id: 'channel_modal.cancel', defaultMessage: 'Cancel'}),
text: formatMessage({id: 'channel_modal.cancel', defaultMessage: 'Cancel'}),
style: 'cancel',
onPress: () => true,
}]
}, {
text: formatMessage({id: 'mobile.advanced_settings.delete', defaultMessage: 'Delete'}),
style: 'destructive',
onPress: this.purgeDocumentsAndData,
}],
{cancelable: false},
);
});
clearDownloadCache = preventDoubleTap(() => {
const {intl} = this.props;
const {cacheSize} = this.state;
if (cacheSize) {
Alert.alert(
intl.formatMessage({
id: 'mobile.advanced_settings.delete_file_cache',
defaultMessage: 'Delete File Cache',
}),
intl.formatMessage({
id: 'mobile.advanced_settings.delete_file_cache_message',
defaultMessage: '\nThis will delete all the files stored in the cache. Are you sure you want to delete them?\n',
}),
[{
text: intl.formatMessage({id: 'mobile.advanced_settings.delete', defaultMessage: 'Delete'}),
onPress: () => {
this.setState({cacheSize: null, cacheSizedFetched: false}, async () => {
await deleteFileCache();
this.setState({cacheSize: 0, cacheSizedFetched: true});
});
},
}, {
text: intl.formatMessage({id: 'channel_modal.cancel', defaultMessage: 'Cancel'}),
onPress: () => true,
}]
);
}
});
getDownloadCacheSize = async () => {
const size = await getFileCacheSize();
this.setState({cacheSize: size, cacheSizedFetched: true});
};
purgeDocumentsAndData = preventDoubleTap(async () => {
const {actions} = this.props;
await deleteFileCache();
this.setState({cacheSize: 0, cacheSizedFetched: true});
actions.purgeOfflineStore();
});
renderCacheFileSize = () => {
const {theme} = this.props;
const {cacheSize, cacheSizedFetched} = this.state;
@ -149,7 +130,7 @@ class AdvancedSettings extends PureComponent {
<View style={style.divider}/>
</View>
);
}
};
render() {
const {theme} = this.props;
@ -164,24 +145,14 @@ class AdvancedSettings extends PureComponent {
>
<View style={style.divider}/>
<SettingsItem
defaultMessage='Reset Cache'
i18nId='mobile.advanced_settings.reset_title'
defaultMessage='Delete Documents & Data'
i18nId='mobile.advanced_settings.delete_title'
iconName='ios-refresh'
iconType='ion'
isDestructor={true}
onPress={this.clearOfflineCache}
separator={false}
showArrow={false}
theme={theme}
/>
<View style={style.divider}/>
<SettingsItem
defaultMessage='Delete File Cache'
i18nId='mobile.advanced_settings.delete_file_cache'
iconName='md-trash'
iconType='ion'
onPress={this.clearDownloadCache}
separator={false}
showArrow={false}
rightComponent={this.renderCacheFileSize()}
theme={theme}
/>

View file

@ -62,13 +62,12 @@ export default class SettingsItem extends PureComponent {
style={textStyle}
/>
);
}
};
render() {
const {
iconName,
iconType,
isDestructor,
onPress,
rightComponent,
separator,
@ -85,10 +84,6 @@ export default class SettingsItem extends PureComponent {
let icon;
if (iconType && iconName) {
const iconStyle = [style.icon];
if (isDestructor) {
iconStyle.push(style.destructor);
}
icon = (
<VectorIcon
name={iconName}

View file

@ -130,11 +130,8 @@
"mobile.action_menu.submitted": "Submitted",
"mobile.advanced_settings.clockDisplay": "Clock display",
"mobile.advanced_settings.delete": "Delete",
"mobile.advanced_settings.delete_file_cache": "Delete File Cache",
"mobile.advanced_settings.delete_file_cache_message": "\nThis will delete all the files stored in the cache. Are you sure you want to delete them?\n",
"mobile.advanced_settings.reset_button": "Reset",
"mobile.advanced_settings.reset_message": "\nThis will reset all offline data and restart the app. You will be automatically logged back in once the app restarts.\n",
"mobile.advanced_settings.reset_title": "Reset Cache",
"mobile.advanced_settings.delete_message": "\nThis will reset all offline data and restart the app. You will be automatically logged back in once the app restarts.\n",
"mobile.advanced_settings.delete_title": "Delete Documents & Data",
"mobile.advanced_settings.timezone": "Timezone",
"mobile.advanced_settings.title": "Advanced Settings",
"mobile.android.camera_permission_denied_description": "To take photos and videos with your camera, please change your permission settings.",