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

70 lines
2.0 KiB
TypeScript
Raw Normal View History

import { useNavigation } from '@react-navigation/native'
2020-12-23 15:57:20 +01:00
import React, { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
2020-12-13 14:04:25 +01:00
import { MenuContainer, MenuRow } from '@components/Menu'
2020-12-23 15:57:20 +01:00
import { useQuery } from 'react-query'
import { announcementFetch } from '@root/utils/fetches/announcementsFetch'
2020-11-22 00:46:23 +01:00
2020-11-29 18:08:31 +01:00
const Collections: React.FC = () => {
const { t } = useTranslation('meRoot')
const navigation = useNavigation()
2020-11-22 00:46:23 +01:00
2020-12-23 15:57:20 +01:00
const queryKey = ['Announcements', { showAll: true }]
2020-12-27 00:55:22 +01:00
const { data, isFetching } = useQuery(queryKey, announcementFetch)
2020-12-23 15:57:20 +01:00
const announcementContent = useMemo(() => {
if (data) {
const amount = data.filter(announcement => !announcement.read).length
if (amount) {
return `${amount} 条未读公告`
} else {
return '无未读公告'
}
}
}, [data])
2020-11-22 00:46:23 +01:00
return (
<MenuContainer>
2020-12-03 01:28:56 +01:00
<MenuRow
iconFront='mail'
2020-12-23 15:57:20 +01:00
iconBack='chevron-right'
2020-11-29 18:08:31 +01:00
title={t('content.collections.conversations')}
onPress={() => navigation.navigate('Screen-Me-Conversations')}
/>
2020-12-03 01:28:56 +01:00
<MenuRow
iconFront='bookmark'
2020-12-23 15:57:20 +01:00
iconBack='chevron-right'
2020-11-29 18:08:31 +01:00
title={t('content.collections.bookmarks')}
onPress={() => navigation.navigate('Screen-Me-Bookmarks')}
/>
2020-12-03 01:28:56 +01:00
<MenuRow
iconFront='star'
2020-12-23 15:57:20 +01:00
iconBack='chevron-right'
2020-11-29 18:08:31 +01:00
title={t('content.collections.favourites')}
onPress={() => navigation.navigate('Screen-Me-Favourites')}
/>
2020-12-03 01:28:56 +01:00
<MenuRow
iconFront='list'
2020-12-23 15:57:20 +01:00
iconBack='chevron-right'
2020-11-29 18:08:31 +01:00
title={t('content.collections.lists')}
onPress={() => navigation.navigate('Screen-Me-Lists')}
/>
2020-12-23 15:57:20 +01:00
<MenuRow
iconFront='clipboard'
iconBack='chevron-right'
title={t('content.collections.announcements')}
content={announcementContent}
2020-12-27 00:55:22 +01:00
loading={isFetching}
2020-12-23 15:57:20 +01:00
onPress={() =>
data &&
data.length &&
navigation.navigate('Screen-Shared-Announcements', { showAll: true })
}
/>
2020-11-22 00:46:23 +01:00
</MenuContainer>
)
}
2020-11-29 18:08:31 +01:00
export default Collections