ソースを参照

更改 time 为 updatedAt

visuddhinanda 2 年 前
コミット
32b1b5aa73

+ 1 - 1
dashboard/src/components/article/AnthologyDetail.tsx

@@ -67,7 +67,7 @@ const AnthologyDetailWidget = ({
       <Paragraph>
         <Space>
           <StudioName data={tableData?.studio} />
-          <TimeShow time={tableData?.updated_at} title="updated" />
+          <TimeShow updatedAt={tableData?.updated_at} />
         </Space>
       </Paragraph>
       <Paragraph>

+ 5 - 1
dashboard/src/components/article/ArticleListPublic.tsx

@@ -51,7 +51,11 @@ const ArticleListWidget = ({ search, studioName }: IWidget) => {
               return (
                 <Space>
                   {row.editor?.nickName}
-                  <TimeShow time={row.updatedAt} />
+                  <TimeShow
+                    updatedAt={row.updatedAt}
+                    showLabel={false}
+                    showIcon={false}
+                  />
                 </Space>
               );
             },

+ 7 - 1
dashboard/src/components/blog/TimeLine.tsx

@@ -63,7 +63,13 @@ const TimeLineWidget = ({ studioName }: IWidget) => {
               style={{ backgroundColor: "unset" }}
               key={id}
               dot={icon}
-              label={<TimeShow time={item.date} showIcon={false} />}
+              label={
+                <TimeShow
+                  createdAt={item.date}
+                  showIcon={false}
+                  showLabel={false}
+                />
+              }
             >
               {intl.formatMessage({
                 id: `labels.${item.event}`,

+ 1 - 6
dashboard/src/components/corpus/ChapterCard.tsx

@@ -84,12 +84,7 @@ const ChapterCardWidget = ({ data, onTagClick }: IWidget) => {
           </div>
           <Space>
             <ChannelListItem channel={data.channel} studio={data.studio} />
-            <TimeShow
-              time={data.updatedAt}
-              title={intl.formatMessage({
-                id: "labels.updated-at",
-              })}
-            />
+            <TimeShow updatedAt={data.updatedAt} />
           </Space>
         </div>
       </Col>

+ 1 - 1
dashboard/src/components/corpus/ChapterChannelSelect.tsx

@@ -91,7 +91,7 @@ const ChapterChannelSelectWidget = ({
                   <EyeOutlined />
                   {item.hit} | <LikeOutlined />
                   {item.like} |
-                  <TimeShow time={item.updatedAt} title={item.updatedAt} />
+                  <TimeShow updatedAt={item.updatedAt} />
                 </Space>
               </Text>
             </List.Item>

+ 1 - 1
dashboard/src/components/corpus/ChapterInChannel.tsx

@@ -96,7 +96,7 @@ const ChapterInChannelWidget = ({
                     <EyeOutlined />
                     {item.hit} | <LikeOutlined />
                     {item.like} |
-                    <TimeShow time={item.updatedAt} /> |
+                    <TimeShow updatedAt={item.updatedAt} /> |
                     <ProgressOutlinedIcon />
                     {`${item.progress}%`}
                   </Space>

+ 1 - 7
dashboard/src/components/corpus/SentHistory.tsx

@@ -91,13 +91,7 @@ const SentHistoryWidget = ({ sentId }: IWidget) => {
         },
         description: {
           render: (text, row, index, action) => {
-            return (
-              <TimeShow
-                type="secondary"
-                time={row.createdAt}
-                title="created at"
-              />
-            );
+            return <TimeShow type="secondary" createdAt={row.createdAt} />;
           },
         },
         actions: {

+ 7 - 1
dashboard/src/components/dict/UserDictList.tsx

@@ -209,7 +209,13 @@ const UserDictListWidget = ({ studioName, view = "studio" }: IWidget) => {
             valueType: "date",
             sorter: true,
             render: (text, row, index, action) => {
-              return <TimeShow time={row.updated_at} showIcon={false} />;
+              return (
+                <TimeShow
+                  updatedAt={row.updated_at}
+                  showIcon={false}
+                  showLabel={false}
+                />
+              );
             },
           },
           {

+ 11 - 1
dashboard/src/components/discussion/DiscussionItem.tsx

@@ -20,20 +20,30 @@ export interface IComment {
 }
 interface IWidget {
   data: IComment;
+  isFocus?: boolean;
   onSelect?: Function;
   onCreated?: Function;
   onDelete?: Function;
 }
 const DiscussionItemWidget = ({
   data,
+  isFocus = false,
   onSelect,
   onCreated,
   onDelete,
 }: IWidget) => {
   const [edit, setEdit] = useState(false);
   const [currData, setCurrData] = useState<IComment>(data);
+  console.log("isFocus", isFocus);
   return (
-    <div style={{ display: "flex", width: "100%" }}>
+    <div
+      id={`answer-${data.id}`}
+      style={{
+        display: "flex",
+        width: "100%",
+        border: isFocus ? "2px solid blue" : "unset",
+      }}
+    >
       <div style={{ width: "2em" }}>
         <Avatar size="small">{data.user?.nickName?.slice(0, 1)}</Avatar>
       </div>

+ 2 - 4
dashboard/src/components/discussion/DiscussionShow.tsx

@@ -149,10 +149,8 @@ const DiscussionShowWidget = ({
               {data.user.nickName}
               <TimeShow
                 type="secondary"
-                time={data.updatedAt}
-                title={intl.formatMessage({
-                  id: "labels.updated-at",
-                })}
+                updatedAt={data.updatedAt}
+                createdAt={data.createdAt}
               />
             </Space>
           </Text>

+ 4 - 0
dashboard/src/components/discussion/DiscussionTopic.tsx

@@ -6,14 +6,17 @@ import { IComment } from "./DiscussionItem";
 
 interface IWidget {
   topicId?: string;
+  focus?: string;
   onItemCountChange?: Function;
   onTopicReady?: Function;
 }
 const DiscussionTopicWidget = ({
   topicId,
+  focus,
   onTopicReady,
   onItemCountChange,
 }: IWidget) => {
+  console.log("focus", focus);
   return (
     <>
       <DiscussionTopicInfo
@@ -27,6 +30,7 @@ const DiscussionTopicWidget = ({
       />
       <Divider />
       <DiscussionTopicChildren
+        focus={focus}
         topicId={topicId}
         onItemCountChange={(count: number, e: string) => {
           //把新建回答的消息传出去。

+ 22 - 16
dashboard/src/components/discussion/DiscussionTopicChildren.tsx

@@ -9,10 +9,12 @@ import DiscussionItem, { IComment } from "./DiscussionItem";
 
 interface IWidget {
   topicId?: string;
+  focus?: string;
   onItemCountChange?: Function;
 }
 const DiscussionTopicChildrenWidget = ({
   topicId,
+  focus,
   onItemCountChange,
 }: IWidget) => {
   const intl = useIntl();
@@ -69,22 +71,26 @@ const DiscussionTopicChildrenWidget = ({
           }}
           itemLayout="horizontal"
           dataSource={data}
-          renderItem={(item) => (
-            <List.Item>
-              <DiscussionItem
-                data={item}
-                onDelete={() => {
-                  console.log("delete", item.id, data);
-                  if (typeof onItemCountChange !== "undefined") {
-                    onItemCountChange(data.length - 1, item.parent);
-                  }
-                  setData((origin) => {
-                    return origin.filter((value) => value.id !== item.id);
-                  });
-                }}
-              />
-            </List.Item>
-          )}
+          renderItem={(item) => {
+            console.log("focus", item.id, focus);
+            return (
+              <List.Item>
+                <DiscussionItem
+                  data={item}
+                  isFocus={item.id === focus ? true : false}
+                  onDelete={() => {
+                    console.log("delete", item.id, data);
+                    if (typeof onItemCountChange !== "undefined") {
+                      onItemCountChange(data.length - 1, item.parent);
+                    }
+                    setData((origin) => {
+                      return origin.filter((value) => value.id !== item.id);
+                    });
+                  }}
+                />
+              </List.Item>
+            );
+          }}
         />
       )}
       <DiscussionCreate

+ 1 - 1
dashboard/src/components/discussion/DiscussionTopicInfo.tsx

@@ -57,7 +57,7 @@ const DiscussionTopicInfoWidget = ({ topicId, onReady }: IWidget) => {
         <Text type="secondary">
           <Space>
             {data?.user.nickName}
-            <TimeShow time={data?.createdAt} title="创建" />
+            <TimeShow updatedAt={data?.updatedAt} createdAt={data?.createdAt} />
           </Space>
         </Text>
       </div>

+ 41 - 9
dashboard/src/components/general/TimeShow.tsx

@@ -8,7 +8,9 @@ const { Text } = Typography;
 interface IWidgetTimeShow {
   showIcon?: boolean;
   showTooltip?: boolean;
-  time?: string;
+  showLabel?: boolean;
+  createdAt?: string;
+  updatedAt?: string;
   title?: string;
   type?: BaseType;
 }
@@ -16,7 +18,9 @@ interface IWidgetTimeShow {
 const TimeShowWidget = ({
   showIcon = true,
   showTooltip = true,
-  time,
+  showLabel = true,
+  createdAt,
+  updatedAt,
   title,
   type,
 }: IWidgetTimeShow) => {
@@ -24,8 +28,35 @@ const TimeShowWidget = ({
   const [passTime, setPassTime] = useState<string>();
   const [mTime, setMTime] = useState(0);
 
+  let mTitle: string | undefined;
+  let showTime: string | undefined;
+  if (typeof title === "undefined") {
+    if (updatedAt && createdAt) {
+      if (updatedAt === createdAt) {
+        mTitle = "创建";
+        showTime = createdAt;
+      } else {
+        mTitle = intl.formatMessage({
+          id: "labels.updated-at",
+        });
+        showTime = updatedAt;
+      }
+    } else if (createdAt) {
+      mTitle = "创建";
+      showTime = createdAt;
+    } else if (updatedAt) {
+      mTitle = "修改";
+      showTime = updatedAt;
+    } else {
+      mTitle = undefined;
+      showTime = "";
+    }
+  } else {
+    mTitle = title;
+  }
+
   useEffect(() => {
-    if (typeof time === "undefined") {
+    if (typeof createdAt === "undefined" && typeof updatedAt === "undefined") {
       return;
     }
     let timer = setInterval(() => {
@@ -37,17 +68,18 @@ const TimeShowWidget = ({
   }, []);
 
   useEffect(() => {
-    if (typeof time !== "undefined" && time !== "") {
-      setPassTime(getPassDataTime(time));
+    if (typeof showTime !== "undefined" && showTime !== "") {
+      setPassTime(getPassDataTime(showTime));
     }
-  }, [mTime, time]);
+  }, [mTime, showTime]);
 
-  if (typeof time === "undefined" || time === "") {
+  if (typeof showTime === "undefined") {
     return <></>;
   }
+
   const icon = showIcon ? <FieldTimeOutlined /> : <></>;
 
-  const tooltip: string = getFullDataTime(time);
+  const tooltip: string = getFullDataTime(showTime);
   const color = "lime";
   function getPassDataTime(t: string): string {
     let currDate = new Date();
@@ -106,7 +138,7 @@ const TimeShowWidget = ({
       <Text type={type}>
         <Space>
           {icon}
-          {title}
+          {mTitle}
           {passTime}
         </Space>
       </Text>

+ 5 - 3
dashboard/src/components/template/SentEdit/EditInfo.tsx

@@ -21,15 +21,17 @@ const EditInfoWidget = ({ data, isPr = false, compact = false }: IWidget) => {
       <User {...data.editor} showAvatar={isPr ? true : false} />
       <span>edit</span>
       {data.prEditAt ? (
-        <TimeShow time={data.prEditAt} />
+        <TimeShow updatedAt={data.prEditAt} />
       ) : (
-        <TimeShow time={data.updateAt} />
+        <TimeShow updatedAt={data.updateAt} />
       )}
       {data.acceptor ? (
         <User {...data.acceptor} showAvatar={false} />
       ) : undefined}
       {data.acceptor ? "accept at" : undefined}
-      {data.prEditAt ? <TimeShow time={data.updateAt} /> : undefined}
+      {data.prEditAt ? (
+        <TimeShow updatedAt={data.updateAt} showLabel={false} />
+      ) : undefined}
     </Space>
   );
   return (

+ 1 - 2
dashboard/src/components/term/TermItem.tsx

@@ -28,8 +28,7 @@ const TermItemWidget = ({ data }: IWidget) => {
               <Text type="secondary">
                 <UserName {...data?.editor} />
               </Text>
-              <Text type="secondary">update at</Text>
-              <TimeShow time={data?.updated_at} />
+              <TimeShow type="secondary" updatedAt={data?.updated_at} />
             </Space>
           </Space>
         }

+ 7 - 1
dashboard/src/pages/admin/nissaya-ending/list.tsx

@@ -231,7 +231,13 @@ const Widget = () => {
             valueType: "date",
             sorter: true,
             render: (text, row, index, action) => {
-              return <TimeShow time={row.updated_at} showIcon={false} />;
+              return (
+                <TimeShow
+                  updatedAt={row.updated_at}
+                  showLabel
+                  showIcon={false}
+                />
+              );
             },
           },
           {

+ 7 - 1
dashboard/src/pages/admin/relation/list.tsx

@@ -317,7 +317,13 @@ const Widget = () => {
             valueType: "date",
             sorter: true,
             render: (text, row, index, action) => {
-              return <TimeShow time={row.updated_at} showIcon={false} />;
+              return (
+                <TimeShow
+                  updatedAt={row.updated_at}
+                  showLabel={false}
+                  showIcon={false}
+                />
+              );
             },
           },
           {

+ 1 - 1
dashboard/src/pages/library/discussion/list.tsx

@@ -73,7 +73,7 @@ const Widget = () => {
             return (
               <Space>
                 {`${row.user.nickName} created on`}
-                <TimeShow time={row.createdAt} title={""} />
+                <TimeShow createdAt={row.createdAt} showLabel={false} />
               </Space>
             );
           },

+ 11 - 3
dashboard/src/pages/library/discussion/topic.tsx

@@ -5,13 +5,20 @@ import { ArrowLeftOutlined } from "@ant-design/icons";
 
 import CommentAnchor from "../../../components/discussion/DiscussionAnchor";
 import { IComment } from "../../../components/discussion/DiscussionItem";
-import CommentTopic from "../../../components/discussion/DiscussionTopic";
-import { useState } from "react";
+import DiscussionTopic from "../../../components/discussion/DiscussionTopic";
+import { useEffect, useLayoutEffect, useState } from "react";
 
 const Widget = () => {
   const { id } = useParams(); //url 参数
   const navigate = useNavigate();
   const [discussion, setDiscussion] = useState<IComment>();
+  const href = window.location.href.split("#");
+  const anchor = href.length > 1 ? href[1] : undefined;
+
+  useEffect(() => {
+    const ele = document.getElementById(`answer-${anchor}`);
+    ele?.scrollIntoView();
+  });
   return (
     <>
       <CommentAnchor resId={discussion?.resId} resType={discussion?.resType} />
@@ -32,8 +39,9 @@ const Widget = () => {
           </Button>
         }
       >
-        <CommentTopic
+        <DiscussionTopic
           topicId={id}
+          focus={anchor}
           onTopicReady={(value: IComment) => {
             console.log("onTopicReady");
             setDiscussion(value);