2022-01-10 22:17:52 +00:00
|
|
|
import React from 'react';
|
2022-01-10 22:25:06 +00:00
|
|
|
|
2022-11-15 16:00:49 +00:00
|
|
|
import Base from 'soapbox/components/modal-root';
|
2020-03-27 20:59:38 +00:00
|
|
|
import {
|
2023-02-07 21:22:23 +00:00
|
|
|
AccountModerationModal,
|
|
|
|
ActionsModal,
|
|
|
|
BirthdaysModal,
|
2021-09-16 20:44:39 +00:00
|
|
|
BoostModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
CompareHistoryModal,
|
|
|
|
ComponentModal,
|
|
|
|
ComposeEventModal,
|
|
|
|
ComposeModal,
|
2021-09-16 20:44:39 +00:00
|
|
|
ConfirmationModal,
|
2021-09-11 21:49:05 +00:00
|
|
|
CryptoDonateModal,
|
2023-03-25 22:16:40 +00:00
|
|
|
DislikesModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
EditAnnouncementModal,
|
|
|
|
EditFederationModal,
|
|
|
|
EmbedModal,
|
|
|
|
EventMapModal,
|
|
|
|
EventParticipantsModal,
|
|
|
|
FamiliarFollowersModal,
|
|
|
|
FavouritesModal,
|
|
|
|
HotkeysModal,
|
|
|
|
JoinEventModal,
|
|
|
|
LandingPageModal,
|
2020-03-27 20:59:38 +00:00
|
|
|
ListAdder,
|
2023-02-07 21:22:23 +00:00
|
|
|
ListEditor,
|
2023-04-03 20:12:50 +00:00
|
|
|
CreateGroupModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
MediaModal,
|
|
|
|
MentionsModal,
|
2021-09-16 20:44:39 +00:00
|
|
|
MissingDescriptionModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
MuteModal,
|
2022-01-06 13:43:58 +00:00
|
|
|
ReactionsModal,
|
|
|
|
ReblogsModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
ReplyMentionsModal,
|
|
|
|
ReportModal,
|
|
|
|
UnauthorizedModal,
|
|
|
|
VideoModal,
|
2022-04-27 20:50:35 +00:00
|
|
|
} from 'soapbox/features/ui/util/async-components';
|
|
|
|
|
2022-11-16 13:32:32 +00:00
|
|
|
import BundleContainer from '../containers/bundle-container';
|
2022-01-10 22:25:06 +00:00
|
|
|
|
2022-11-16 13:32:32 +00:00
|
|
|
import ModalLoading from './modal-loading';
|
2022-01-10 22:01:24 +00:00
|
|
|
|
2023-02-12 17:07:30 +00:00
|
|
|
/* eslint sort-keys: "error" */
|
2023-10-07 21:00:42 +00:00
|
|
|
const MODAL_COMPONENTS: Record<string, React.LazyExoticComponent<any>> = {
|
2023-02-07 21:22:23 +00:00
|
|
|
'ACCOUNT_MODERATION': AccountModerationModal,
|
2021-09-16 20:44:39 +00:00
|
|
|
'ACTIONS': ActionsModal,
|
2022-01-20 21:28:49 +00:00
|
|
|
'BIRTHDAYS': BirthdaysModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
'BOOST': BoostModal,
|
2022-04-27 20:50:35 +00:00
|
|
|
'COMPARE_HISTORY': CompareHistoryModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
'COMPONENT': ComponentModal,
|
|
|
|
'COMPOSE': ComposeModal,
|
2022-09-25 21:18:11 +00:00
|
|
|
'COMPOSE_EVENT': ComposeEventModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
'CONFIRM': ConfirmationModal,
|
2023-04-03 20:12:50 +00:00
|
|
|
'CREATE_GROUP': CreateGroupModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
'CRYPTO_DONATE': CryptoDonateModal,
|
2023-03-25 22:16:40 +00:00
|
|
|
'DISLIKES': DislikesModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
'EDIT_ANNOUNCEMENT': EditAnnouncementModal,
|
|
|
|
'EDIT_FEDERATION': EditFederationModal,
|
|
|
|
'EMBED': EmbedModal,
|
2022-12-08 15:30:48 +00:00
|
|
|
'EVENT_MAP': EventMapModal,
|
2022-09-21 21:27:53 +00:00
|
|
|
'EVENT_PARTICIPANTS': EventParticipantsModal,
|
2023-02-07 21:22:23 +00:00
|
|
|
'FAMILIAR_FOLLOWERS': FamiliarFollowersModal,
|
|
|
|
'FAVOURITES': FavouritesModal,
|
|
|
|
'HOTKEYS': HotkeysModal,
|
|
|
|
'JOIN_EVENT': JoinEventModal,
|
|
|
|
'LANDING_PAGE': LandingPageModal,
|
|
|
|
'LIST_ADDER': ListAdder,
|
|
|
|
'LIST_EDITOR': ListEditor,
|
|
|
|
'MEDIA': MediaModal,
|
|
|
|
'MENTIONS': MentionsModal,
|
|
|
|
'MISSING_DESCRIPTION': MissingDescriptionModal,
|
|
|
|
'MUTE': MuteModal,
|
|
|
|
'REACTIONS': ReactionsModal,
|
|
|
|
'REBLOGS': ReblogsModal,
|
|
|
|
'REPLY_MENTIONS': ReplyMentionsModal,
|
|
|
|
'REPORT': ReportModal,
|
|
|
|
'UNAUTHORIZED': UnauthorizedModal,
|
|
|
|
'VIDEO': VideoModal,
|
2020-03-27 20:59:38 +00:00
|
|
|
};
|
|
|
|
|
2022-11-12 14:18:24 +00:00
|
|
|
export type ModalType = keyof typeof MODAL_COMPONENTS | null;
|
2020-03-27 20:59:38 +00:00
|
|
|
|
2022-11-12 14:18:24 +00:00
|
|
|
interface IModalRoot {
|
2023-10-02 18:54:02 +00:00
|
|
|
type: ModalType;
|
|
|
|
props?: Record<string, any> | null;
|
|
|
|
onClose: (type?: ModalType) => void;
|
2022-11-12 14:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class ModalRoot extends React.PureComponent<IModalRoot> {
|
2020-03-27 20:59:38 +00:00
|
|
|
|
2020-04-14 21:47:35 +00:00
|
|
|
getSnapshotBeforeUpdate() {
|
2020-03-27 20:59:38 +00:00
|
|
|
return { visible: !!this.props.type };
|
|
|
|
}
|
|
|
|
|
2022-11-12 14:18:24 +00:00
|
|
|
componentDidUpdate(prevProps: IModalRoot, prevState: any, { visible }: any) {
|
2020-03-27 20:59:38 +00:00
|
|
|
if (visible) {
|
2022-03-21 18:09:01 +00:00
|
|
|
document.body.classList.add('with-modals');
|
2020-03-27 20:59:38 +00:00
|
|
|
} else {
|
2022-03-21 18:09:01 +00:00
|
|
|
document.body.classList.remove('with-modals');
|
2020-03-27 20:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-12 14:18:24 +00:00
|
|
|
renderLoading = (modalId: string) => () => {
|
2022-08-12 11:47:32 +00:00
|
|
|
return !['MEDIA', 'VIDEO', 'BOOST', 'CONFIRM', 'ACTIONS'].includes(modalId) ? <ModalLoading /> : null;
|
2023-01-05 17:55:08 +00:00
|
|
|
};
|
2020-03-27 20:59:38 +00:00
|
|
|
|
2022-11-12 14:18:24 +00:00
|
|
|
onClickClose = (_?: ModalType) => {
|
2020-03-27 20:59:38 +00:00
|
|
|
const { onClose, type } = this.props;
|
2022-01-30 17:46:57 +00:00
|
|
|
onClose(type);
|
2023-01-05 17:55:08 +00:00
|
|
|
};
|
2020-03-27 20:59:38 +00:00
|
|
|
|
2020-04-14 21:47:35 +00:00
|
|
|
render() {
|
2022-01-30 17:46:57 +00:00
|
|
|
const { type, props } = this.props;
|
2020-03-27 20:59:38 +00:00
|
|
|
const visible = !!type;
|
|
|
|
|
|
|
|
return (
|
2022-01-30 17:46:57 +00:00
|
|
|
<Base onClose={this.onClickClose} type={type}>
|
2020-03-27 20:59:38 +00:00
|
|
|
{visible && (
|
2023-10-07 21:00:42 +00:00
|
|
|
<BundleContainer fetchComponent={MODAL_COMPONENTS[type]} loading={this.renderLoading(type)} renderDelay={200}>
|
2020-03-27 20:59:38 +00:00
|
|
|
{(SpecificComponent) => <SpecificComponent {...props} onClose={this.onClickClose} />}
|
|
|
|
</BundleContainer>
|
|
|
|
)}
|
|
|
|
</Base>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|