feat: add notification tabs pages (#410)

zio/stable
Joaquín Sánchez 2022-12-13 14:50:42 +01:00 committed by GitHub
parent d546390f5c
commit fd29c379dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 23 deletions

View File

@ -5,35 +5,18 @@ definePageMeta({
const { t } = useI18n() const { t } = useI18n()
// Default limit is 20 notifications, and servers are normally caped to 30
const paginatorAll = useMasto().notifications.iterate({ limit: 30 })
const paginatorMention = useMasto().notifications.iterate({ limit: 30, types: ['mention'] })
const { clearNotifications } = useNotifications()
onActivated(clearNotifications)
const stream = await useMasto().stream.streamUser()
const tabs = $computed(() => [ const tabs = $computed(() => [
{ {
name: 'all', name: 'all',
to: '/notifications',
display: t('tab.notifications_all'), display: t('tab.notifications_all'),
paginator: paginatorAll,
}, },
{ {
name: 'mention', name: 'mention',
to: '/notifications/mention',
display: t('tab.notifications_mention'), display: t('tab.notifications_mention'),
paginator: paginatorMention,
}, },
] as const) ] as const)
// Don't use local storage because it is better to default to Posts every time you visit a user's profile.
const tab = $ref(tabs[0].name)
const paginator = $computed(() => tabs.find(t => t.name === tab)!.paginator)
useHeadFixed({
title: () => t('nav_side.notifications'),
})
</script> </script>
<template> <template>
@ -46,10 +29,8 @@ useHeadFixed({
</template> </template>
<template #header> <template #header>
<CommonTabs v-model="tab" :options="tabs" /> <CommonRouteTabs replace :options="tabs" />
</template> </template>
<slot> <NuxtPage />
<NotificationPaginator :key="tab" v-bind="{ paginator, stream }" />
</slot>
</MainContent> </MainContent>
</template> </template>

View File

@ -0,0 +1,19 @@
<script setup lang="ts">
const { t } = useI18n()
// Default limit is 20 notifications, and servers are normally caped to 30
const paginator = useMasto().notifications.iterate({ limit: 30 })
const { clearNotifications } = useNotifications()
onActivated(clearNotifications)
const stream = await useMasto().stream.streamUser()
useHeadFixed({
title: () => `${t('tab.notifications_all')} | ${t('nav_side.notifications')}`,
})
</script>
<template>
<NotificationPaginator v-bind="{ paginator, stream }" />
</template>

View File

@ -0,0 +1,19 @@
<script setup lang="ts">
const { t } = useI18n()
// Default limit is 20 notifications, and servers are normally caped to 30
const paginator = useMasto().notifications.iterate({ limit: 30, types: ['mention'] })
const { clearNotifications } = useNotifications()
onActivated(clearNotifications)
const stream = await useMasto().stream.streamUser()
useHeadFixed({
title: () => `${t('tab.notifications_mention')} | ${t('nav_side.notifications')}`,
})
</script>
<template>
<NotificationPaginator v-bind="{ paginator, stream }" />
</template>