pl-fe: add NotificationsAction type
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
3071b314ae
commit
32d25d9f54
3 changed files with 39 additions and 26 deletions
|
@ -23,7 +23,6 @@ import type { AppDispatch, RootState } from 'pl-fe/store';
|
||||||
|
|
||||||
const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE' as const;
|
const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE' as const;
|
||||||
const NOTIFICATIONS_UPDATE_NOOP = 'NOTIFICATIONS_UPDATE_NOOP' as const;
|
const NOTIFICATIONS_UPDATE_NOOP = 'NOTIFICATIONS_UPDATE_NOOP' as const;
|
||||||
const NOTIFICATIONS_UPDATE_QUEUE = 'NOTIFICATIONS_UPDATE_QUEUE' as const;
|
|
||||||
|
|
||||||
const NOTIFICATIONS_EXPAND_REQUEST = 'NOTIFICATIONS_EXPAND_REQUEST' as const;
|
const NOTIFICATIONS_EXPAND_REQUEST = 'NOTIFICATIONS_EXPAND_REQUEST' as const;
|
||||||
const NOTIFICATIONS_EXPAND_SUCCESS = 'NOTIFICATIONS_EXPAND_SUCCESS' as const;
|
const NOTIFICATIONS_EXPAND_SUCCESS = 'NOTIFICATIONS_EXPAND_SUCCESS' as const;
|
||||||
|
@ -31,13 +30,8 @@ const NOTIFICATIONS_EXPAND_FAIL = 'NOTIFICATIONS_EXPAND_FAIL' as const;
|
||||||
|
|
||||||
const NOTIFICATIONS_FILTER_SET = 'NOTIFICATIONS_FILTER_SET' as const;
|
const NOTIFICATIONS_FILTER_SET = 'NOTIFICATIONS_FILTER_SET' as const;
|
||||||
|
|
||||||
const NOTIFICATIONS_CLEAR = 'NOTIFICATIONS_CLEAR' as const;
|
|
||||||
const NOTIFICATIONS_SCROLL_TOP = 'NOTIFICATIONS_SCROLL_TOP' as const;
|
const NOTIFICATIONS_SCROLL_TOP = 'NOTIFICATIONS_SCROLL_TOP' as const;
|
||||||
|
|
||||||
const NOTIFICATIONS_MARK_READ_REQUEST = 'NOTIFICATIONS_MARK_READ_REQUEST' as const;
|
|
||||||
const NOTIFICATIONS_MARK_READ_SUCCESS = 'NOTIFICATIONS_MARK_READ_SUCCESS' as const;
|
|
||||||
const NOTIFICATIONS_MARK_READ_FAIL = 'NOTIFICATIONS_MARK_READ_FAIL' as const;
|
|
||||||
|
|
||||||
const MAX_QUEUED_NOTIFICATIONS = 40;
|
const MAX_QUEUED_NOTIFICATIONS = 40;
|
||||||
|
|
||||||
const FILTER_TYPES = {
|
const FILTER_TYPES = {
|
||||||
|
@ -65,6 +59,11 @@ const fetchRelatedRelationships = (dispatch: AppDispatch, notifications: Array<N
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface NotificationsUpdateAction {
|
||||||
|
type: typeof NOTIFICATIONS_UPDATE;
|
||||||
|
notification: NotificationGroup;
|
||||||
|
}
|
||||||
|
|
||||||
const updateNotifications = (notification: BaseNotification) =>
|
const updateNotifications = (notification: BaseNotification) =>
|
||||||
(dispatch: AppDispatch) => {
|
(dispatch: AppDispatch) => {
|
||||||
const selectedFilter = useSettingsStore.getState().settings.notifications.quickFilter.active;
|
const selectedFilter = useSettingsStore.getState().settings.notifications.quickFilter.active;
|
||||||
|
@ -78,7 +77,7 @@ const updateNotifications = (notification: BaseNotification) =>
|
||||||
if (showInColumn) {
|
if (showInColumn) {
|
||||||
const normalizedNotification = normalizeNotification(notification);
|
const normalizedNotification = normalizeNotification(notification);
|
||||||
|
|
||||||
dispatch({
|
dispatch<NotificationsUpdateAction>({
|
||||||
type: NOTIFICATIONS_UPDATE,
|
type: NOTIFICATIONS_UPDATE,
|
||||||
notification: normalizedNotification,
|
notification: normalizedNotification,
|
||||||
});
|
});
|
||||||
|
@ -87,6 +86,11 @@ const updateNotifications = (notification: BaseNotification) =>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface NotificationsUpdateNoopAction {
|
||||||
|
type: typeof NOTIFICATIONS_UPDATE_NOOP;
|
||||||
|
meta: { sound: 'boop' };
|
||||||
|
}
|
||||||
|
|
||||||
const updateNotificationsQueue = (notification: BaseNotification, intlMessages: Record<string, string>, intlLocale: string) =>
|
const updateNotificationsQueue = (notification: BaseNotification, intlMessages: Record<string, string>, intlLocale: string) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
if (!notification.type) return; // drop invalid notifications
|
if (!notification.type) return; // drop invalid notifications
|
||||||
|
@ -130,7 +134,7 @@ const updateNotificationsQueue = (notification: BaseNotification, intlMessages:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playSound && !filtered) {
|
if (playSound && !filtered) {
|
||||||
dispatch({
|
dispatch<NotificationsUpdateNoopAction>({
|
||||||
type: NOTIFICATIONS_UPDATE_NOOP,
|
type: NOTIFICATIONS_UPDATE_NOOP,
|
||||||
meta: { sound: 'boop' },
|
meta: { sound: 'boop' },
|
||||||
});
|
});
|
||||||
|
@ -217,15 +221,24 @@ const expandNotificationsFail = (error: unknown) => ({
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface NotificationsScrollTopAction {
|
||||||
|
type: typeof NOTIFICATIONS_SCROLL_TOP;
|
||||||
|
top: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
const scrollTopNotifications = (top: boolean) =>
|
const scrollTopNotifications = (top: boolean) =>
|
||||||
(dispatch: AppDispatch) => {
|
(dispatch: AppDispatch) => {
|
||||||
dispatch({
|
dispatch(markReadNotifications());
|
||||||
|
return dispatch<NotificationsScrollTopAction>({
|
||||||
type: NOTIFICATIONS_SCROLL_TOP,
|
type: NOTIFICATIONS_SCROLL_TOP,
|
||||||
top,
|
top,
|
||||||
});
|
});
|
||||||
dispatch(markReadNotifications());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface SetFilterAction {
|
||||||
|
type: typeof NOTIFICATIONS_FILTER_SET;
|
||||||
|
}
|
||||||
|
|
||||||
const setFilter = (filterType: FilterType, abort?: boolean) =>
|
const setFilter = (filterType: FilterType, abort?: boolean) =>
|
||||||
(dispatch: AppDispatch) => {
|
(dispatch: AppDispatch) => {
|
||||||
const settingsStore = useSettingsStore.getState();
|
const settingsStore = useSettingsStore.getState();
|
||||||
|
@ -233,10 +246,10 @@ const setFilter = (filterType: FilterType, abort?: boolean) =>
|
||||||
|
|
||||||
settingsStore.changeSetting(['notifications', 'quickFilter', 'active'], filterType);
|
settingsStore.changeSetting(['notifications', 'quickFilter', 'active'], filterType);
|
||||||
|
|
||||||
dispatch({ type: NOTIFICATIONS_FILTER_SET });
|
|
||||||
dispatch(expandNotifications(undefined, undefined, abort));
|
dispatch(expandNotifications(undefined, undefined, abort));
|
||||||
|
|
||||||
if (activeFilter !== filterType) dispatch(saveSettings());
|
if (activeFilter !== filterType) dispatch(saveSettings());
|
||||||
|
|
||||||
|
return dispatch<SetFilterAction>({ type: NOTIFICATIONS_FILTER_SET });
|
||||||
};
|
};
|
||||||
|
|
||||||
const markReadNotifications = () =>
|
const markReadNotifications = () =>
|
||||||
|
@ -258,19 +271,23 @@ const markReadNotifications = () =>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type NotificationsAction =
|
||||||
|
| NotificationsUpdateAction
|
||||||
|
| NotificationsUpdateNoopAction
|
||||||
|
| ReturnType<typeof expandNotificationsRequest>
|
||||||
|
| ReturnType<typeof expandNotificationsSuccess>
|
||||||
|
| ReturnType<typeof expandNotificationsFail>
|
||||||
|
| NotificationsScrollTopAction
|
||||||
|
| SetFilterAction;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
NOTIFICATIONS_UPDATE,
|
NOTIFICATIONS_UPDATE,
|
||||||
NOTIFICATIONS_UPDATE_NOOP,
|
NOTIFICATIONS_UPDATE_NOOP,
|
||||||
NOTIFICATIONS_UPDATE_QUEUE,
|
|
||||||
NOTIFICATIONS_EXPAND_REQUEST,
|
NOTIFICATIONS_EXPAND_REQUEST,
|
||||||
NOTIFICATIONS_EXPAND_SUCCESS,
|
NOTIFICATIONS_EXPAND_SUCCESS,
|
||||||
NOTIFICATIONS_EXPAND_FAIL,
|
NOTIFICATIONS_EXPAND_FAIL,
|
||||||
NOTIFICATIONS_FILTER_SET,
|
NOTIFICATIONS_FILTER_SET,
|
||||||
NOTIFICATIONS_CLEAR,
|
|
||||||
NOTIFICATIONS_SCROLL_TOP,
|
NOTIFICATIONS_SCROLL_TOP,
|
||||||
NOTIFICATIONS_MARK_READ_REQUEST,
|
|
||||||
NOTIFICATIONS_MARK_READ_SUCCESS,
|
|
||||||
NOTIFICATIONS_MARK_READ_FAIL,
|
|
||||||
MAX_QUEUED_NOTIFICATIONS,
|
MAX_QUEUED_NOTIFICATIONS,
|
||||||
type FilterType,
|
type FilterType,
|
||||||
updateNotifications,
|
updateNotifications,
|
||||||
|
@ -282,4 +299,5 @@ export {
|
||||||
scrollTopNotifications,
|
scrollTopNotifications,
|
||||||
setFilter,
|
setFilter,
|
||||||
markReadNotifications,
|
markReadNotifications,
|
||||||
|
type NotificationsAction,
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,9 +18,8 @@ import {
|
||||||
NOTIFICATIONS_EXPAND_REQUEST,
|
NOTIFICATIONS_EXPAND_REQUEST,
|
||||||
NOTIFICATIONS_EXPAND_FAIL,
|
NOTIFICATIONS_EXPAND_FAIL,
|
||||||
NOTIFICATIONS_FILTER_SET,
|
NOTIFICATIONS_FILTER_SET,
|
||||||
NOTIFICATIONS_CLEAR,
|
|
||||||
NOTIFICATIONS_SCROLL_TOP,
|
NOTIFICATIONS_SCROLL_TOP,
|
||||||
NOTIFICATIONS_MARK_READ_REQUEST,
|
type NotificationsAction,
|
||||||
} from '../actions/notifications';
|
} from '../actions/notifications';
|
||||||
import { TIMELINE_DELETE, type TimelineAction } from '../actions/timelines';
|
import { TIMELINE_DELETE, type TimelineAction } from '../actions/timelines';
|
||||||
|
|
||||||
|
@ -110,7 +109,7 @@ const importMarker = (state: State, marker: Markers) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const notifications = (state: State = ReducerRecord(), action: AccountsAction | AnyAction | TimelineAction) => {
|
const notifications = (state: State = ReducerRecord(), action: AccountsAction | AnyAction | NotificationsAction | TimelineAction) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case NOTIFICATIONS_EXPAND_REQUEST:
|
case NOTIFICATIONS_EXPAND_REQUEST:
|
||||||
return state.set('isLoading', true);
|
return state.set('isLoading', true);
|
||||||
|
@ -132,10 +131,6 @@ const notifications = (state: State = ReducerRecord(), action: AccountsAction |
|
||||||
case FOLLOW_REQUEST_AUTHORIZE_SUCCESS:
|
case FOLLOW_REQUEST_AUTHORIZE_SUCCESS:
|
||||||
case FOLLOW_REQUEST_REJECT_SUCCESS:
|
case FOLLOW_REQUEST_REJECT_SUCCESS:
|
||||||
return filterNotificationIds(state, [action.accountId], 'follow_request');
|
return filterNotificationIds(state, [action.accountId], 'follow_request');
|
||||||
case NOTIFICATIONS_CLEAR:
|
|
||||||
return state.set('items', ImmutableOrderedMap()).set('hasMore', false);
|
|
||||||
case NOTIFICATIONS_MARK_READ_REQUEST:
|
|
||||||
return state.set('lastRead', action.lastRead);
|
|
||||||
case MARKER_FETCH_SUCCESS:
|
case MARKER_FETCH_SUCCESS:
|
||||||
case MARKER_SAVE_REQUEST:
|
case MARKER_SAVE_REQUEST:
|
||||||
case MARKER_SAVE_SUCCESS:
|
case MARKER_SAVE_SUCCESS:
|
||||||
|
|
|
@ -43,7 +43,7 @@ import {
|
||||||
REACTIONS_FETCH_SUCCESS,
|
REACTIONS_FETCH_SUCCESS,
|
||||||
InteractionsAction,
|
InteractionsAction,
|
||||||
} from 'pl-fe/actions/interactions';
|
} from 'pl-fe/actions/interactions';
|
||||||
import { NOTIFICATIONS_UPDATE } from 'pl-fe/actions/notifications';
|
import { NOTIFICATIONS_UPDATE, type NotificationsAction } from 'pl-fe/actions/notifications';
|
||||||
|
|
||||||
import type { Account, EmojiReaction, Notification, PaginatedResponse } from 'pl-api';
|
import type { Account, EmojiReaction, Notification, PaginatedResponse } from 'pl-api';
|
||||||
import type { APIEntity } from 'pl-fe/types/entities';
|
import type { APIEntity } from 'pl-fe/types/entities';
|
||||||
|
@ -157,7 +157,7 @@ const normalizeFollowRequest = (state: State, notification: Notification) =>
|
||||||
draft.follow_requests.items = [...new Set([notification.account.id, ...draft.follow_requests.items])];
|
draft.follow_requests.items = [...new Set([notification.account.id, ...draft.follow_requests.items])];
|
||||||
});
|
});
|
||||||
|
|
||||||
const userLists = (state = initialState, action: AccountsAction | DirectoryAction | InteractionsAction | AnyAction): State => {
|
const userLists = (state = initialState, action: AccountsAction | DirectoryAction | InteractionsAction | NotificationsAction | AnyAction): State => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case REBLOGS_FETCH_SUCCESS:
|
case REBLOGS_FETCH_SUCCESS:
|
||||||
return normalizeList(state, ['reblogged_by', action.statusId], action.accounts, action.next);
|
return normalizeList(state, ['reblogged_by', action.statusId], action.accounts, action.next);
|
||||||
|
|
Loading…
Reference in a new issue