Skip to content

Commit

Permalink
runfix: Use primary modals directly in jsx (#13846)
Browse files Browse the repository at this point in the history
* runfix: Use primary modals directly in jsx

* remove log
  • Loading branch information
thisisamir98 committed Oct 12, 2022
1 parent ec438b7 commit 9d77998
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const usePrimaryModalState = create<PrimaryModalState>((set, get) => ({
updateErrorMessage: nextErrorMessage => set(state => ({...state, errorMessage: nextErrorMessage})),
}));

const addNewModalToQueue = (type: PrimaryModalType, options: ModalOptions, modalId = createRandomUuid()) => {
const addNewModalToQueue = (type: PrimaryModalType, options: ModalOptions, modalId = createRandomUuid()): void => {
const {currentModalId, existsInQueue, addToQueue, replaceInQueue} = usePrimaryModalState.getState();

const alreadyOpen = modalId === currentModalId;
Expand All @@ -99,7 +99,7 @@ const addNewModalToQueue = (type: PrimaryModalType, options: ModalOptions, modal
showNextModalInQueue();
};

const showNextModalInQueue = () => {
const showNextModalInQueue = (): void => {
const {queue, removeFirstItemInQueue} = usePrimaryModalState.getState();
if (queue.length > 0) {
const nextModalToShow = queue[0];
Expand Down Expand Up @@ -209,7 +209,7 @@ const updateCurrentModalContent = (type: PrimaryModalType, options: ModalOptions
updateCurrentModalId(id ?? null);
};

const removeCurrentModal = () => {
const removeCurrentModal = (): void => {
const {currentModalContent, updateCurrentModalId} = usePrimaryModalState.getState();

currentModalContent?.closeFn();
Expand Down
6 changes: 1 addition & 5 deletions src/script/components/Modals/PrimaryModal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@
*
*/

import renderElement from 'Util/renderElement';

import {PrimaryModalComponent} from './PrimaryModal';
import {addNewModalToQueue, showNextModalInQueue} from './PrimaryModalState';
import {PrimaryModalType} from './PrimaryModalTypes';

export {usePrimaryModalState, removeCurrentModal} from './PrimaryModalState';

const PrimaryModal = {
init: () => {
renderElement(PrimaryModalComponent, 'primary-modal-container')({});
init: (): void => {
showNextModalInQueue();
},
show: addNewModalToQueue,
Expand Down
3 changes: 2 additions & 1 deletion src/script/page/AppMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {PanelEntity, PanelState} from './RightSidebar/RightSidebar';
import RootProvider from './RootProvider';
import {useAppMainState} from './state';

import {PrimaryModalComponent} from '../components/Modals/PrimaryModal/PrimaryModal';
import {User} from '../entity/User';
import {TeamState} from '../team/TeamState';
import {UserState} from '../user/UserState';
Expand Down Expand Up @@ -104,7 +105,7 @@ const AppContainer: FC<AppContainerProps> = ({root}) => {

{/*The order of these elements matter to show proper modals stack upon each other*/}
<div id="user-modal-container"></div>
<div id="primary-modal-container"></div>
<PrimaryModalComponent />
</main>
</RootProvider>
</StyledApp>
Expand Down

0 comments on commit 9d77998

Please sign in to comment.