mirror of
https://github.com/tooot-app/app
synced 2025-04-09 16:11:03 +02:00
Push not available scenario
This commit is contained in:
parent
d8703148f0
commit
47e6ca5e59
@ -144,6 +144,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"push": {
|
"push": {
|
||||||
|
"notAvailable": "Your phone does not support tooot's push notification",
|
||||||
"enable": {
|
"enable": {
|
||||||
"direct": "Enable push notification",
|
"direct": "Enable push notification",
|
||||||
"settings": "Enable in settings"
|
"settings": "Enable in settings"
|
||||||
|
@ -144,6 +144,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"push": {
|
"push": {
|
||||||
|
"notAvailable": "您的机型暂不支持 tooot 推送通知",
|
||||||
"enable": {
|
"enable": {
|
||||||
"direct": "启用推送通知",
|
"direct": "启用推送通知",
|
||||||
"settings": "在系统设置中启用"
|
"settings": "在系统设置中启用"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import analytics from '@components/analytics'
|
import analytics from '@components/analytics'
|
||||||
import Button from '@components/Button'
|
import Button from '@components/Button'
|
||||||
|
import Icon from '@components/Icon'
|
||||||
import { MenuContainer, MenuRow } from '@components/Menu'
|
import { MenuContainer, MenuRow } from '@components/Menu'
|
||||||
import { updateInstancePush } from '@utils/slices/instances/updatePush'
|
import { updateInstancePush } from '@utils/slices/instances/updatePush'
|
||||||
import { updateInstancePushAlert } from '@utils/slices/instances/updatePushAlert'
|
import { updateInstancePushAlert } from '@utils/slices/instances/updatePushAlert'
|
||||||
@ -12,14 +13,16 @@ import {
|
|||||||
} from '@utils/slices/instancesSlice'
|
} from '@utils/slices/instancesSlice'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import layoutAnimation from '@utils/styles/layoutAnimation'
|
import layoutAnimation from '@utils/styles/layoutAnimation'
|
||||||
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import * as WebBrowser from 'expo-web-browser'
|
import * as WebBrowser from 'expo-web-browser'
|
||||||
import React, { useState, useEffect, useMemo } from 'react'
|
import React, { useState, useEffect, useMemo } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { AppState, Linking, ScrollView } from 'react-native'
|
import { AppState, Linking, ScrollView, Text, View } from 'react-native'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
|
|
||||||
const TabMePush: React.FC = () => {
|
const TabMePush: React.FC = () => {
|
||||||
|
const { theme } = useTheme()
|
||||||
const { t } = useTranslation('screenTabs')
|
const { t } = useTranslation('screenTabs')
|
||||||
const instanceAccount = useSelector(
|
const instanceAccount = useSelector(
|
||||||
getInstanceAccount,
|
getInstanceAccount,
|
||||||
@ -30,6 +33,9 @@ const TabMePush: React.FC = () => {
|
|||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const instancePush = useSelector(getInstancePush)
|
const instancePush = useSelector(getInstancePush)
|
||||||
|
|
||||||
|
const [pushAvailable, setPushAvailable] = useState<boolean | undefined>(
|
||||||
|
undefined
|
||||||
|
)
|
||||||
const [pushEnabled, setPushEnabled] = useState<boolean>()
|
const [pushEnabled, setPushEnabled] = useState<boolean>()
|
||||||
const [pushCanAskAgain, setPushCanAskAgain] = useState<boolean>()
|
const [pushCanAskAgain, setPushCanAskAgain] = useState<boolean>()
|
||||||
const checkPush = async () => {
|
const checkPush = async () => {
|
||||||
@ -39,10 +45,15 @@ const TabMePush: React.FC = () => {
|
|||||||
setPushCanAskAgain(settings.canAskAgain)
|
setPushCanAskAgain(settings.canAskAgain)
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Notifications.getExpoPushTokenAsync({
|
||||||
|
experienceId: '@xmflsct/tooot'
|
||||||
|
})
|
||||||
|
.then(data => setPushAvailable(!!data))
|
||||||
|
.catch(() => setPushAvailable(false))
|
||||||
checkPush()
|
checkPush()
|
||||||
AppState.addEventListener('change', checkPush)
|
const subscription = AppState.addEventListener('change', checkPush)
|
||||||
return () => {
|
return () => {
|
||||||
AppState.removeEventListener('change', checkPush)
|
subscription.remove()
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
@ -54,13 +65,15 @@ const TabMePush: React.FC = () => {
|
|||||||
|
|
||||||
const alerts = useMemo(() => {
|
const alerts = useMemo(() => {
|
||||||
return instancePush?.alerts
|
return instancePush?.alerts
|
||||||
? (['follow', 'favourite', 'reblog', 'mention', 'poll'] as [
|
? (
|
||||||
|
['follow', 'favourite', 'reblog', 'mention', 'poll'] as [
|
||||||
'follow',
|
'follow',
|
||||||
'favourite',
|
'favourite',
|
||||||
'reblog',
|
'reblog',
|
||||||
'mention',
|
'mention',
|
||||||
'poll'
|
'poll'
|
||||||
]).map(alert => (
|
]
|
||||||
|
).map(alert => (
|
||||||
<MenuRow
|
<MenuRow
|
||||||
key={alert}
|
key={alert}
|
||||||
title={t(`me.push.${alert}.heading`)}
|
title={t(`me.push.${alert}.heading`)}
|
||||||
@ -93,6 +106,8 @@ const TabMePush: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
|
{pushAvailable !== false ? (
|
||||||
|
<>
|
||||||
{pushEnabled === false ? (
|
{pushEnabled === false ? (
|
||||||
<MenuContainer>
|
<MenuContainer>
|
||||||
<Button
|
<Button
|
||||||
@ -104,7 +119,8 @@ const TabMePush: React.FC = () => {
|
|||||||
}
|
}
|
||||||
style={{
|
style={{
|
||||||
marginTop: StyleConstants.Spacing.Global.PagePadding,
|
marginTop: StyleConstants.Spacing.Global.PagePadding,
|
||||||
marginHorizontal: StyleConstants.Spacing.Global.PagePadding * 2
|
marginHorizontal:
|
||||||
|
StyleConstants.Spacing.Global.PagePadding * 2
|
||||||
}}
|
}}
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
if (pushCanAskAgain) {
|
if (pushCanAskAgain) {
|
||||||
@ -167,6 +183,31 @@ const TabMePush: React.FC = () => {
|
|||||||
/>
|
/>
|
||||||
</MenuContainer>
|
</MenuContainer>
|
||||||
<MenuContainer>{alerts}</MenuContainer>
|
<MenuContainer>{alerts}</MenuContainer>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
minHeight: '100%',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name='Frown'
|
||||||
|
size={StyleConstants.Font.Size.L}
|
||||||
|
color={theme.primaryDefault}
|
||||||
|
/>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
...StyleConstants.FontStyle.M,
|
||||||
|
color: theme.primaryDefault
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('me.push.notAvailable')}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user