Skip to content

Commit

Permalink
runfix: Correctly open user modal container (#13977)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisamir98 committed Oct 26, 2022
1 parent b3cfe4f commit c2b8dd3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/page/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include('loading.htm')

<div id="user-modal-container"></div>

<script src="./config.js?{{@config.VERSION}}"></script>
<script src="./min/dexie.js?{{@config.VERSION}}"></script>
<script src="./min/vendor.js?{{@config.VERSION}}"></script>
Expand Down
1 change: 0 additions & 1 deletion src/script/page/AppMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ 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>
<PrimaryModalComponent />
<GroupCreationModal userState={userState} teamState={teamState} />
</main>
Expand Down
21 changes: 16 additions & 5 deletions src/script/util/renderElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import React from 'react';

import {createRoot, Root} from 'react-dom/client';

import {getLogger} from './Logger';

const logger = getLogger('renderElement');

const roots = new Map<
string,
{
Expand Down Expand Up @@ -60,25 +64,32 @@ const renderElement =
style?: Partial<CSSStyleDeclaration>,
) =>
(props: T) => {
const currentElementId = parentElementId;
cleanUpElement(parentElementId);

const parentElement = document.getElementById(parentElementId);

if (!parentElement) {
logger.warn(`Unable to find element with id: ${parentElementId}`);

return;
}

cleanUpElement(currentElementId);
const elementContainer = document.createElement('div');

if (style) {
elementContainer.setAttribute('style', generateStyleString(style));
}

document.getElementById(currentElementId)?.appendChild(elementContainer);
parentElement.appendChild(elementContainer);
const reactRoot = createRoot(elementContainer);

roots.set(currentElementId, {
roots.set(parentElementId, {
elementContainer,
reactRoot,
});

const onClose = () => {
cleanUpElement(currentElementId);
cleanUpElement(parentElementId);
props.onClose?.();
};

Expand Down

0 comments on commit c2b8dd3

Please sign in to comment.