From 267ba03e86d2dfe8c67375c15d1a97d0f5141c36 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Thu, 25 Jul 2024 18:26:21 +0200 Subject: [PATCH] Replace fetcher in api/notifications.ts --- client/src/api/notifications.ts | 63 +++++-------------- .../Categories/MessageNotification.vue | 12 ++-- .../admin/Notifications/NotificationForm.vue | 28 ++++----- client/src/stores/notificationsStore.ts | 37 ++++++++--- 4 files changed, 62 insertions(+), 78 deletions(-) diff --git a/client/src/api/notifications.ts b/client/src/api/notifications.ts index 780bfa884266..a638e0ef472d 100644 --- a/client/src/api/notifications.ts +++ b/client/src/api/notifications.ts @@ -1,4 +1,4 @@ -import { type components, fetcher } from "@/api/schema"; +import { type components } from "@/api/schema"; export type BaseUserNotification = components["schemas"]["UserNotificationResponse"]; export type UserNotificationPreferences = components["schemas"]["UserNotificationPreferences"]["preferences"]; @@ -14,61 +14,26 @@ export interface SharedItemNotification extends BaseUserNotification { content: components["schemas"]["NewSharedItemNotificationContent"]; } -export type UserNotification = MessageNotification | SharedItemNotification; - -export type NotificationChanges = components["schemas"]["UserNotificationUpdateRequest"]; - -export type UserNotificationsBatchUpdateRequest = components["schemas"]["UserNotificationsBatchUpdateRequest"]; - -export type NotificationVariants = components["schemas"]["NotificationVariant"]; - -export type NewSharedItemNotificationContentItemType = - components["schemas"]["NewSharedItemNotificationContent"]["item_type"]; - -type UserNotificationUpdateRequest = components["schemas"]["UserNotificationUpdateRequest"]; - -export type NotificationCreateRequest = components["schemas"]["NotificationCreateRequest"]; - -type NotificationResponse = components["schemas"]["NotificationResponse"]; +type NotificationCreateData = components["schemas"]["NotificationCreateData"]; -const getNotification = fetcher.path("/api/notifications/{notification_id}").method("get").create(); - -export async function loadNotification(id: string): Promise { - const { data } = await getNotification({ notification_id: id }); - return data; -} - -const postNotification = fetcher.path("/api/notifications").method("post").create(); - -export async function sendNotification(notification: NotificationCreateRequest) { - const { data } = await postNotification(notification); - return data; +export interface MessageNotificationCreateData extends NotificationCreateData { + category: "message"; + content: components["schemas"]["MessageNotificationContent"]; } -const putNotification = fetcher.path("/api/notifications/{notification_id}").method("put").create(); +export type NotificationCreateRequest = components["schemas"]["NotificationCreateRequest"]; -export async function updateNotification(id: string, notification: UserNotificationUpdateRequest) { - const { data } = await putNotification({ notification_id: id, ...notification }); - return data; +export interface MessageNotificationCreateRequest extends NotificationCreateRequest { + notification: MessageNotificationCreateData; } -const getNotifications = fetcher.path("/api/notifications").method("get").create(); - -export async function loadNotificationsFromServer(): Promise { - const { data } = await getNotifications({}); - return data as UserNotification[]; -} +export type UserNotification = MessageNotification | SharedItemNotification; -const putBatchNotifications = fetcher.path("/api/notifications").method("put").create(); +export type NotificationChanges = components["schemas"]["UserNotificationUpdateRequest"]; -export async function updateBatchNotificationsOnServer(request: UserNotificationsBatchUpdateRequest) { - const { data } = await putBatchNotifications(request); - return data; -} +export type UserNotificationsBatchUpdateRequest = components["schemas"]["UserNotificationsBatchUpdateRequest"]; -const getNotificationStatus = fetcher.path("/api/notifications/status").method("get").create(); +export type NotificationVariants = components["schemas"]["NotificationVariant"]; -export async function loadNotificationsStatus(since: Date) { - const { data } = await getNotificationStatus({ since: since.toISOString().replace("Z", "") }); - return data; -} +export type NewSharedItemNotificationContentItemType = + components["schemas"]["NewSharedItemNotificationContent"]["item_type"]; diff --git a/client/src/components/Notifications/Categories/MessageNotification.vue b/client/src/components/Notifications/Categories/MessageNotification.vue index b313b961454b..ad1f533e32b0 100644 --- a/client/src/components/Notifications/Categories/MessageNotification.vue +++ b/client/src/components/Notifications/Categories/MessageNotification.vue @@ -4,15 +4,13 @@ import { faInbox } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; import { computed } from "vue"; -import { type MessageNotification } from "@/api/notifications"; +import { type MessageNotification, type MessageNotificationCreateData } from "@/api/notifications"; import { useMarkdown } from "@/composables/markdown"; import NotificationActions from "@/components/Notifications/NotificationActions.vue"; library.add(faInbox); -type PartialNotification = Partial & { content: MessageNotification["content"] }; - type Options = | { previewMode?: false; @@ -20,7 +18,7 @@ type Options = } | { previewMode: true; - notification: PartialNotification; + notification: MessageNotificationCreateData; }; const props = defineProps<{ @@ -37,12 +35,16 @@ const notificationVariant = computed(() => { return props.options.notification.variant; } }); + +const notificationSeen = computed(() => { + return "seen_time" in props.options.notification && !!props.options.notification.seen_time; +});