Properly type Modal props to ensure useful typescript checking (#10238

* Properly type Modal props to ensure useful typescript checking

* delint

* Iterate

* Iterate

* Fix modal.close loop

* Iterate

* Fix tests

* Add comment

* Fix test
This commit is contained in:
Michael Telatyński 2023-02-28 10:31:48 +00:00 committed by GitHub
parent ae5725b24c
commit 629e5cb01f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
124 changed files with 600 additions and 560 deletions

View file

@ -30,12 +30,11 @@ export function openLinkModal(
composerContext: ComposerContextState,
isEditing: boolean,
): void {
const modal = Modal.createDialog(
Modal.createDialog(
LinkModal,
{
composerContext,
composer,
onClose: () => modal.close(),
isTextEnabled: isSelectionEmpty(),
isEditing,
},
@ -52,18 +51,18 @@ function isEmpty(text: string): boolean {
interface LinkModalProps {
composer: FormattingFunctions;
isTextEnabled: boolean;
onClose: () => void;
onFinished: () => void;
composerContext: ComposerContextState;
isEditing: boolean;
}
export function LinkModal({
export const LinkModal: React.FC<LinkModalProps> = ({
composer,
isTextEnabled,
onClose,
onFinished,
composerContext,
isEditing,
}: LinkModalProps): JSX.Element {
}) => {
const [hasLinkChanged, setHasLinkChanged] = useState(false);
const [fields, setFields] = useState({ text: "", link: isEditing ? composer.getLink() : "" });
const hasText = !isEditing && isTextEnabled;
@ -74,7 +73,7 @@ export function LinkModal({
className="mx_LinkModal"
title={isEditing ? _t("Edit link") : _t("Create a link")}
hasCancel={true}
onFinished={onClose}
onFinished={onFinished}
>
<form
className="mx_LinkModal_content"
@ -82,7 +81,7 @@ export function LinkModal({
evt.preventDefault();
evt.stopPropagation();
onClose();
onFinished();
// When submitting is done when pressing enter when the link field has the focus,
// The link field is getting back the focus (due to react-focus-lock)
@ -126,7 +125,7 @@ export function LinkModal({
className="danger"
onClick={() => {
composer.removeLinks();
onClose();
onFinished();
}}
>
{_t("Remove")}
@ -136,10 +135,10 @@ export function LinkModal({
primaryButton={_t("Save")}
primaryDisabled={isSaveDisabled}
primaryIsSubmit={true}
onCancel={onClose}
onCancel={onFinished}
/>
</div>
</form>
</BaseDialog>
);
}
};