1
0
elk/pages/notifications.vue

103 lines
2.8 KiB
Vue
Raw Normal View History

2022-11-16 06:21:54 +09:00
<script setup lang="ts">
import type { mastodon } from 'masto'
import { NOTIFICATION_FILTER_TYPES } from '~/constants'
import type { CommonRouteTabMoreOption, CommonRouteTabOption } from '~/types'
2023-01-25 03:52:48 +09:00
2022-11-16 06:21:54 +09:00
definePageMeta({
middleware: 'auth',
})
const route = useRoute()
2022-11-28 23:25:32 +09:00
const { t } = useI18n()
const pwaEnabled = useAppConfig().pwaEnabled
2022-11-28 23:25:32 +09:00
const tabs = computed<CommonRouteTabOption[]>(() => [
2022-11-30 08:25:29 +09:00
{
name: 'all',
to: '/notifications',
display: t('tab.notifications_all'),
2022-11-30 08:25:29 +09:00
},
{
name: 'mention',
to: '/notifications/mention',
display: t('tab.notifications_mention'),
2022-11-30 08:25:29 +09:00
},
2023-01-25 03:52:48 +09:00
])
const filter = computed<mastodon.v1.NotificationType | undefined>(() => {
if (!isHydrated.value)
return undefined
const rawFilter = route.params?.filter
const actualFilter = Array.isArray(rawFilter) ? rawFilter[0] : rawFilter
if (isNotificationFilter(actualFilter))
return actualFilter
return undefined
})
const filterIconMap: Record<mastodon.v1.NotificationType, string> = {
'mention': 'i-ri:at-line',
'status': 'i-ri:account-pin-circle-line',
'reblog': 'i-ri:repeat-fill',
'follow': 'i-ri:user-follow-line',
'follow_request': 'i-ri:user-shared-line',
'favourite': 'i-ri:heart-3-line',
'poll': 'i-ri:chat-poll-line',
'update': 'i-ri:edit-2-line',
'admin.sign_up': 'i-ri:user-add-line',
'admin.report': 'i-ri:flag-line',
}
const filterText = computed(() => `${t('tab.notifications_more_tooltip')}${filter.value ? `: ${t(`tab.notifications_${filter.value}`)}` : ''}`)
const notificationFilterRoutes = computed<CommonRouteTabOption[]>(() => NOTIFICATION_FILTER_TYPES.map(
name => ({
name,
to: `/notifications/${name}`,
display: t(`tab.notifications_${name}`),
icon: filterIconMap[name],
match: name === filter.value,
}),
))
const moreOptions = computed<CommonRouteTabMoreOption>(() => ({
options: notificationFilterRoutes.value,
icon: 'i-ri:filter-2-line',
tooltip: filterText.value,
match: !!filter.value,
}))
2022-11-16 06:21:54 +09:00
</script>
<template>
2022-12-31 03:16:23 +09:00
<MainContent>
2022-11-16 06:21:54 +09:00
<template #title>
2023-01-05 08:17:30 +09:00
<NuxtLink to="/notifications" timeline-title-style flex items-center gap-2 @click="$scrollToTop">
2022-11-30 05:15:53 +09:00
<div i-ri:notification-4-line />
<span>{{ t('nav.notifications') }}</span>
2022-11-30 05:15:53 +09:00
</NuxtLink>
2022-11-16 06:21:54 +09:00
</template>
2022-11-24 15:42:26 +09:00
<template #actions>
<NuxtLink
flex rounded-4 p1
hover:bg-active cursor-pointer transition-100
:title="t('settings.notifications.show_btn')"
to="/settings/notifications"
>
<span aria-hidden="true" i-ri:notification-badge-line />
</NuxtLink>
</template>
2022-11-23 17:08:49 +09:00
<template #header>
<CommonRouteTabs replace :options="tabs" :more-options="moreOptions" />
2022-11-23 17:08:49 +09:00
</template>
<slot>
<template v-if="pwaEnabled">
<NotificationPreferences />
</template>
<NuxtPage />
</slot>
2022-11-16 06:21:54 +09:00
</MainContent>
</template>