mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
tying in notifications to updated settings
This commit is contained in:
parent
04ec4f5959
commit
894ac14a10
@ -27,7 +27,7 @@ const Strings = [
|
||||
monthEnd: 'dd/mm',
|
||||
|
||||
sealUnset: 'Generate a key to enable end-to-end encrypted topics.',
|
||||
sealUnlocked: 'Disabling the sealing key will prevent access to all end-to-end encrypted topics from this device until the key is unlocked again.',
|
||||
sealUnlocked: 'Disabling the sealing key will block access to all end-to-end encrypted topics from this device until the key is unlocked again.',
|
||||
sealLocked: 'Unlock the sealing key to support end-to-end encrypted topics on this device.',
|
||||
sealDelete: 'Deleting the sealing key will premanently remove access to any existing end-to-end encrypted topics for ALL of your devices.',
|
||||
password: 'Password',
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
import { ActivityIndicator, KeyboardAvoidingView, Modal, ScrollView, View, Switch, Text, TextInput, TouchableOpacity, Alert } from 'react-native';
|
||||
import { Linking, ActivityIndicator, KeyboardAvoidingView, Modal, ScrollView, View, Switch, Text, TextInput, TouchableOpacity, Alert } from 'react-native';
|
||||
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
|
||||
import { styles } from './Settings.styled';
|
||||
import { useSettings } from './useSettings.hook';
|
||||
@ -29,6 +29,19 @@ export function Settings() {
|
||||
}
|
||||
};
|
||||
|
||||
const setNotifications = async (notify) => {
|
||||
try {
|
||||
await actions.setNotifications(notify);
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
Alert.alert(
|
||||
'Failed to update account notifications',
|
||||
'Please try again.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollView style={styles.content}>
|
||||
<SafeAreaView edges={['top']}>
|
||||
@ -41,7 +54,8 @@ export function Settings() {
|
||||
</View>
|
||||
<View style={styles.optionControl}>
|
||||
<Text style={styles.optionLink}>{ state.strings.enableNotifications }</Text>
|
||||
<Switch value={true} style={styles.notifications} thumbColor={Colors.sliderGrip} ios_backgroundColor={Colors.disabledIndicator} trackColor={styles.track}/>
|
||||
<Switch value={state.pushEnabled} style={styles.notifications} thumbColor={Colors.sliderGrip} ios_backgroundColor={Colors.disabledIndicator}
|
||||
trackColor={styles.track} onValueChange={setNotifications} />
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
<View style={styles.divider} />
|
||||
@ -183,7 +197,7 @@ export function Settings() {
|
||||
|
||||
<Text style={styles.label}>{ state.strings.support }</Text>
|
||||
<View style={styles.group}>
|
||||
<TouchableOpacity style={styles.entry} activeOpacity={1}>
|
||||
<TouchableOpacity style={styles.entry} activeOpacity={1} onPress={() => Linking.openURL('https://github.com/balzack/databag/discussions')}>
|
||||
<View style={styles.icon}>
|
||||
<MatIcons name="help-network-outline" size={20} color={Colors.linkText} />
|
||||
</View>
|
||||
|
@ -13,6 +13,7 @@ export function useSettings() {
|
||||
strings: getLanguageStrings(),
|
||||
timeFull: false,
|
||||
monthLast: false,
|
||||
pushEnabled: null,
|
||||
|
||||
editSeal: false,
|
||||
sealEnabled: false,
|
||||
@ -36,11 +37,12 @@ export function useSettings() {
|
||||
}, [profile.state.timeFull, profile.state.monthLast]);
|
||||
|
||||
useEffect(() => {
|
||||
const { seal, sealable } = account.state.status;
|
||||
const { seal, sealable, pushEnabled } = account.state.status;
|
||||
const sealKey = account.state.sealKey;
|
||||
const sealEnabled = seal?.publicKey != null;
|
||||
const sealUnlocked = seal?.publicKey === sealKey?.public && sealKey?.private && sealKey?.public;
|
||||
updateState({ sealable, seal, sealKey, sealEnabled, sealUnlocked });
|
||||
updateState({ sealable, seal, sealKey, sealEnabled, sealUnlocked, pushEnabled });
|
||||
|
||||
}, [account.state]);
|
||||
|
||||
const unlockKey = async () => {
|
||||
@ -75,6 +77,9 @@ export function useSettings() {
|
||||
updateState({ monthLast: flag });
|
||||
await profile.actions.setMonthLast(flag);
|
||||
},
|
||||
setNotifications: async (flag) => {
|
||||
await account.actions.setNotifications(flag);
|
||||
},
|
||||
showEditSeal: () => {
|
||||
updateState({ editSeal: true, sealPassword: null, sealConfirm: null, hidePassword: true, hideConfirm: true,
|
||||
sealDelete: null, sealRemove: false, sealUpdate: false });
|
||||
|
Loading…
Reference in New Issue
Block a user