Convert ReactWrapperView to TypeScript

This commit is contained in:
Evan Hahn 2022-06-03 16:33:39 +00:00 committed by GitHub
parent bb9a270bfd
commit 63189f3f91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 325 additions and 364 deletions

View file

@ -26,23 +26,14 @@ const { ChatColorPicker } = require('../../ts/components/ChatColorPicker');
const {
ConfirmationDialog,
} = require('../../ts/components/ConfirmationDialog');
const {
ContactDetail,
} = require('../../ts/components/conversation/ContactDetail');
const {
ContactModal,
} = require('../../ts/components/conversation/ContactModal');
const { Emojify } = require('../../ts/components/conversation/Emojify');
const { ErrorModal } = require('../../ts/components/ErrorModal');
const { Lightbox } = require('../../ts/components/Lightbox');
const {
MediaGallery,
} = require('../../ts/components/conversation/media-gallery/MediaGallery');
const {
MessageDetail,
} = require('../../ts/components/conversation/MessageDetail');
const { Quote } = require('../../ts/components/conversation/Quote');
const { ProgressModal } = require('../../ts/components/ProgressModal');
const {
StagedLinkPreview,
} = require('../../ts/components/conversation/StagedLinkPreview');
@ -52,7 +43,6 @@ const {
const {
SystemTraySettingsCheckboxes,
} = require('../../ts/components/conversation/SystemTraySettingsCheckboxes');
const { WhatsNewLink } = require('../../ts/components/WhatsNewLink');
// State
const {
@ -320,19 +310,13 @@ exports.setup = (options = {}) => {
AttachmentList,
ChatColorPicker,
ConfirmationDialog,
ContactDetail,
ContactModal,
Emojify,
ErrorModal,
Lightbox,
MediaGallery,
MessageDetail,
Quote,
ProgressModal,
StagedLinkPreview,
DisappearingTimeDialog,
SystemTraySettingsCheckboxes,
WhatsNewLink,
};
const Roots = {

View file

@ -1,86 +0,0 @@
// Copyright 2018-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* global Backbone: false */
/* global i18n: false */
/* global React: false */
/* global ReactDOM: false */
// eslint-disable-next-line func-names
(function () {
window.Whisper = window.Whisper || {};
window.Whisper.ReactWrapperView = Backbone.View.extend({
className: 'react-wrapper',
initialize(options) {
const {
Component,
JSX,
props,
onClose,
tagName,
className,
onInitialRender,
elCallback,
} = options;
this.render();
if (elCallback) {
elCallback(this.el);
}
this.tagName = tagName;
this.className = className;
this.JSX = JSX;
this.Component = Component;
this.onClose = onClose;
this.onInitialRender = onInitialRender;
this.update(props);
this.hasRendered = false;
},
update(propsOrJSX, cb) {
const reactElement = this.JSX
? propsOrJSX || this.JSX
: React.createElement(this.Component, this.augmentProps(propsOrJSX));
ReactDOM.render(reactElement, this.el, () => {
if (cb) {
try {
cb();
} catch (error) {
window.SignalContext.log.error(
'ReactWrapperView.update error:',
error && error.stack ? error.stack : error
);
}
}
if (this.hasRendered) {
return;
}
this.hasRendered = true;
if (this.onInitialRender) {
this.onInitialRender();
}
});
},
augmentProps(props) {
return {
...props,
close: () => {
this.remove();
},
i18n,
};
},
remove() {
if (this.onClose) {
this.onClose();
}
ReactDOM.unmountComponentAtNode(this.el);
Backbone.View.prototype.remove.call(this);
},
});
})();