visuddhinanda 2 years ago
parent
commit
04d5205c38

+ 51 - 0
dashboard/src/components/api/view.ts

@@ -0,0 +1,51 @@
+import { ArticleType } from "../article/Article";
+
+export interface IViewRequest {
+  target_type: ArticleType;
+  book: number;
+  para: number;
+  channel: string;
+  mode: string;
+}
+export interface IMetaChapter {
+  book: number;
+  para: number;
+  channel: string;
+  mode: string;
+}
+export interface IViewData {
+  id: string;
+  target_id: string;
+  target_type: ArticleType;
+  updated_at: string;
+  title: string;
+  org_title: string;
+  meta: string;
+}
+export interface IViewStoreResponse {
+  ok: boolean;
+  message: string;
+  data: number;
+}
+export interface IViewResponse {
+  ok: boolean;
+  message: string;
+  data: IViewData;
+}
+export interface IViewListResponse {
+  ok: boolean;
+  message: string;
+  data: {
+    rows: IViewData[];
+    count: number;
+  };
+}
+
+export interface IView {
+  id: string;
+  title: string;
+  subtitle: string;
+  type: ArticleType;
+  updatedAt: string;
+  meta: IMetaChapter;
+}

+ 69 - 0
dashboard/src/components/article/ArticleDrawer.tsx

@@ -0,0 +1,69 @@
+import { Drawer } from "antd";
+import React, { useEffect, useState } from "react";
+
+import Article, { ArticleMode, ArticleType } from "./Article";
+
+interface IWidget {
+  trigger?: React.ReactNode;
+  title?: string;
+  type?: ArticleType;
+  book?: string;
+  para?: string;
+  channelId?: string;
+  articleId?: string;
+  mode?: ArticleMode;
+  open?: boolean;
+  onClose?: Function;
+}
+
+const ArticleDrawerWidget = ({
+  trigger,
+  title,
+  type,
+  book,
+  para,
+  channelId,
+  articleId,
+  mode,
+  open,
+  onClose,
+}: IWidget) => {
+  const [openDrawer, setOpenDrawer] = useState(open);
+  useEffect(() => setOpenDrawer(open), [open]);
+  const showDrawer = () => {
+    setOpenDrawer(true);
+  };
+
+  const onDrawerClose = () => {
+    setOpenDrawer(false);
+    if (typeof onClose !== "undefined") {
+      onClose();
+    }
+  };
+
+  return (
+    <>
+      <span onClick={() => showDrawer()}>{trigger}</span>
+      <Drawer
+        title={title}
+        width={1000}
+        placement="right"
+        onClose={onDrawerClose}
+        open={openDrawer}
+        destroyOnClose={true}
+      >
+        <Article
+          active={true}
+          type={type as ArticleType}
+          book={book}
+          para={para}
+          channelId={channelId}
+          articleId={articleId}
+          mode={mode}
+        />
+      </Drawer>
+    </>
+  );
+};
+
+export default ArticleDrawerWidget;