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

75 lines
2.2 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'
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-01-31 03:09:35 +01:00
const { data, isFetching } = useAnnouncementQuery({
showAll: true
})
2020-12-23 15:57:20 +01:00
const announcementContent = useMemo(() => {
if (data) {
2021-01-31 03:09:35 +01:00
if (data.length === 0) {
return t('content.collections.announcements.content.empty')
2020-12-23 15:57:20 +01:00
} else {
2021-01-31 03:09:35 +01:00
const amount = data.filter(announcement => !announcement.read).length
if (amount) {
return t('content.collections.announcements.content.unread', {
amount
})
} else {
return t('content.collections.announcements.content.read')
}
2020-12-23 15:57:20 +01:00
}
}
2021-01-22 01:34:20 +01:00
}, [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')}
/>
2020-12-03 01:28:56 +01:00
<MenuRow
iconFront='List'
iconBack='ChevronRight'
2020-11-29 18:08:31 +01:00
title={t('content.collections.lists')}
2021-01-30 01:29:15 +01:00
onPress={() => navigation.navigate('Tab-Me-Lists')}
/>
2020-12-23 15:57:20 +01:00
<MenuRow
iconFront='Clipboard'
2021-01-31 03:09:35 +01:00
iconBack={data && data.length === 0 ? undefined : 'ChevronRight'}
2021-01-19 01:13:45 +01:00
title={t('content.collections.announcements.heading')}
2020-12-23 15:57:20 +01:00
content={announcementContent}
2020-12-27 00:55:22 +01:00
loading={isFetching}
2020-12-23 15:57:20 +01:00
onPress={() =>
data &&
data.length &&
2021-01-30 01:29:15 +01:00
navigation.navigate('Screen-Announcements', { showAll: true })
2020-12-23 15:57:20 +01:00
}
/>
2020-11-22 00:46:23 +01:00
</MenuContainer>
)
}
2020-11-29 18:08:31 +01:00
export default Collections