import React, { Component, useState } from 'react';
import {
Platform,
StyleSheet,
TouchableOpacity,
Text,
ScrollView,
View,
Switch
} from 'react-native';
import I18n from './i18n';
import AsyncStorage from '@react-native-community/async-storage'
const STORAGE_KEY_ANNOUNCEMENT = "announcementNotifs"
const STORAGE_KEY_EVENT = "eventNotifs"
function parseBoolean (val) {
if (val == "true") {
return true;
}
else if (val == "false") {
return false;
}
}
function AnnouncementNotifs() {
const [ isEnabled, setIsEnabled ] = React.useState()
React.useEffect(() => {
const checkAsync = async () => {
const value = await AsyncStorage.getItem('announcementNotifs')
if (value !== undefined || value !== null){
setIsEnabled(parseBoolean(value))
} else {
setIsEnabled(false)
AsyncStorage.setItem('announcementNotifs', JSON.stringify('false'))
}
}
checkAsync()
}, [])
const toggleSwitch = () => {
AsyncStorage.getItem('announcementNotifs')
.then((token) => {
const temp = parseBoolean(token)
AsyncStorage.setItem('announcementNotifs', JSON.stringify(!temp))
setIsEnabled(!isEnabled)
})
}
return (
{I18n.t('notifications.announcements')}
)
}
function EventNotifs() {
const [ isEnabled, setIsEnabled ] = React.useState()
React.useEffect(() => {
const checkAsync = async () => {
const value = await AsyncStorage.getItem('eventNotifs')
if (value !== undefined || value !== null){
setIsEnabled(parseBoolean(value))
} else {
setIsEnabled(false)
AsyncStorage.setItem('eventNotifs', JSON.stringify('false'))
}
}
checkAsync()
}, [])
const toggleSwitch = () => {
AsyncStorage.getItem('eventNotifs')
.then((token) => {
const temp = parseBoolean(token)
AsyncStorage.setItem('eventNotifs', JSON.stringify(!temp))
setIsEnabled(!isEnabled)
})
}
return (
{I18n.t('notifications.events')}
)
}
class Notifications extends Component {
render() {
return (
Notifs
/*
*/
);
}
}
export default Notifications