pleroma/src/actions/modals.ts

51 lines
1.1 KiB
TypeScript
Raw Normal View History

import { AppDispatch } from 'soapbox/store';
import type { MediaAttachment } from 'pl-api';
2022-11-16 05:32:32 -08:00
import type { ModalType } from 'soapbox/features/ui/components/modal-root';
const MODAL_OPEN = 'MODAL_OPEN';
const MODAL_CLOSE = 'MODAL_CLOSE';
2020-03-27 13:59:38 -07:00
type OpenModalProps =
| [type: 'MEDIA', props: {
media: Array<MediaAttachment>;
statusId?: string;
index: number;
time?: number;
}]
| [type: Exclude<ModalType, 'MEDIA'>, props: any]
| [type: Exclude<ModalType, 'MEDIA'>];
/** Open a modal of the given type */
const openModal = (...[type, props]: OpenModalProps) => {
// const [type, props] = args;
return (dispatch: AppDispatch) => {
dispatch(closeModal(type));
dispatch(openModalSuccess(type, props));
2020-03-27 13:59:38 -07:00
};
};
2020-03-27 13:59:38 -07:00
const openModalSuccess = (type: ModalType, props?: any) => ({
type: MODAL_OPEN,
modalType: type,
modalProps: props,
});
/** Close the modal */
const closeModal = (type?: ModalType) => ({
type: MODAL_CLOSE,
modalType: type,
});
type ModalsAction =
ReturnType<typeof openModalSuccess>
| ReturnType<typeof closeModal>;
export {
MODAL_OPEN,
MODAL_CLOSE,
openModal,
closeModal,
type ModalsAction,
};