-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
advanced_settings.js
215 lines (191 loc) · 6.67 KB
/
advanced_settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {injectIntl, intlShape} from 'react-intl';
import {
ActivityIndicator,
Alert,
Platform,
ScrollView,
Text,
View,
} from 'react-native';
import * as Sentry from '@sentry/react-native';
import {getFormattedFileSize} from 'mattermost-redux/utils/file_utils';
import SettingsItem from 'app/screens/settings/settings_item';
import StatusBar from 'app/components/status_bar';
import {t} from 'app/utils/i18n';
import {deleteFileCache, getFileCacheSize} from 'app/utils/file';
import {preventDoubleTap} from 'app/utils/tap';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
import {dismissAllModals} from 'app/actions/navigation';
import Config from 'assets/config';
class AdvancedSettings extends Component {
static propTypes = {
actions: PropTypes.shape({
purgeOfflineStore: PropTypes.func.isRequired,
}).isRequired,
intl: intlShape.isRequired,
theme: PropTypes.object,
isLandscape: PropTypes.bool.isRequired,
};
state = {
cacheSize: null,
cacheSizedFetched: false,
};
componentDidMount() {
this.getDownloadCacheSize();
}
shouldComponentUpdate(nextProps) {
return this.props.theme === nextProps.theme;
}
clearOfflineCache = preventDoubleTap(() => {
const {formatMessage} = this.props.intl;
Alert.alert(
formatMessage({id: t('mobile.advanced_settings.delete_title'), defaultMessage: 'Delete Documents & Data'}),
formatMessage({id: t('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: 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},
);
});
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();
if (Platform.OS === 'android') {
dismissAllModals();
}
});
renderCacheFileSize = () => {
const {theme} = this.props;
const {cacheSize, cacheSizedFetched} = this.state;
const style = getStyleSheet(theme);
let component;
if (cacheSize === null) {
component = (
<ActivityIndicator
size='small'
color={theme.centerChannelColor}
/>
);
} else if (cacheSizedFetched) {
component = (
<Text style={style.cacheSize}>
{getFormattedFileSize({size: cacheSize})}
</Text>
);
}
return component;
};
renderSentryDebugOptions = () => {
if (!Config.ShowSentryDebugOptions) {
return null;
}
const {theme, isLandscape} = this.props;
const style = getStyleSheet(theme);
return (
<View>
<SettingsItem
defaultMessage='Throw JavaScript Exception'
iconName='md-flame'
iconType='ion'
onPress={Sentry.crash}
separator={false}
showArrow={false}
theme={theme}
isLandscape={isLandscape}
/>
<View style={style.divider}/>
<SettingsItem
defaultMessage='Throw Native Exception'
iconName='md-nuclear'
iconType='ion'
onPress={Sentry.nativeCrash}
separator={false}
showArrow={false}
theme={theme}
isLandscape={isLandscape}
/>
<View style={style.divider}/>
</View>
);
};
render() {
const {theme, isLandscape} = this.props;
const style = getStyleSheet(theme);
return (
<View style={style.container}>
<StatusBar/>
<ScrollView
contentContainerStyle={style.wrapper}
alwaysBounceVertical={false}
>
<View style={style.divider}/>
<SettingsItem
defaultMessage='Delete Documents & Data'
i18nId='mobile.advanced_settings.delete_title'
iconName='ios-refresh'
iconType='ion'
isDestructor={true}
onPress={this.clearOfflineCache}
separator={false}
showArrow={false}
rightComponent={this.renderCacheFileSize()}
theme={theme}
isLandscape={isLandscape}
/>
<View style={style.divider}/>
{this.renderSentryDebugOptions()}
</ScrollView>
</View>
);
}
}
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
return {
container: {
flex: 1,
backgroundColor: theme.centerChannelBg,
},
wrapper: {
backgroundColor: changeOpacity(theme.centerChannelColor, 0.06),
...Platform.select({
ios: {
paddingTop: 35,
},
}),
},
divider: {
backgroundColor: changeOpacity(theme.centerChannelColor, 0.1),
height: 1,
},
cacheSize: {
color: theme.centerChannelColor,
flex: 1,
fontSize: 14,
...Platform.select({
android: {
lineHeight: 68,
},
ios: {
lineHeight: 43,
},
}),
},
};
});
export default injectIntl(AdvancedSettings);