in src/Settings.tsx [40:183]
export default function Settings() {
const [centralSimulated, simulate] = useSimulation();
const {mode} = useContext(ThemeContext);
const {colors, dark} = useTheme();
const [deliveryInterval] = useDeliveryInterval();
const {clear} = useContext(StorageContext);
const [loading] = useBoolean(false);
const styles: Literal<ViewStyle | TextStyle> = {
container: {flex: 1, marginVertical: 10},
};
const clearStorage = useCallback(() => {
Alert.alert(
Strings.Settings.Clear.Alert.Title,
Strings.Settings.Clear.Alert.Text,
[
{
text: 'Proceed',
onPress: async () => {
// IMPORTANT!: clear stored credentials before cleaning client, otherwise device will continue to re-connect
await clear();
Alert.alert(
Strings.Settings.Clear.Success.Title,
Strings.Settings.Clear.Success.Text,
);
},
},
{
text: 'Cancel',
style: 'cancel',
onPress: () => {},
},
],
{
cancelable: false,
},
);
}, [clear]);
const items = useMemo<ProfileItem[]>(
() => [
{
title: 'Registration',
icon: 'hammer-outline',
action: {
type: 'expand',
fn: (navigation: PagesNavigator) => {
// TIPS: use push as we may already have a registration screen stacked.
// this happens when a device is not registered and user goes on Registration through settings instead of from home screen
navigation.push('Registration', {
previousScreen: Pages.SETTINGS,
});
},
},
},
// {
// title: Strings.Settings.Clear.Title,
// icon: 'trash-outline',
// action: {
// type: 'select',
// fn: clearStorage,
// },
// },
{
title: Strings.Settings.Theme.Title,
icon: 'moon-outline',
subtitle: camelToName(ThemeMode[mode].toLowerCase()),
action: {
type: 'expand',
fn: navigation => {
navigation.navigate('Theme', {previousScreen: 'root'});
},
},
},
{
title: Strings.Settings.DeliveryInterval.Title,
icon: 'timer-outline',
subtitle:
Strings.Settings.DeliveryInterval[
`${deliveryInterval}` as keyof typeof Strings.Settings.DeliveryInterval
],
action: {
type: 'expand',
fn: navigation => {
navigation.navigate('Interval', {previousScreen: 'root'});
},
},
},
...(defaults.dev
? [
{
title: 'Simulation Mode',
icon: dark ? 'sync-outline' : 'sync',
action: {
type: 'switch',
fn: async (val, nav: PagesNavigator) => {
const navState = nav.getState();
await simulate(val);
if (val) {
// if simulation just applied remove registration route
nav.dispatch({
...StackActions.replace(Pages.ROOT),
source: navState.routes.find(
r => r.name === Pages.REGISTRATION,
)?.key,
target: navState.key,
});
} else {
// if simulation just applied remove registration route
nav.dispatch({
...StackActions.replace(Pages.REGISTRATION),
source: navState.routes.find(r => r.name === Pages.ROOT)
?.key,
target: navState.key,
});
}
},
},
value: centralSimulated,
} as ProfileItem,
{
title: 'Wipe data',
icon: 'trash-outline',
action: {
type: 'select',
fn: clearStorage,
},
} as ProfileItem,
]
: []),
{
title: 'Version',
value: pkg.version,
},
],
[deliveryInterval, mode, centralSimulated, dark, simulate, clearStorage],
);
return (
<View style={styles.container}>
<Root items={items} colors={colors} dark={dark} />
<Loader visible={loading} message={Strings.Core.Loading} modal={true} />
</View>
);
}