From 5670aaadb33f97f609cf796b95d509025d80bba0 Mon Sep 17 00:00:00 2001 From: whoslen Date: Thu, 5 Oct 2023 14:47:03 +0800 Subject: [PATCH 1/3] perf initiate multiple email widgets dev --- .gitignore | 1 + .../src/inbox/components/EmailWidget.tsx | 266 ++++++++++-------- packages/ui-inbox/src/inbox/styles.ts | 2 +- .../integrations/components/mail/styles.ts | 67 +++-- .../.erxes/webpack.config.js | 6 +- 5 files changed, 191 insertions(+), 151 deletions(-) diff --git a/.gitignore b/.gitignore index ed8ddfdb07..d482570c22 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ out *.swo *.log build +/dock .env.local .env.development.local .env.development diff --git a/packages/ui-inbox/src/inbox/components/EmailWidget.tsx b/packages/ui-inbox/src/inbox/components/EmailWidget.tsx index c9563fa32c..fe8f111cdd 100644 --- a/packages/ui-inbox/src/inbox/components/EmailWidget.tsx +++ b/packages/ui-inbox/src/inbox/components/EmailWidget.tsx @@ -1,4 +1,5 @@ import { + EmailWidgetsWrapper, Link, NewEmailHeader, WidgetButton @@ -9,7 +10,7 @@ import CommonPortal from '@erxes/ui/src/components/CommonPortal'; import Icon from '@erxes/ui/src/components/Icon'; import MailForm from '@erxes/ui-inbox/src/settings/integrations/containers/mail/MailForm'; import { ModalWrapper } from '../styles'; -import React from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import Tip from '@erxes/ui/src/components/Tip'; import { WidgetWrapper } from '@erxes/ui-inbox/src/settings/integrations/components/mail/styles'; import { __ } from '@erxes/ui/src/utils'; @@ -26,57 +27,60 @@ type Props = { }; type State = { - shrink: string; - clear: boolean; - isFullscreen: boolean; - isEmptyEmail: boolean; + // shrink: string; + // clear: boolean; + // isFullscreen: boolean; + // isEmptyEmail: boolean; + widgets: any[]; }; -class Widget extends React.Component { - constructor(props) { - super(props); +function Widget(props) { + const [widgets, setWidgets] = useState([]); - this.state = { - shrink: localStorage.getItem('emailWidgetShrink') || 'false', - clear: false, - isFullscreen: false, - isEmptyEmail: false - }; - } - - changeState = (state: boolean) => { - this.setState({ - shrink: 'false', - clear: false - }); + const changeState = (state: boolean) => { + // this.setState({ + // shrink: 'false', + // clear: false, + // }); localStorage.setItem( 'emailWidgetShow', JSON.stringify({ - type: this.props.type || 'widget', + type: props.type || 'widget', show: state }) ); localStorage.setItem('emailWidgetShrink', 'false'); }; - showWidget = (isEmptyEmail?: boolean) => { - const { type = 'widget' } = this.props; - const storageShow = JSON.parse(localStorage.getItem('emailWidgetShow')); - const storageWidgetShow = storageShow ? storageShow.show : false; + const showWidget = (isEmptyEmail?: boolean) => { + // const { type = 'widget' } = props; + // const storageShow = JSON.parse( + // localStorage.getItem('emailWidgetShow') ?? '' + // ); + // const storageWidgetShow = storageShow ? storageShow.show : false; - if (storageWidgetShow === false) { - this.changeState(true); - } - if (storageWidgetShow === true && storageShow.type === type) { - this.changeState(false); - } + // if (storageWidgetShow === false) { + // changeState(true); + // } + // if (storageWidgetShow === true && storageShow.type === type) { + // changeState(false); + // } + setWidgets(prevWidgets => [ + ...prevWidgets, + { + isShrink: false, + clear: false, + isFullscreen: false, + isEmptyEmail: true + } + ]); - if (isEmptyEmail) { - this.setState({ isEmptyEmail: true }); - } + // if (isEmptyEmail) { + // this.setState({ isEmptyEmail: true }); + // } }; - renderTrigger() { + function renderTrigger() { const { disabled, type = 'widget', @@ -85,13 +89,13 @@ class Widget extends React.Component { buttonText, emailTo, emailStatus - } = this.props; + } = props; if (type === 'action' || type === 'tab') { return (