pl-fe: Improve types
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
929f6726fb
commit
89f91d6e3c
3 changed files with 16 additions and 4 deletions
|
@ -27,7 +27,6 @@ const baseNotificationGroupSchema = v.object({
|
||||||
page_max_id: v.fallback(v.optional(v.string()), undefined),
|
page_max_id: v.fallback(v.optional(v.string()), undefined),
|
||||||
latest_page_notification_at: v.fallback(v.optional(datetimeSchema), undefined),
|
latest_page_notification_at: v.fallback(v.optional(datetimeSchema), undefined),
|
||||||
sample_account_ids: v.array(v.string()),
|
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_muted: v.fallback(v.optional(v.boolean()), undefined),
|
||||||
is_seen: v.fallback(v.optional(v.boolean()), undefined),
|
is_seen: v.fallback(v.optional(v.boolean()), undefined),
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
||||||
import { useAppSelector } from 'pl-fe/hooks/use-app-selector';
|
import { useAppSelector } from 'pl-fe/hooks/use-app-selector';
|
||||||
import { useInstance } from 'pl-fe/hooks/use-instance';
|
import { useInstance } from 'pl-fe/hooks/use-instance';
|
||||||
import { useLoggedIn } from 'pl-fe/hooks/use-logged-in';
|
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 { useModalsStore } from 'pl-fe/stores/modals';
|
||||||
import { useSettingsStore } from 'pl-fe/stores/settings';
|
import { useSettingsStore } from 'pl-fe/stores/settings';
|
||||||
import { NotificationType } from 'pl-fe/utils/notification';
|
import { NotificationType } from 'pl-fe/utils/notification';
|
||||||
|
@ -188,7 +188,7 @@ interface INotification {
|
||||||
onReblog?: (status: StatusEntity, e?: KeyboardEvent) => void;
|
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))
|
if (['mention', 'status', 'reblog', 'favourite', 'poll', 'update', 'emoji_reaction', 'event_reminder', 'participation_accepted', 'participation_request'].includes(n.type))
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return n.status;
|
return n.status;
|
||||||
|
|
|
@ -183,13 +183,25 @@ const makeGetNotification = () => createSelector([
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
(state: RootState, notification: NotificationGroup) => state.statuses.get(notification.status_id),
|
(state: RootState, notification: NotificationGroup) => state.statuses.get(notification.status_id),
|
||||||
(state: RootState, notification: NotificationGroup) => selectAccounts(state, notification.sample_account_ids),
|
(state: RootState, notification: NotificationGroup) => selectAccounts(state, notification.sample_account_ids),
|
||||||
], (notification, target, status, accounts) => ({
|
], (notification, target, status, accounts): SelectedNotification => ({
|
||||||
...notification,
|
...notification,
|
||||||
target,
|
target,
|
||||||
status,
|
status,
|
||||||
accounts,
|
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 & {
|
type AccountGalleryAttachment = MediaAttachment & {
|
||||||
status: MinifiedStatus;
|
status: MinifiedStatus;
|
||||||
account: BaseAccount;
|
account: BaseAccount;
|
||||||
|
@ -350,6 +362,7 @@ export {
|
||||||
makeGetStatus,
|
makeGetStatus,
|
||||||
type SelectedStatus,
|
type SelectedStatus,
|
||||||
makeGetNotification,
|
makeGetNotification,
|
||||||
|
type SelectedNotification,
|
||||||
type AccountGalleryAttachment,
|
type AccountGalleryAttachment,
|
||||||
getAccountGallery,
|
getAccountGallery,
|
||||||
getGroupGallery,
|
getGroupGallery,
|
||||||
|
|
Loading…
Reference in a new issue