import { MenuContainer, MenuRow } from '@components/Menu' import { updateInstancePush } from '@utils/slices/instances/updatePush' import { updateInstancePushAlert } from '@utils/slices/instances/updatePushAlert' import { updateInstancePushDecode } from '@utils/slices/instances/updatePushDecode' import { getInstancePush } from '@utils/slices/instancesSlice' import * as WebBrowser from 'expo-web-browser' import * as Notifications from 'expo-notifications' import React, { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { ScrollView } from 'react-native-gesture-handler' import { useDispatch, useSelector } from 'react-redux' import layoutAnimation from '@utils/styles/layoutAnimation' import Button from '@components/Button' import { StyleConstants } from '@utils/styles/constants' import { AppState, Linking } from 'react-native' const ScreenMeSettingsPush: React.FC = () => { const { t } = useTranslation('meSettingsPush') const dispatch = useDispatch() const instancePush = useSelector(getInstancePush) const [pushEnabled, setPushEnabled] = useState() const [pushCanAskAgain, setPushCanAskAgain] = useState() const checkPush = async () => { const settings = await Notifications.getPermissionsAsync() layoutAnimation() setPushEnabled(settings.granted) setPushCanAskAgain(settings.canAskAgain) } useEffect(() => { checkPush() AppState.addEventListener('change', checkPush) return () => { AppState.removeEventListener('change', checkPush) } }, []) const isLoading = instancePush?.global.loading || instancePush?.decode.loading const alerts = useMemo(() => { return instancePush?.alerts ? (['follow', 'favourite', 'reblog', 'mention', 'poll'] as [ 'follow', 'favourite', 'reblog', 'mention', 'poll' ]).map(alert => ( dispatch( updateInstancePushAlert({ changed: alert, alerts: { ...instancePush?.alerts, [alert]: { ...instancePush?.alerts[alert], value: !instancePush?.alerts[alert].value } } }) ) } /> )) : null }, [instancePush?.global, instancePush?.alerts, isLoading]) return ( {pushEnabled === false ? (