Sfoglia il codice sorgente

unuse isUsePermanentLink

yusuketk 5 anni fa
parent
commit
8ee2c93410
1 ha cambiato i file con 8 aggiunte e 9 eliminazioni
  1. 8 9
      src/client/js/components/PageEditor/LinkEditModal.jsx

+ 8 - 9
src/client/js/components/PageEditor/LinkEditModal.jsx

@@ -32,7 +32,6 @@ class LinkEditModal extends React.PureComponent {
       linkerType: Linker.types.markdownLink,
       linkerType: Linker.types.markdownLink,
       markdown: '',
       markdown: '',
       permalink: '',
       permalink: '',
-      isEnablePermanentLink: false,
     };
     };
 
 
     this.isApplyPukiwikiLikeLinkerPlugin = window.growiRenderer.preProcessors.some(process => process.constructor.name === 'PukiwikiLikeLinker');
     this.isApplyPukiwikiLikeLinkerPlugin = window.growiRenderer.preProcessors.some(process => process.constructor.name === 'PukiwikiLikeLinker');
@@ -99,7 +98,7 @@ class LinkEditModal extends React.PureComponent {
   }
   }
 
 
   toggleIsUsePamanentLink() {
   toggleIsUsePamanentLink() {
-    if (!this.state.isEnablePermanentLink) {
+    if (this.state.permalink === '' || this.state.linkerType === Linker.types.growiLink) {
       return;
       return;
     }
     }
 
 
@@ -146,10 +145,12 @@ class LinkEditModal extends React.PureComponent {
   }
   }
 
 
   handleSelecteLinkerType(linkerType) {
   handleSelecteLinkerType(linkerType) {
-    if (this.state.isUseRelativePath && linkerType === Linker.types.growiLink) {
-      this.toggleIsUseRelativePath();
+    let { isUseRelativePath, isUsePermanentLink } = this.state;
+    if (linkerType === Linker.types.growiLink) {
+      isUseRelativePath = false;
+      isUsePermanentLink = false;
     }
     }
-    this.setState({ linkerType });
+    this.setState({ linkerType, isUseRelativePath, isUsePermanentLink });
   }
   }
 
 
   save() {
   save() {
@@ -165,17 +166,15 @@ class LinkEditModal extends React.PureComponent {
   async getPreviewWithLinkInputValue(path) {
   async getPreviewWithLinkInputValue(path) {
     let markdown = '';
     let markdown = '';
     let permalink = '';
     let permalink = '';
-    let isEnablePermanentLink = false;
     try {
     try {
       const res = await this.props.appContainer.apiGet('/pages.get', { path });
       const res = await this.props.appContainer.apiGet('/pages.get', { path });
       markdown = res.page.revision.body;
       markdown = res.page.revision.body;
       permalink = `${window.location.origin}/${res.page.id}`;
       permalink = `${window.location.origin}/${res.page.id}`;
-      isEnablePermanentLink = true;
     }
     }
     catch (err) {
     catch (err) {
       markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
       markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
     }
     }
-    this.setState({ markdown, permalink, isEnablePermanentLink });
+    this.setState({ markdown, permalink });
   }
   }
 
 
   generateLink() {
   generateLink() {
@@ -293,7 +292,7 @@ class LinkEditModal extends React.PureComponent {
                           id="permanentLink"
                           id="permanentLink"
                           type="checkbox"
                           type="checkbox"
                           checked={this.state.isUsePermanentLink}
                           checked={this.state.isUsePermanentLink}
-                          disabled={!this.state.isEnablePermanentLink}
+                          disabled={this.state.permalink === '' || this.state.linkerType === Linker.types.growiLink}
                         />
                         />
                         <label className="custom-control-label" htmlFor="permanentLink" onClick={this.toggleIsUsePamanentLink}>
                         <label className="custom-control-label" htmlFor="permanentLink" onClick={this.toggleIsUsePamanentLink}>
                           Use permanent link
                           Use permanent link