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

92 lines
2.6 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'
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'
2020-12-23 15:57:20 +01:00
import React, { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
2020-11-29 18:08:31 +01:00
const Collections: React.FC = () => {
2021-01-22 01:34:20 +01:00
const { t, i18n } = useTranslation('meRoot')
const navigation = useNavigation()
2020-11-22 00:46:23 +01:00
2021-02-28 17:41:21 +01:00
const listsQuery = useListsQuery({
options: {
notifyOnChangeProps: []
}
2021-01-31 03:09:35 +01:00
})
2021-02-28 17:41:21 +01:00
const rowLists = useMemo(() => {
if (listsQuery.isSuccess && listsQuery.data?.length) {
return (
<MenuRow
iconFront='List'
iconBack='ChevronRight'
title={t('content.collections.lists')}
onPress={() => navigation.navigate('Tab-Me-Lists')}
/>
)
2021-03-02 01:17:06 +01:00
} else {
return null
2021-02-28 17:41:21 +01:00
}
}, [listsQuery.isSuccess, listsQuery.data, i18n.language])
2020-12-23 15:57:20 +01:00
2021-02-28 17:41:21 +01:00
const announcementsQuery = useAnnouncementQuery({
showAll: true,
options: {
notifyOnChangeProps: []
}
})
const rowAnnouncements = useMemo(() => {
if (announcementsQuery.isSuccess && announcementsQuery.data?.length) {
const amount = announcementsQuery.data.filter(
announcement => !announcement.read
).length
return (
<MenuRow
iconFront='Clipboard'
iconBack='ChevronRight'
title={t('content.collections.announcements.heading')}
content={
2021-01-31 03:09:35 +01:00
amount
2021-02-28 17:41:21 +01:00
? t('content.collections.announcements.content.unread', {
amount
})
: t('content.collections.announcements.content.read')
}
onPress={() =>
navigation.navigate('Screen-Announcements', { showAll: true })
}
/>
)
2021-03-02 01:17:06 +01:00
} else {
return null
2020-12-23 15:57:20 +01:00
}
2021-02-28 17:41:21 +01:00
}, [announcementsQuery.isSuccess, announcementsQuery.data, i18n.language])
2020-12-23 15:57:20 +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'
2020-11-29 18:08:31 +01:00
title={t('content.collections.conversations')}
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'
2020-11-29 18:08:31 +01:00
title={t('content.collections.bookmarks')}
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'
2020-11-29 18:08:31 +01:00
title={t('content.collections.favourites')}
2021-01-30 01:29:15 +01:00
onPress={() => navigation.navigate('Tab-Me-Favourites')}
/>
2021-02-28 17:41:21 +01:00
{rowLists}
{rowAnnouncements}
2020-11-22 00:46:23 +01:00
</MenuContainer>
)
}
2020-11-29 18:08:31 +01:00
export default Collections