2022-07-12 16:41:41 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { useBoundActions } from '../../hooks/useBoundActions';
|
2022-09-26 16:24:52 +00:00
|
|
|
import type { ReplacementValuesType } from '../../types/Util';
|
2022-07-12 16:41:41 +00:00
|
|
|
|
|
|
|
export enum ToastType {
|
2022-12-06 17:31:44 +00:00
|
|
|
AddingUserToGroup = 'AddingUserToGroup',
|
2022-12-08 01:26:59 +00:00
|
|
|
CannotMixMultiAndNonMultiAttachments = 'CannotMixMultiAndNonMultiAttachments',
|
2022-12-06 17:31:44 +00:00
|
|
|
CannotStartGroupCall = 'CannotStartGroupCall',
|
|
|
|
CopiedUsername = 'CopiedUsername',
|
|
|
|
CopiedUsernameLink = 'CopiedUsernameLink',
|
2022-12-08 01:26:59 +00:00
|
|
|
DangerousFileType = 'DangerousFileType',
|
2022-12-06 17:31:44 +00:00
|
|
|
DeleteForEveryoneFailed = 'DeleteForEveryoneFailed',
|
2022-07-29 00:10:07 +00:00
|
|
|
Error = 'Error',
|
2022-12-06 17:31:44 +00:00
|
|
|
FailedToDeleteUsername = 'FailedToDeleteUsername',
|
2022-12-08 01:26:59 +00:00
|
|
|
FileSize = 'FileSize',
|
|
|
|
MaxAttachments = 'MaxAttachments',
|
2022-07-12 16:41:41 +00:00
|
|
|
MessageBodyTooLong = 'MessageBodyTooLong',
|
2022-12-07 01:00:02 +00:00
|
|
|
PinnedConversationsFull = 'PinnedConversationsFull',
|
2022-12-06 19:03:09 +00:00
|
|
|
ReportedSpamAndBlocked = 'ReportedSpamAndBlocked',
|
2022-07-29 19:27:02 +00:00
|
|
|
StoryMuted = 'StoryMuted',
|
2022-07-12 16:41:41 +00:00
|
|
|
StoryReact = 'StoryReact',
|
|
|
|
StoryReply = 'StoryReply',
|
2022-08-12 23:44:10 +00:00
|
|
|
StoryVideoError = 'StoryVideoError',
|
|
|
|
StoryVideoTooLong = 'StoryVideoTooLong',
|
|
|
|
StoryVideoUnsupported = 'StoryVideoUnsupported',
|
2022-12-08 01:26:59 +00:00
|
|
|
UnableToLoadAttachment = 'UnableToLoadAttachment',
|
|
|
|
UnsupportedMultiAttachment = 'UnsupportedMultiAttachment',
|
2022-09-26 16:24:52 +00:00
|
|
|
UserAddedToGroup = 'UserAddedToGroup',
|
2022-07-12 16:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// State
|
|
|
|
|
|
|
|
export type ToastStateType = {
|
2022-09-26 16:24:52 +00:00
|
|
|
toast?: {
|
|
|
|
toastType: ToastType;
|
|
|
|
parameters?: ReplacementValuesType;
|
|
|
|
};
|
2022-07-12 16:41:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
|
|
|
const HIDE_TOAST = 'toast/HIDE_TOAST';
|
2022-12-05 22:56:23 +00:00
|
|
|
export const SHOW_TOAST = 'toast/SHOW_TOAST';
|
2022-07-12 16:41:41 +00:00
|
|
|
|
|
|
|
type HideToastActionType = {
|
|
|
|
type: typeof HIDE_TOAST;
|
|
|
|
};
|
|
|
|
|
2022-12-05 22:56:23 +00:00
|
|
|
export type ShowToastActionType = {
|
2022-07-12 16:41:41 +00:00
|
|
|
type: typeof SHOW_TOAST;
|
2022-09-26 16:24:52 +00:00
|
|
|
payload: {
|
|
|
|
toastType: ToastType;
|
|
|
|
parameters?: ReplacementValuesType;
|
|
|
|
};
|
2022-07-12 16:41:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type ToastActionType = HideToastActionType | ShowToastActionType;
|
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
|
|
|
|
function hideToast(): HideToastActionType {
|
|
|
|
return {
|
|
|
|
type: HIDE_TOAST,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export type ShowToastActionCreatorType = (
|
2022-09-26 16:24:52 +00:00
|
|
|
toastType: ToastType,
|
|
|
|
parameters?: ReplacementValuesType
|
2022-07-12 16:41:41 +00:00
|
|
|
) => ShowToastActionType;
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
export const showToast: ShowToastActionCreatorType = (
|
|
|
|
toastType,
|
|
|
|
parameters
|
|
|
|
) => {
|
2022-07-12 16:41:41 +00:00
|
|
|
return {
|
|
|
|
type: SHOW_TOAST,
|
2022-09-26 16:24:52 +00:00
|
|
|
payload: {
|
|
|
|
toastType,
|
|
|
|
parameters,
|
|
|
|
},
|
2022-07-12 16:41:41 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
hideToast,
|
|
|
|
showToast,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const useToastActions = (): typeof actions => useBoundActions(actions);
|
|
|
|
|
|
|
|
// Reducer
|
|
|
|
|
|
|
|
export function getEmptyState(): ToastStateType {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(
|
|
|
|
state: Readonly<ToastStateType> = getEmptyState(),
|
|
|
|
action: Readonly<ToastActionType>
|
|
|
|
): ToastStateType {
|
|
|
|
if (action.type === HIDE_TOAST) {
|
|
|
|
return {
|
|
|
|
...state,
|
2022-09-26 16:24:52 +00:00
|
|
|
toast: undefined,
|
2022-07-12 16:41:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === SHOW_TOAST) {
|
|
|
|
return {
|
|
|
|
...state,
|
2022-09-26 16:24:52 +00:00
|
|
|
toast: action.payload,
|
2022-07-12 16:41:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|