pl-fe: Improve types

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-11-03 15:35:05 +01:00
parent 929f6726fb
commit 89f91d6e3c
3 changed files with 16 additions and 4 deletions

View file

@ -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),

View file

@ -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<Exclude<ReturnType<ReturnType<typeof makeGetNotification>>, 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;

View file

@ -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<Account>;
} & ({
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,