From 7f45dc76cf209f0f268e2010c9b05b226e0be761 Mon Sep 17 00:00:00 2001 From: Mamalizz Date: Sun, 25 May 2025 00:19:45 +0330 Subject: [PATCH] connected notifications to api --- frontend/pages/profile/notifications.vue | 205 ++++++++++++++++++----- 1 file changed, 160 insertions(+), 45 deletions(-) diff --git a/frontend/pages/profile/notifications.vue b/frontend/pages/profile/notifications.vue index 7976411..2c5d6b4 100644 --- a/frontend/pages/profile/notifications.vue +++ b/frontend/pages/profile/notifications.vue @@ -2,7 +2,7 @@ // meta useSeoMeta({ - title : "پنل کاربری اعلان ها" + title: "پنل کاربری اعلان ها", }); definePageMeta({ @@ -14,21 +14,35 @@ definePageMeta({ import { usePushNotifications } from "~/composables/global/usePushNotifications"; import useSubscribeNotification from "~/composables/api/notifications/useSubscribeNotification"; +import useGetAllNotifications, { + type GetAllNotificationsRequest, +} from "~/composables/api/account/useGetAllNotifications"; // state -const params = useUrlSearchParams("history"); +const params: GetAllNotificationsRequest = useUrlSearchParams("history"); const subscribe = ref(false); const sortFilters = ref([ { - title: "جدید ترین", - value: "created_at", + title: "اخبار", + value: "NEWS", }, { - title: "قدیمی ترین", - value: "-created_at", + title: "اعلانات کاربر", + value: "USER_NOTIF", + }, +]); + +const statusFilters = ref([ + { + title: "خوانده شده", + value: "read", + }, + { + title: "خوانده نشده", + value: "not_read", }, ]); @@ -41,8 +55,31 @@ const { subscription, } = usePushNotifications(); -const { isPending: subscribeNotificationIsPending } = - useSubscribeNotification(); +const { isPending: subscribeNotificationIsPending } = useSubscribeNotification(); + +// computeds + +const filters = computed(() => { + return { + sort: params.sort ?? "created_at", + status: params.status ?? "", + page: params.page ?? 1, + }; +}); + +const hasNotifications = computed(() => data.value && data.value.count > 0); + +const { data, isLoading: notificationsIsLoading } = useGetAllNotifications(filters); + +const notifications = computed(() => { + return data.value?.results.flat(); +}); + +const paginationData = computed(() => { + return data.value?.results.map((_, i: number) => { + return { type: "page", value: i }; + }); +}); // watch @@ -60,19 +97,24 @@ watch(