Bladeren bron

add focus

visuddhinanda 2 jaren geleden
bovenliggende
commit
06c4063613

+ 3 - 0
dashboard/src/components/article/Article.tsx

@@ -50,6 +50,7 @@ interface IWidget {
   exerciseId?: string;
   userName?: string;
   active?: boolean;
+  focus?: string | null;
   onArticleChange?: Function;
   onFinal?: Function;
   onLoad?: Function;
@@ -67,6 +68,7 @@ const ArticleWidget = ({
   userName,
   mode = "read",
   active = false,
+  focus,
   onArticleChange,
   onFinal,
   onLoad,
@@ -128,6 +130,7 @@ const ArticleWidget = ({
           mode={mode}
           book={book}
           para={para}
+          focus={focus}
           onArticleChange={(type: ArticleType, id: string) => {
             if (typeof onArticleChange !== "undefined") {
               onArticleChange(type, id);

+ 9 - 0
dashboard/src/components/article/TypePali.tsx

@@ -12,6 +12,8 @@ import { ArticleMode, ArticleType } from "./Article";
 import "./article.css";
 import ArticleSkeleton from "./ArticleSkeleton";
 import ErrorResult from "../general/ErrorResult";
+import store from "../../store";
+import { refresh } from "../../reducers/focus";
 
 interface IWidget {
   type?: ArticleType;
@@ -21,6 +23,7 @@ interface IWidget {
   book?: string | null;
   para?: string | null;
   active?: boolean;
+  focus?: string | null;
   onArticleChange?: Function;
   onFinal?: Function;
   onLoad?: Function;
@@ -33,6 +36,7 @@ const TypePaliWidget = ({
   articleId,
   mode = "read",
   active = true,
+  focus,
   onArticleChange,
   onFinal,
   onLoad,
@@ -48,6 +52,11 @@ const TypePaliWidget = ({
   const channels = channelId?.split("_");
 
   const srcDataMode = mode === "edit" || mode === "wbw" ? "edit" : "read";
+
+  useEffect(() => {
+    store.dispatch(refresh({ type: "para", id: focus }));
+  }, [focus]);
+
   useEffect(() => {
     console.log("srcDataMode", srcDataMode);
     if (!active) {

+ 29 - 2
dashboard/src/components/template/ParaShell.tsx

@@ -1,3 +1,6 @@
+import { useEffect, useState } from "react";
+import { useAppSelector } from "../../hooks";
+import { currFocus } from "../../reducers/focus";
 import { ParaHandleCtl } from "./ParaHandle";
 
 interface IWidgetParaShellCtl {
@@ -16,10 +19,34 @@ const ParaShellCtl = ({
   sentences,
   children,
 }: IWidgetParaShellCtl) => {
+  const focus = useAppSelector(currFocus);
+  const [isFocus, setIsFocus] = useState(false);
+  useEffect(() => {
+    if (focus) {
+      if (focus.focus?.type === "para") {
+        if (focus.focus.id) {
+          const arrId = focus.focus.id.split("-");
+          if (arrId.length > 1) {
+            const focusBook = parseInt(arrId[0]);
+            const focusPara = arrId[1].split(",").map((item) => parseInt(item));
+            if (focusBook === book && focusPara.includes(para)) {
+              setIsFocus(true);
+            }
+          }
+        } else {
+          setIsFocus(false);
+        }
+      }
+    } else {
+      setIsFocus(false);
+    }
+  }, [book, focus, para]);
   return (
     <div
       style={{
-        borderTop: "1px solid #80808080",
+        borderTop: isFocus ? undefined : "1px solid #80808080",
+        border: isFocus ? "1px solid #006bff" : undefined,
+        borderRadius: isFocus ? 6 : undefined,
         marginTop: 20,
         paddingTop: 16,
       }}
@@ -28,7 +55,7 @@ const ParaShellCtl = ({
         style={{
           position: "absolute",
           marginTop: "-2em",
-          left: "56px",
+          marginLeft: "1em",
           backgroundColor: "#d9e9ff",
           borderRadius: "4px",
         }}

+ 1 - 2
dashboard/src/pages/library/article/show.tsx

@@ -48,7 +48,6 @@ import { TResType } from "../../../components/discussion/DiscussionListCard";
 import { modeChange } from "../../../reducers/article-mode";
 import SearchButton from "../../../components/general/SearchButton";
 import ToStudio from "../../../components/auth/ToStudio";
-import { currentUser as _currentUser } from "../../../reducers/current-user";
 import LoginAlertModal from "../../../components/auth/LoginAlertModal";
 import ShareButton from "../../../components/export/ShareButton";
 
@@ -76,7 +75,6 @@ const Widget = () => {
     useState<IArticleDataResponse>();
 
   const paraChange = useAppSelector(paraParam);
-  const user = useAppSelector(_currentUser);
 
   useEffect(() => {
     if (typeof paraChange === "undefined") {
@@ -331,6 +329,7 @@ const Widget = () => {
               book={searchParams.get("book")}
               para={searchParams.get("par")}
               channelId={searchParams.get("channel")}
+              focus={searchParams.get("focus")}
               articleId={id}
               anthologyId={searchParams.get("anthology")}
               mode={searchParams.get("mode") as ArticleMode}

+ 2 - 0
dashboard/src/store.ts

@@ -25,6 +25,7 @@ import netStatusReducer from "./reducers/net-status";
 import discussionReducer from "./reducers/discussion";
 import wbwReducer from "./reducers/wbw";
 import termOrderReducer from "./reducers/term-order";
+import focusReducer from "./reducers/focus";
 
 const store = configureStore({
   reducer: {
@@ -53,6 +54,7 @@ const store = configureStore({
     discussion: discussionReducer,
     wbw: wbwReducer,
     termOrder: termOrderReducer,
+    focus: focusReducer,
   },
 });