signal-desktop/ts/components/ProgressModal.tsx

41 lines
1 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2020-10-06 17:06:34 +00:00
import * as React from 'react';
import { createPortal } from 'react-dom';
import { ProgressDialog } from './ProgressDialog';
import type { LocalizerType } from '../types/Util';
2020-10-06 17:06:34 +00:00
export type PropsType = {
readonly i18n: LocalizerType;
};
2022-11-18 00:45:19 +00:00
export const ProgressModal = React.memo(function ProgressModalInner({
i18n,
}: PropsType) {
2020-10-06 17:06:34 +00:00
const [root, setRoot] = React.useState<HTMLElement | null>(null);
// Note: We explicitly don't register for user interaction here, since this dialog
// cannot be dismissed.
React.useEffect(() => {
const div = document.createElement('div');
document.body.appendChild(div);
setRoot(div);
return () => {
document.body.removeChild(div);
setRoot(null);
};
}, []);
return root
? createPortal(
<div role="presentation" className="module-progress-dialog__overlay">
<ProgressDialog i18n={i18n} />
</div>,
root
)
: null;
});