mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
@@ -14,6 +14,7 @@ import TabMePush from './Me/Push'
|
||||
import TabMeRoot from './Me/Root'
|
||||
import TabMeSettings from './Me/Settings'
|
||||
import TabMeSettingsFontsize from './Me/SettingsFontsize'
|
||||
import TabMeSettingsLanguage from './Me/SettingsLanguage'
|
||||
import TabMeSwitch from './Me/Switch'
|
||||
import TabSharedRoot from './Shared/Root'
|
||||
|
||||
@@ -152,6 +153,19 @@ const TabMe = React.memo(
|
||||
headerLeft: () => <HeaderLeft onPress={() => navigation.pop(1)} />
|
||||
})}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='Tab-Me-Settings-Language'
|
||||
component={TabMeSettingsLanguage}
|
||||
options={({ navigation }: any) => ({
|
||||
title: t('me.stacks.language.name'),
|
||||
...(Platform.OS === 'android' && {
|
||||
headerCenter: () => (
|
||||
<HeaderCenter content={t('me.stacks.language.name')} />
|
||||
)
|
||||
}),
|
||||
headerLeft: () => <HeaderLeft onPress={() => navigation.pop(1)} />
|
||||
})}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='Tab-Me-Switch'
|
||||
component={TabMeSwitch}
|
||||
|
||||
@@ -5,11 +5,8 @@ import { useActionSheet } from '@expo/react-native-action-sheet'
|
||||
import { useNavigation } from '@react-navigation/native'
|
||||
import { LOCALES } from '@root/i18n/locales'
|
||||
import { useAppDispatch } from '@root/store'
|
||||
import androidDefaults from '@utils/slices/instances/push/androidDefaults'
|
||||
import { getInstances } from '@utils/slices/instancesSlice'
|
||||
import {
|
||||
changeBrowser,
|
||||
changeLanguage,
|
||||
changeTheme,
|
||||
getSettingsTheme,
|
||||
getSettingsBrowser,
|
||||
@@ -19,11 +16,8 @@ import {
|
||||
getSettingsStaticEmoji,
|
||||
changeStaticEmoji
|
||||
} from '@utils/slices/settingsSlice'
|
||||
import { useTheme } from '@utils/styles/ThemeManager'
|
||||
import * as Notifications from 'expo-notifications'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Platform } from 'react-native'
|
||||
import { useSelector } from 'react-redux'
|
||||
import { mapFontsizeToName } from '../SettingsFontsize'
|
||||
|
||||
@@ -31,10 +25,8 @@ const SettingsApp: React.FC = () => {
|
||||
const navigation = useNavigation<any>()
|
||||
const dispatch = useAppDispatch()
|
||||
const { showActionSheetWithOptions } = useActionSheet()
|
||||
const { mode } = useTheme()
|
||||
const { t, i18n } = useTranslation('screenTabs')
|
||||
|
||||
const instances = useSelector(getInstances, () => true)
|
||||
const settingsFontsize = useSelector(getSettingsFontsize)
|
||||
const settingsTheme = useSelector(getSettingsTheme)
|
||||
const settingsDarkTheme = useSelector(getSettingsDarkTheme)
|
||||
@@ -49,102 +41,14 @@ const SettingsApp: React.FC = () => {
|
||||
`me.settings.fontsize.content.${mapFontsizeToName(settingsFontsize)}`
|
||||
)}
|
||||
iconBack='ChevronRight'
|
||||
onPress={() => {
|
||||
navigation.navigate('Tab-Me-Settings-Fontsize')
|
||||
}}
|
||||
onPress={() => navigation.navigate('Tab-Me-Settings-Fontsize')}
|
||||
/>
|
||||
<MenuRow
|
||||
title={t('me.settings.language.heading')}
|
||||
// @ts-ignore
|
||||
content={LOCALES[i18n.language]}
|
||||
iconBack='ChevronRight'
|
||||
onPress={() => {
|
||||
const options = Object.keys(LOCALES)
|
||||
// @ts-ignore
|
||||
.map(locale => LOCALES[locale])
|
||||
.concat(t('me.settings.language.options.cancel'))
|
||||
|
||||
showActionSheetWithOptions(
|
||||
{
|
||||
title: t('me.settings.language.heading'),
|
||||
options,
|
||||
cancelButtonIndex: options.length - 1,
|
||||
userInterfaceStyle: mode
|
||||
},
|
||||
buttonIndex => {
|
||||
if (buttonIndex === undefined) return
|
||||
if (buttonIndex < options.length - 1) {
|
||||
analytics('settings_language_press', {
|
||||
current: i18n.language,
|
||||
new: options[buttonIndex]
|
||||
})
|
||||
haptics('Success')
|
||||
|
||||
// @ts-ignore
|
||||
dispatch(changeLanguage(Object.keys(LOCALES)[buttonIndex]))
|
||||
i18n.changeLanguage(Object.keys(LOCALES)[buttonIndex])
|
||||
|
||||
// Update Android notification channel language
|
||||
if (Platform.OS === 'android') {
|
||||
instances.forEach(instance => {
|
||||
const accountFull = `@${instance.account.acct}@${instance.uri}`
|
||||
if (instance.push.decode.value === false) {
|
||||
Notifications.setNotificationChannelAsync(
|
||||
`${accountFull}_default`,
|
||||
{
|
||||
groupId: accountFull,
|
||||
name: t('me.push.default.heading'),
|
||||
...androidDefaults
|
||||
}
|
||||
)
|
||||
} else {
|
||||
Notifications.setNotificationChannelAsync(
|
||||
`${accountFull}_follow`,
|
||||
{
|
||||
groupId: accountFull,
|
||||
name: t('me.push.follow.heading'),
|
||||
...androidDefaults
|
||||
}
|
||||
)
|
||||
Notifications.setNotificationChannelAsync(
|
||||
`${accountFull}_favourite`,
|
||||
{
|
||||
groupId: accountFull,
|
||||
name: t('me.push.favourite.heading'),
|
||||
...androidDefaults
|
||||
}
|
||||
)
|
||||
Notifications.setNotificationChannelAsync(
|
||||
`${accountFull}_reblog`,
|
||||
{
|
||||
groupId: accountFull,
|
||||
name: t('me.push.reblog.heading'),
|
||||
...androidDefaults
|
||||
}
|
||||
)
|
||||
Notifications.setNotificationChannelAsync(
|
||||
`${accountFull}_mention`,
|
||||
{
|
||||
groupId: accountFull,
|
||||
name: t('me.push.mention.heading'),
|
||||
...androidDefaults
|
||||
}
|
||||
)
|
||||
Notifications.setNotificationChannelAsync(
|
||||
`${accountFull}_poll`,
|
||||
{
|
||||
groupId: accountFull,
|
||||
name: t('me.push.poll.heading'),
|
||||
...androidDefaults
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}}
|
||||
onPress={() => navigation.navigate('Tab-Me-Settings-Language')}
|
||||
/>
|
||||
<MenuRow
|
||||
title={t('me.settings.theme.heading')}
|
||||
|
||||
@@ -45,7 +45,7 @@ const TabMeSettingsFontsize: React.FC<
|
||||
const item = {
|
||||
id: 'demo',
|
||||
uri: 'https://tooot.app',
|
||||
created_at: new Date(),
|
||||
created_at: new Date(2021, 4, 16),
|
||||
sensitive: false,
|
||||
visibility: 'public',
|
||||
replies_count: 0,
|
||||
@@ -67,6 +67,7 @@ const TabMeSettingsFontsize: React.FC<
|
||||
username: 'tooot📱',
|
||||
acct: 'tooot@xmflsct.com',
|
||||
display_name: 'tooot📱',
|
||||
avatar: 'https://avatars.githubusercontent.com/u/77554750?s=100',
|
||||
avatar_static: 'https://avatars.githubusercontent.com/u/77554750?s=100'
|
||||
},
|
||||
media_attachments: [],
|
||||
@@ -100,7 +101,7 @@ const TabMeSettingsFontsize: React.FC<
|
||||
}, [theme, initialSize])
|
||||
|
||||
return (
|
||||
<ScrollView scrollEnabled={false}>
|
||||
<ScrollView>
|
||||
<CustomText
|
||||
fontStyle='M'
|
||||
style={{
|
||||
|
||||
97
src/screens/Tabs/Me/SettingsLanguage.tsx
Normal file
97
src/screens/Tabs/Me/SettingsLanguage.tsx
Normal file
@@ -0,0 +1,97 @@
|
||||
import analytics from '@components/analytics'
|
||||
import haptics from '@components/haptics'
|
||||
import { MenuContainer, MenuRow } from '@components/Menu'
|
||||
import { LOCALES } from '@root/i18n/locales'
|
||||
import { TabMeStackScreenProps } from '@utils/navigation/navigators'
|
||||
import androidDefaults from '@utils/slices/instances/push/androidDefaults'
|
||||
import { getInstances } from '@utils/slices/instancesSlice'
|
||||
import { changeLanguage } from '@utils/slices/settingsSlice'
|
||||
import * as Notifications from 'expo-notifications'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FlatList, Platform } from 'react-native'
|
||||
import { useDispatch, useSelector } from 'react-redux'
|
||||
|
||||
const TabMeSettingsLanguage: React.FC<
|
||||
TabMeStackScreenProps<'Tab-Me-Settings-Language'>
|
||||
> = () => {
|
||||
const { i18n, t } = useTranslation('screenTabs')
|
||||
const languages = Object.entries(LOCALES)
|
||||
const instances = useSelector(getInstances)
|
||||
const dispatch = useDispatch()
|
||||
|
||||
const change = (lang: string) => {
|
||||
analytics('settings_language_press', {
|
||||
current: i18n.language,
|
||||
new: lang
|
||||
})
|
||||
haptics('Success')
|
||||
|
||||
dispatch(changeLanguage(lang))
|
||||
i18n.changeLanguage(lang)
|
||||
|
||||
// Update Android notification channel language
|
||||
if (Platform.OS === 'android') {
|
||||
instances.forEach(instance => {
|
||||
const accountFull = `@${instance.account.acct}@${instance.uri}`
|
||||
if (instance.push.decode.value === false) {
|
||||
Notifications.setNotificationChannelAsync(`${accountFull}_default`, {
|
||||
groupId: accountFull,
|
||||
name: t('me.push.default.heading'),
|
||||
...androidDefaults
|
||||
})
|
||||
} else {
|
||||
Notifications.setNotificationChannelAsync(`${accountFull}_follow`, {
|
||||
groupId: accountFull,
|
||||
name: t('me.push.follow.heading'),
|
||||
...androidDefaults
|
||||
})
|
||||
Notifications.setNotificationChannelAsync(
|
||||
`${accountFull}_favourite`,
|
||||
{
|
||||
groupId: accountFull,
|
||||
name: t('me.push.favourite.heading'),
|
||||
...androidDefaults
|
||||
}
|
||||
)
|
||||
Notifications.setNotificationChannelAsync(`${accountFull}_reblog`, {
|
||||
groupId: accountFull,
|
||||
name: t('me.push.reblog.heading'),
|
||||
...androidDefaults
|
||||
})
|
||||
Notifications.setNotificationChannelAsync(`${accountFull}_mention`, {
|
||||
groupId: accountFull,
|
||||
name: t('me.push.mention.heading'),
|
||||
...androidDefaults
|
||||
})
|
||||
Notifications.setNotificationChannelAsync(`${accountFull}_poll`, {
|
||||
groupId: accountFull,
|
||||
name: t('me.push.poll.heading'),
|
||||
...androidDefaults
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<MenuContainer>
|
||||
<FlatList
|
||||
data={languages}
|
||||
renderItem={({ item }) => {
|
||||
return (
|
||||
<MenuRow
|
||||
key={item[0]}
|
||||
title={item[1]}
|
||||
iconBack={item[0] === i18n.language ? 'Check' : undefined}
|
||||
iconBackColor={'blue'}
|
||||
onPress={() => item[0] !== i18n.language && change(item[0])}
|
||||
/>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</MenuContainer>
|
||||
)
|
||||
}
|
||||
|
||||
export default TabMeSettingsLanguage
|
||||
Reference in New Issue
Block a user