Browse Source

add onClick

visuddhinanda 2 years ago
parent
commit
2c9f888474

+ 14 - 0
dashboard/src/components/anthology/AnthologyTocTree.tsx

@@ -9,12 +9,14 @@ interface IWidget {
   anthologyId?: string;
   channels?: string[];
   onSelect?: Function;
+  onClick?: Function;
   onArticleSelect?: Function;
 }
 const AnthologyTocTreeWidget = ({
   anthologyId,
   channels,
   onSelect,
+  onClick,
   onArticleSelect,
 }: IWidget) => {
   const [tocData, setTocData] = useState<ListNodeData[]>([]);
@@ -63,6 +65,18 @@ const AnthologyTocTreeWidget = ({
           onArticleSelect(anthologyId, keys);
         }
       }}
+      onClick={(
+        id: string,
+        e: React.MouseEvent<HTMLSpanElement, MouseEvent>
+      ) => {
+        const target = e.ctrlKey || e.metaKey ? "_blank" : "self";
+        if (
+          typeof onClick !== "undefined" &&
+          typeof anthologyId !== "undefined"
+        ) {
+          onClick(anthologyId, id, target);
+        }
+      }}
     />
   );
 };

+ 5 - 3
dashboard/src/components/article/AnthologyDetail.tsx

@@ -19,6 +19,7 @@ interface IWidgetAnthologyDetail {
   channels?: string[];
   visible?: boolean;
   onArticleSelect?: Function;
+  onArticleClick?: Function;
   onLoad?: Function;
   onTitle?: Function;
   onLoading?: Function;
@@ -29,6 +30,7 @@ const AnthologyDetailWidget = ({
   channels,
   visible = true,
   onArticleSelect,
+  onArticleClick,
   onLoading,
   onTitle,
   onError,
@@ -102,9 +104,9 @@ const AnthologyDetailWidget = ({
       <AnthologyTocTree
         anthologyId={aid}
         channels={channels}
-        onArticleSelect={(anthologyId: string, keys: string[]) => {
-          if (typeof onArticleSelect !== "undefined") {
-            onArticleSelect(anthologyId, keys);
+        onClick={(anthologyId: string, id: string, target: string) => {
+          if (typeof onArticleClick !== "undefined") {
+            onArticleClick(anthologyId, id, target);
           }
         }}
       />

+ 7 - 3
dashboard/src/components/article/TypeAnthology.tsx

@@ -36,9 +36,13 @@ const TypeAnthologyWidget = ({
       )}
       <AnthologyDetail
         visible={!loading}
-        onArticleSelect={(anthologyId: string, keys: string[]) => {
-          if (typeof onArticleChange !== "undefined" && keys.length > 0) {
-            onArticleChange("article", keys[0], {
+        onArticleClick={(
+          anthologyId: string,
+          articleId: string,
+          target: string
+        ) => {
+          if (typeof onArticleChange !== "undefined" && articleId) {
+            onArticleChange("article", articleId, target, {
               anthologyId: anthologyId,
             });
           }