Просмотр исходного кода

change timing to generate CopyDropdown Items

yusuketk 5 лет назад
Родитель
Сommit
c0e1c2d6ad
1 измененных файлов с 22 добавлено и 13 удалено
  1. 22 13
      src/client/js/components/Page/CopyDropdown.jsx

+ 22 - 13
src/client/js/components/Page/CopyDropdown.jsx

@@ -16,25 +16,24 @@ class CopyDropdown extends React.Component {
     super(props);
     super(props);
 
 
     this.state = {
     this.state = {
-      dropdownOpen: false,
       tooltipOpen: false,
       tooltipOpen: false,
       isParamsAppended: true,
       isParamsAppended: true,
+      pagePathWithParams: '',
+      pagePathUrl: '',
+      permalink: '',
+      markdownLink: '',
     };
     };
 
 
     this.id = (Math.random() * 1000).toString();
     this.id = (Math.random() * 1000).toString();
 
 
-    this.toggle = this.toggle.bind(this);
     this.showToolTip = this.showToolTip.bind(this);
     this.showToolTip = this.showToolTip.bind(this);
+    this.generateItemContents = this.generateItemContents.bind(this);
     this.generatePagePathWithParams = this.generatePagePathWithParams.bind(this);
     this.generatePagePathWithParams = this.generatePagePathWithParams.bind(this);
     this.generatePagePathUrl = this.generatePagePathUrl.bind(this);
     this.generatePagePathUrl = this.generatePagePathUrl.bind(this);
     this.generatePermalink = this.generatePermalink.bind(this);
     this.generatePermalink = this.generatePermalink.bind(this);
     this.generateMarkdownLink = this.generateMarkdownLink.bind(this);
     this.generateMarkdownLink = this.generateMarkdownLink.bind(this);
   }
   }
 
 
-  toggle() {
-    this.setState({ dropdownOpen: !this.state.dropdownOpen });
-  }
-
   showToolTip() {
   showToolTip() {
     this.setState({ tooltipOpen: true });
     this.setState({ tooltipOpen: true });
     setTimeout(() => {
     setTimeout(() => {
@@ -64,6 +63,17 @@ class CopyDropdown extends React.Component {
     return str.replace(/ /g, '%20').replace(/\u3000/g, '%E3%80%80');
     return str.replace(/ /g, '%20').replace(/\u3000/g, '%E3%80%80');
   }
   }
 
 
+  generateItemContents() {
+    const pagePathWithParams = this.generatePagePathWithParams();
+    const pagePathUrl = this.generatePagePathUrl();
+    const permalink = this.generatePermalink();
+    const markdownLink = this.generateMarkdownLink();
+
+    this.setState({
+      pagePathWithParams, pagePathUrl, permalink, markdownLink,
+    });
+  }
+
   generatePagePathWithParams() {
   generatePagePathWithParams() {
     const { pagePath } = this.props;
     const { pagePath } = this.props;
     return decodeURI(`${pagePath}${this.uriParams}`);
     return decodeURI(`${pagePath}${this.uriParams}`);
@@ -108,11 +118,9 @@ class CopyDropdown extends React.Component {
     const {
     const {
       t, pageId, isShareLinkMode,
       t, pageId, isShareLinkMode,
     } = this.props;
     } = this.props;
-    const { isParamsAppended } = this.state;
-
-    const pagePathWithParams = this.generatePagePathWithParams();
-    const pagePathUrl = this.generatePagePathUrl();
-    const permalink = this.generatePermalink();
+    const {
+      isParamsAppended, pagePathWithParams, pagePathUrl, permalink, markdownLink,
+    } = this.state;
 
 
     const copyTarget = isShareLinkMode ? `copyShareLink${pageId}` : 'copyPagePathDropdown';
     const copyTarget = isShareLinkMode ? `copyShareLink${pageId}` : 'copyPagePathDropdown';
     const dropdownToggleStyle = isShareLinkMode ? 'btn btn-secondary' : 'd-block text-muted bg-transparent btn-copy border-0';
     const dropdownToggleStyle = isShareLinkMode ? 'btn btn-secondary' : 'd-block text-muted bg-transparent btn-copy border-0';
@@ -128,6 +136,7 @@ class CopyDropdown extends React.Component {
             caret
             caret
             className={dropdownToggleStyle}
             className={dropdownToggleStyle}
             style={this.props.buttonStyle}
             style={this.props.buttonStyle}
+            onClick={this.generateItemContents}
           >
           >
             { isShareLinkMode ? (
             { isShareLinkMode ? (
               <>Copy Link</>
               <>Copy Link</>
@@ -195,9 +204,9 @@ class CopyDropdown extends React.Component {
 
 
             {/* Markdown Link */}
             {/* Markdown Link */}
             { pageId && (
             { pageId && (
-              <CopyToClipboard text={this.generateMarkdownLink()} onCopy={this.showToolTip}>
+              <CopyToClipboard text={markdownLink} onCopy={this.showToolTip}>
                 <DropdownItem className="px-3 text-wrap">
                 <DropdownItem className="px-3 text-wrap">
-                  <DropdownItemContents title={t('copy_to_clipboard.Markdown link')} contents={this.generateMarkdownLink()} isContentsWrap />
+                  <DropdownItemContents title={t('copy_to_clipboard.Markdown link')} contents={markdownLink} isContentsWrap />
                 </DropdownItem>
                 </DropdownItem>
               </CopyToClipboard>
               </CopyToClipboard>
             )}
             )}