From 89f91d6e3c0376f1e9aca4bff8d1f34e14f41a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 3 Nov 2024 15:35:05 +0100 Subject: [PATCH] pl-fe: Improve types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../lib/entities/grouped-notifications-results.ts | 1 - .../notifications/components/notification.tsx | 4 ++-- packages/pl-fe/src/selectors/index.ts | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/pl-api/lib/entities/grouped-notifications-results.ts b/packages/pl-api/lib/entities/grouped-notifications-results.ts index 53eeadece..96b6483e8 100644 --- a/packages/pl-api/lib/entities/grouped-notifications-results.ts +++ b/packages/pl-api/lib/entities/grouped-notifications-results.ts @@ -27,7 +27,6 @@ const baseNotificationGroupSchema = v.object({ page_max_id: v.fallback(v.optional(v.string()), undefined), latest_page_notification_at: v.fallback(v.optional(datetimeSchema), undefined), sample_account_ids: v.array(v.string()), - status_id: v.fallback(v.optional(v.string()), undefined), is_muted: v.fallback(v.optional(v.boolean()), undefined), is_seen: v.fallback(v.optional(v.boolean()), undefined), diff --git a/packages/pl-fe/src/features/notifications/components/notification.tsx b/packages/pl-fe/src/features/notifications/components/notification.tsx index 654a25783..3b924aefa 100644 --- a/packages/pl-fe/src/features/notifications/components/notification.tsx +++ b/packages/pl-fe/src/features/notifications/components/notification.tsx @@ -19,7 +19,7 @@ import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch'; import { useAppSelector } from 'pl-fe/hooks/use-app-selector'; import { useInstance } from 'pl-fe/hooks/use-instance'; import { useLoggedIn } from 'pl-fe/hooks/use-logged-in'; -import { makeGetNotification } from 'pl-fe/selectors'; +import { makeGetNotification, SelectedNotification } from 'pl-fe/selectors'; import { useModalsStore } from 'pl-fe/stores/modals'; import { useSettingsStore } from 'pl-fe/stores/settings'; import { NotificationType } from 'pl-fe/utils/notification'; @@ -188,7 +188,7 @@ interface INotification { onReblog?: (status: StatusEntity, e?: KeyboardEvent) => void; } -const getNotificationStatus = (n: Pick>, null>, 'type' | 'status'>) => { +const getNotificationStatus = (n: SelectedNotification) => { if (['mention', 'status', 'reblog', 'favourite', 'poll', 'update', 'emoji_reaction', 'event_reminder', 'participation_accepted', 'participation_request'].includes(n.type)) // @ts-ignore return n.status; diff --git a/packages/pl-fe/src/selectors/index.ts b/packages/pl-fe/src/selectors/index.ts index 96a806d6c..1375c0381 100644 --- a/packages/pl-fe/src/selectors/index.ts +++ b/packages/pl-fe/src/selectors/index.ts @@ -183,13 +183,25 @@ const makeGetNotification = () => createSelector([ // @ts-ignore (state: RootState, notification: NotificationGroup) => state.statuses.get(notification.status_id), (state: RootState, notification: NotificationGroup) => selectAccounts(state, notification.sample_account_ids), -], (notification, target, status, accounts) => ({ +], (notification, target, status, accounts): SelectedNotification => ({ ...notification, target, status, accounts, })); +type SelectedNotification = NotificationGroup & { + accounts: Array; +} & ({ + type: 'follow' | 'follow_request' | 'admin.sign_up' | 'bite'; +} | { + type: 'status' | 'mention' | 'reblog' | 'favourite' | 'poll' | 'update' | 'emoji_reaction' | 'event_reminder' | 'participation_accepted' | 'participation_request'; + status: MinifiedStatus; +} | { + type: 'move'; + target: Account; +}) + type AccountGalleryAttachment = MediaAttachment & { status: MinifiedStatus; account: BaseAccount; @@ -350,6 +362,7 @@ export { makeGetStatus, type SelectedStatus, makeGetNotification, + type SelectedNotification, type AccountGalleryAttachment, getAccountGallery, getGroupGallery,