diff --git a/src/@types/react-navigation.d.ts b/src/@types/react-navigation.d.ts index 3d6798b5..a87a6078 100644 --- a/src/@types/react-navigation.d.ts +++ b/src/@types/react-navigation.d.ts @@ -12,6 +12,9 @@ declare namespace Nav { type: 'account' account: Mastodon.Account } + | { + type: 'notifications_filter' + } 'Screen-Announcements': { showAll: boolean } 'Screen-Compose': | { diff --git a/src/api/general.ts b/src/api/general.ts index 2cd364f7..56cda191 100644 --- a/src/api/general.ts +++ b/src/api/general.ts @@ -9,7 +9,7 @@ export type Params = { domain?: string url: string params?: { - [key: string]: string | number | boolean + [key: string]: string | number | boolean | string[] | number[] | boolean[] } headers?: { [key: string]: string } body?: FormData | Object diff --git a/src/api/instance.ts b/src/api/instance.ts index 595f53b0..5bfd48c8 100644 --- a/src/api/instance.ts +++ b/src/api/instance.ts @@ -10,7 +10,7 @@ export type Params = { version?: 'v1' | 'v2' url: string params?: { - [key: string]: string | number | boolean + [key: string]: string | number | boolean | string[] | number[] | boolean[] } headers?: { [key: string]: string } body?: FormData diff --git a/src/i18n/en/_all.ts b/src/i18n/en/_all.ts index 4fc87212..2512e104 100644 --- a/src/i18n/en/_all.ts +++ b/src/i18n/en/_all.ts @@ -32,5 +32,6 @@ export default { componentRelativeTime: require('./components/relativeTime').default, componentTimeline: require('./components/timeline').default, + screenActions: require('./screens/screenActions').default, screenImageViewer: require('./screens/screenImageViewer').default } diff --git a/src/i18n/en/common.ts b/src/i18n/en/common.ts index 94937194..24705143 100644 --- a/src/i18n/en/common.ts +++ b/src/i18n/en/common.ts @@ -15,6 +15,7 @@ export default { localCorrupt: 'Login expired, please login again' }, buttons: { + apply: 'Apply', cancel: 'Cancel' }, toastMessage: { diff --git a/src/i18n/en/screens/screenActions.ts b/src/i18n/en/screens/screenActions.ts new file mode 100644 index 00000000..9bb5b72d --- /dev/null +++ b/src/i18n/en/screens/screenActions.ts @@ -0,0 +1,19 @@ +export default { + content: { + button: { + apply: '$t(common:buttons.apply)', + cancel: '$t(common:buttons.cancel)' + }, + notificationsFilter: { + heading: 'Show notification types', + content: { + follow: '$t(meSettingsPush:content.follow.heading)', + favourite: '$t(meSettingsPush:content.favourite.heading)', + reblog: '$t(meSettingsPush:content.reblog.heading)', + mention: '$t(meSettingsPush:content.mention.heading)', + poll: '$t(meSettingsPush:content.poll.heading)', + follow_request: 'Follow request' + } + } + } +} diff --git a/src/i18n/zh-Hans/_all.ts b/src/i18n/zh-Hans/_all.ts index 4fc87212..2512e104 100644 --- a/src/i18n/zh-Hans/_all.ts +++ b/src/i18n/zh-Hans/_all.ts @@ -32,5 +32,6 @@ export default { componentRelativeTime: require('./components/relativeTime').default, componentTimeline: require('./components/timeline').default, + screenActions: require('./screens/screenActions').default, screenImageViewer: require('./screens/screenImageViewer').default } diff --git a/src/i18n/zh-Hans/common.ts b/src/i18n/zh-Hans/common.ts index 7b6b825c..854c9fb2 100644 --- a/src/i18n/zh-Hans/common.ts +++ b/src/i18n/zh-Hans/common.ts @@ -14,6 +14,7 @@ export default { localCorrupt: '登录已过期,请重新登录' }, buttons: { + apply: '应用', cancel: '取消' }, toastMessage: { diff --git a/src/i18n/zh-Hans/screens/screenActions.ts b/src/i18n/zh-Hans/screens/screenActions.ts new file mode 100644 index 00000000..5bf080d2 --- /dev/null +++ b/src/i18n/zh-Hans/screens/screenActions.ts @@ -0,0 +1,19 @@ +export default { + content: { + button: { + apply: '$t(common:buttons.apply)', + cancel: '$t(common:buttons.cancel)' + }, + notificationsFilter: { + heading: '显示通知', + content: { + follow: '$t(meSettingsPush:content.follow.heading)', + favourite: '$t(meSettingsPush:content.favourite.heading)', + reblog: '$t(meSettingsPush:content.reblog.heading)', + mention: '$t(meSettingsPush:content.mention.heading)', + poll: '$t(meSettingsPush:content.poll.heading)', + follow_request: '关注请求' + } + } + } +} diff --git a/src/screens/Actions/NotificationsFilter.tsx b/src/screens/Actions/NotificationsFilter.tsx new file mode 100644 index 00000000..de21fcb3 --- /dev/null +++ b/src/screens/Actions/NotificationsFilter.tsx @@ -0,0 +1,94 @@ +import Button from '@components/Button' +import MenuContainer from '@components/Menu/Container' +import MenuHeader from '@components/Menu/Header' +import MenuRow from '@components/Menu/Row' +import { useNavigation } from '@react-navigation/native' +import { + getInstanceNotificationsFilter, + updateInstanceNotificationsFilter +} from '@utils/slices/instancesSlice' +import { StyleConstants } from '@utils/styles/constants' +import React, { useMemo } from 'react' +import { StyleSheet } from 'react-native' +import { useTranslation } from 'react-i18next' +import { useDispatch, useSelector } from 'react-redux' +import { useQueryClient } from 'react-query' +import { QueryKeyTimeline } from '@utils/queryHooks/timeline' + +const ActionsNotificationsFilter: React.FC = () => { + const navigation = useNavigation() + const { t } = useTranslation('screenActions') + + const queryKey: QueryKeyTimeline = ['Timeline', { page: 'Notifications' }] + const queryClient = useQueryClient() + + const dispatch = useDispatch() + const instanceNotificationsFilter = useSelector( + getInstanceNotificationsFilter + ) + + if (!instanceNotificationsFilter) { + navigation.goBack() + return null + } + + const options = useMemo(() => { + return ( + instanceNotificationsFilter && + ([ + 'follow', + 'favourite', + 'reblog', + 'mention', + 'poll', + 'follow_request' + ] as [ + 'follow', + 'favourite', + 'reblog', + 'mention', + 'poll', + 'follow_request' + ]).map(type => ( + + dispatch( + updateInstanceNotificationsFilter({ + ...instanceNotificationsFilter, + [type]: !instanceNotificationsFilter[type] + }) + ) + } + /> + )) + ) + }, [instanceNotificationsFilter]) + + return ( + <> + + + {options} + +