|
2 | 2 | <div class="relative"> |
3 | 3 | <slot |
4 | 4 | name="trigger" |
5 | | - :unread-count="notificationsStore.unreadCount" |
| 5 | + :unread-count="unreadCount" |
6 | 6 | :is-open="isOpen" |
7 | 7 | :toggle="() => (isOpen = !isOpen)" |
8 | 8 | /> |
|
17 | 17 | <div |
18 | 18 | class="fixed w-[400px] p-4 mb-3 border-b border-gray-200 dark:border-slate-800 shadow dark:shadow-slate-900 rounded-lg z-30 backdrop-blur-lg bg-white/60 dark:bg-slate-950/60" |
19 | 19 | > |
20 | | - <h3 class="text-lg font-semibold dark:text-slate-500"> |
21 | | - {{ t('common.notifications') }} |
22 | | - </h3> |
| 20 | + <div class="flex justify-between"> |
| 21 | + <h3 class="text-lg font-semibold dark:text-slate-500"> |
| 22 | + {{ t('common.notifications') }} |
| 23 | + </h3> |
| 24 | + |
| 25 | + <button |
| 26 | + v-if="unreadCount" |
| 27 | + class="text-xs font-bold bg-[#F02C56] border border-[#F02C56] text-white rounded-lg px-5 py-2 hover:bg-[#F02C56]/90 hover:border-[#F02C5699] cursor-pointer" |
| 28 | + @click="markAllRead" |
| 29 | + > |
| 30 | + {{ $t('common.markAllRead') }} |
| 31 | + </button> |
| 32 | + </div> |
23 | 33 | </div> |
24 | 34 |
|
25 | 35 | <div class="relative top-[60px]"> |
|
132 | 142 | </template> |
133 | 143 |
|
134 | 144 | <script setup> |
135 | | -import { ref, onMounted } from 'vue' |
| 145 | +import { ref, onMounted, computed } from 'vue' |
136 | 146 | import { useNotificationStore } from '~/stores/notifications' |
137 | 147 | import { useNotifications } from '~/composables/useNotifications' |
138 | 148 | import { format } from 'date-fns' |
139 | 149 | import { useRouter } from 'vue-router' |
140 | 150 | import LoopLink from '../LoopLink.vue' |
141 | 151 | import { useI18n } from 'vue-i18n' |
| 152 | +import { useAlertModal } from '@/composables/useAlertModal.js' |
142 | 153 | const { t } = useI18n() |
143 | 154 | import { useUtils } from '@/composables/useUtils' |
144 | 155 |
|
145 | 156 | const isOpen = ref(false) |
146 | | -const notificationsStore = useNotificationStore() |
| 157 | +const notificationStore = useNotificationStore() |
147 | 158 | const router = useRouter() |
148 | 159 | const { truncateMiddle, formatNumber, formatDate } = useUtils() |
| 160 | +const { alertModal, confirmModal } = useAlertModal() |
149 | 161 |
|
150 | 162 | const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isError } = |
151 | 163 | useNotifications() |
152 | 164 |
|
| 165 | +const { fetchNotifications, loadMore, refresh, markAllAsRead } = notificationStore |
| 166 | +const unreadCount = computed(() => notificationStore.unreadCount) |
| 167 | +
|
153 | 168 | const gotoProfile = (notification) => { |
154 | 169 | isOpen.value = false |
155 | 170 | router.push(`/@${notification.actor.username}`) |
156 | 171 | } |
157 | 172 |
|
| 173 | +const markAllRead = async () => { |
| 174 | + const result = await confirmModal( |
| 175 | + t('common.markAsRead'), |
| 176 | + t('common.markAllAsReadConfirmMessage'), |
| 177 | + t('common.markAllRead'), |
| 178 | + t('common.cancel') |
| 179 | + ) |
| 180 | +
|
| 181 | + if (result) { |
| 182 | + await markAllAsRead().finally(async () => { |
| 183 | + await fetchNotifications() |
| 184 | + }) |
| 185 | + } |
| 186 | +} |
| 187 | +
|
158 | 188 | const getNotificationText = (notification) => { |
159 | 189 | switch (notification.type) { |
160 | 190 | case 'video.like': |
|
0 commit comments