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

117 lines
3.5 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-04 17:56:47 +01:00
import { 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
2021-02-28 17:41:21 +01:00
const listsQuery = useListsQuery({
options: {
2021-05-15 23:08:13 +02:00
notifyOnChangeProps: ['data']
2021-02-28 17:41:21 +01:00
}
2021-01-31 03:09:35 +01:00
})
2021-11-15 23:43:35 +01:00
useEffect(() => {
if (listsQuery.isSuccess) {
dispatch(
2022-01-16 23:26:05 +01:00
updateInstanceMePage({
2021-11-15 23:43:35 +01:00
lists: { shown: listsQuery.data?.length ? true : false }
})
)
}
}, [listsQuery.isSuccess, listsQuery.data?.length])
2020-12-23 15:57:20 +01:00
2021-02-28 17:41:21 +01:00
const announcementsQuery = useAnnouncementQuery({
showAll: true,
options: {
2021-05-15 23:08:13 +02:00
notifyOnChangeProps: ['data']
2021-02-28 17:41:21 +01:00
}
})
2021-11-15 23:43:35 +01:00
useEffect(() => {
2022-12-04 17:56:47 +01:00
if (announcementsQuery.data) {
2021-11-15 23:43:35 +01:00
dispatch(
2022-01-16 23:26:05 +01:00
updateInstanceMePage({
2021-11-15 23:43:35 +01:00
announcements: {
2022-12-04 17:56:47 +01:00
shown: announcementsQuery.data.length ? true : false,
unread: announcementsQuery.data.filter(announcement => !announcement.read).length
2021-11-15 23:43:35 +01:00
}
})
)
}
2022-12-04 17:56:47 +01:00
}, [announcementsQuery.data])
2020-12-23 15:57:20 +01:00
2021-12-15 23:22:47 +01:00
const instancePush = useSelector(
getInstancePush,
(prev, next) => prev?.global.value === next?.global.value
)
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}
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')}
content={
2021-12-18 23:44:08 +01:00
instancePush.global.value
2021-12-15 23:22:47 +01:00
? t('me.root.push.content.enabled')
: t('me.root.push.content.disabled')
}
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