tooot/src/screens/Tabs/Me/Root/Collections.tsx

130 lines
3.9 KiB
TypeScript
Raw Normal View History

2021-01-19 01:13:45 +01:00
import { MenuContainer, MenuRow } from '@components/Menu'
import { useNavigation } from '@react-navigation/native'
2022-04-30 23:47:52 +02:00
import { useAppDispatch } from '@root/store'
2021-01-19 01:13:45 +01:00
import { useAnnouncementQuery } from '@utils/queryHooks/announcement'
2021-02-28 17:41:21 +01:00
import { useListsQuery } from '@utils/queryHooks/lists'
2022-12-10 20:19:18 +01:00
import { useFollowedTagsQuery } from '@utils/queryHooks/tags'
2022-12-15 19:31:20 +01:00
import {
checkInstanceFeature,
getInstanceMePage,
updateInstanceMePage
} from '@utils/slices/instancesSlice'
2021-12-15 23:22:47 +01:00
import { getInstancePush } from '@utils/slices/instancesSlice'
2021-11-15 23:43:35 +01:00
import React, { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
2022-04-30 23:47:52 +02:00
import { useSelector } from 'react-redux'
2020-11-29 18:08:31 +01:00
const Collections: React.FC = () => {
2021-05-15 23:08:13 +02:00
const { t } = useTranslation('screenTabs')
2021-08-29 15:25:38 +02:00
const navigation = useNavigation<any>()
2020-11-22 00:46:23 +01:00
2022-04-30 23:47:52 +02:00
const dispatch = useAppDispatch()
2022-01-16 23:26:05 +01:00
const mePage = useSelector(getInstanceMePage)
2021-11-15 23:43:35 +01:00
2022-12-15 19:31:20 +01:00
const canFollowTags = useSelector(checkInstanceFeature('follow_tags'))
2022-12-10 20:19:18 +01:00
useFollowedTagsQuery({
2021-02-28 17:41:21 +01:00
options: {
2022-12-15 19:31:20 +01:00
enabled: canFollowTags,
2022-12-10 20:19:18 +01:00
onSuccess: data =>
dispatch(
updateInstanceMePage({
followedTags: { shown: !!data?.pages?.[0].body?.length }
})
)
2021-02-28 17:41:21 +01:00
}
2021-01-31 03:09:35 +01:00
})
2022-12-10 20:19:18 +01:00
useListsQuery({
options: {
onSuccess: data =>
dispatch(
updateInstanceMePage({
lists: { shown: !!data?.length }
})
)
2021-11-15 23:43:35 +01:00
}
2022-12-10 20:19:18 +01:00
})
useAnnouncementQuery({
2021-02-28 17:41:21 +01:00
showAll: true,
options: {
2022-12-10 20:19:18 +01:00
onSuccess: data =>
dispatch(
updateInstanceMePage({
announcements: {
shown: !!data?.length ? true : false,
unread: data?.filter(announcement => !announcement.read).length
}
})
)
2021-02-28 17:41:21 +01:00
}
})
2020-12-23 15:57:20 +01:00
2022-12-09 21:09:00 +01:00
const instancePush = useSelector(getInstancePush, (prev, next) => prev?.global === next?.global)
2021-12-15 23:22:47 +01:00
2020-11-22 00:46:23 +01:00
return (
<MenuContainer>
2020-12-03 01:28:56 +01:00
<MenuRow
iconFront='Mail'
iconBack='ChevronRight'
2021-03-28 23:31:10 +02:00
title={t('me.stacks.conversations.name')}
2021-01-30 01:29:15 +01:00
onPress={() => navigation.navigate('Tab-Me-Conversations')}
/>
2020-12-03 01:28:56 +01:00
<MenuRow
iconFront='Bookmark'
iconBack='ChevronRight'
2021-03-28 23:31:10 +02:00
title={t('me.stacks.bookmarks.name')}
2021-01-30 01:29:15 +01:00
onPress={() => navigation.navigate('Tab-Me-Bookmarks')}
/>
2020-12-03 01:28:56 +01:00
<MenuRow
2021-02-10 00:40:44 +01:00
iconFront='Heart'
iconBack='ChevronRight'
2021-03-28 23:31:10 +02:00
title={t('me.stacks.favourites.name')}
2021-01-30 01:29:15 +01:00
onPress={() => navigation.navigate('Tab-Me-Favourites')}
/>
2021-11-15 23:43:35 +01:00
{mePage.lists.shown ? (
2021-05-15 23:08:13 +02:00
<MenuRow
iconFront='List'
iconBack='ChevronRight'
title={t('me.stacks.lists.name')}
onPress={() => navigation.navigate('Tab-Me-List-List')}
2021-05-15 23:08:13 +02:00
/>
) : null}
2022-12-10 20:19:18 +01:00
{mePage.followedTags.shown ? (
<MenuRow
iconFront='Hash'
iconBack='ChevronRight'
title={t('me.stacks.followedTags.name')}
onPress={() => navigation.navigate('Tab-Me-FollowedTags')}
/>
) : null}
2021-11-15 23:43:35 +01:00
{mePage.announcements.shown ? (
2021-05-15 23:08:13 +02:00
<MenuRow
iconFront='Clipboard'
iconBack='ChevronRight'
title={t('screenAnnouncements:heading')}
content={
2021-11-15 23:43:35 +01:00
mePage.announcements.unread
2021-05-15 23:08:13 +02:00
? t('me.root.announcements.content.unread', {
2021-11-15 23:43:35 +01:00
amount: mePage.announcements.unread
2021-05-15 23:08:13 +02:00
})
: t('me.root.announcements.content.read')
}
2022-12-04 17:56:47 +01:00
onPress={() => navigation.navigate('Screen-Announcements', { showAll: true })}
2021-05-15 23:08:13 +02:00
/>
) : null}
2021-12-15 23:22:47 +01:00
<MenuRow
iconFront={instancePush ? 'Bell' : 'BellOff'}
iconBack='ChevronRight'
title={t('me.stacks.push.name')}
2022-12-21 01:07:12 +01:00
content={
typeof instancePush.global === 'boolean'
? t('me.root.push.content', { context: instancePush.global.toString() })
: undefined
}
2021-12-15 23:22:47 +01:00
onPress={() => navigation.navigate('Tab-Me-Push')}
/>
2020-11-22 00:46:23 +01:00
</MenuContainer>
)
}
2020-11-29 18:08:31 +01:00
export default Collections