Преглед изворни кода

Disable lsx in shared page

Shun Miyazawa пре 3 година
родитељ
комит
f954126c8b
1 измењених фајлова са 14 додато и 1 уклоњено
  1. 14 1
      packages/remark-lsx/src/components/Lsx.tsx

+ 14 - 1
packages/remark-lsx/src/components/Lsx.tsx

@@ -1,5 +1,6 @@
 import React, { useCallback, useMemo } from 'react';
 
+import { pagePathUtils } from '@growi/core';
 
 import { useSWRxNodeTree } from '../stores/lsx';
 
@@ -37,7 +38,10 @@ export const Lsx = React.memo(({
     return new LsxContext(prefix, options);
   }, [depth, filter, num, prefix, reverse, sort, except]);
 
-  const { data, error } = useSWRxNodeTree(lsxContext, isImmutable);
+  const pathname = window.location.pathname;
+  const isSharedPage = pagePathUtils.isSharedPage(pathname);
+
+  const { data, error } = useSWRxNodeTree(!isSharedPage, lsxContext, isImmutable);
 
   const isLoading = data === undefined;
   const hasError = error != null;
@@ -82,6 +86,15 @@ export const Lsx = React.memo(({
     return <LsxListView nodeTree={data.nodeTree} lsxContext={lsxContext} basisViewersCount={data.toppageViewersCount} />;
   }, [data?.nodeTree, data?.toppageViewersCount, isLoading, lsxContext]);
 
+  if (isSharedPage) {
+    return (
+      <div className="text-warning">
+        <i className="fa fa-exclamation-triangle fa-fw"></i>
+        {lsxContext.toString()} (-&gt; <small>lsx is not available on the share link page</small>)
+      </div>
+    );
+  }
+
   return (
     <div className={`lsx ${styles.lsx}`}>
       <Error />