Skip to content

Commit a8aed2a

Browse files
committed
Add Mark as Read to notifications dropdown
1 parent 4f8acb4 commit a8aed2a

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

resources/js/components/Layout/NotificationsDropdown.vue

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="relative">
33
<slot
44
name="trigger"
5-
:unread-count="notificationsStore.unreadCount"
5+
:unread-count="unreadCount"
66
:is-open="isOpen"
77
:toggle="() => (isOpen = !isOpen)"
88
/>
@@ -17,9 +17,19 @@
1717
<div
1818
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"
1919
>
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>
2333
</div>
2434

2535
<div class="relative top-[60px]">
@@ -132,29 +142,49 @@
132142
</template>
133143

134144
<script setup>
135-
import { ref, onMounted } from 'vue'
145+
import { ref, onMounted, computed } from 'vue'
136146
import { useNotificationStore } from '~/stores/notifications'
137147
import { useNotifications } from '~/composables/useNotifications'
138148
import { format } from 'date-fns'
139149
import { useRouter } from 'vue-router'
140150
import LoopLink from '../LoopLink.vue'
141151
import { useI18n } from 'vue-i18n'
152+
import { useAlertModal } from '@/composables/useAlertModal.js'
142153
const { t } = useI18n()
143154
import { useUtils } from '@/composables/useUtils'
144155
145156
const isOpen = ref(false)
146-
const notificationsStore = useNotificationStore()
157+
const notificationStore = useNotificationStore()
147158
const router = useRouter()
148159
const { truncateMiddle, formatNumber, formatDate } = useUtils()
160+
const { alertModal, confirmModal } = useAlertModal()
149161
150162
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isError } =
151163
useNotifications()
152164
165+
const { fetchNotifications, loadMore, refresh, markAllAsRead } = notificationStore
166+
const unreadCount = computed(() => notificationStore.unreadCount)
167+
153168
const gotoProfile = (notification) => {
154169
isOpen.value = false
155170
router.push(`/@${notification.actor.username}`)
156171
}
157172
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+
158188
const getNotificationText = (notification) => {
159189
switch (notification.type) {
160190
case 'video.like':

0 commit comments

Comments
 (0)