|
@@ -7,6 +7,7 @@ import { TResType } from "./DiscussionListCard";
|
|
|
import { useAppSelector } from "../../hooks";
|
|
import { useAppSelector } from "../../hooks";
|
|
|
import { currentUser } from "../../reducers/current-user";
|
|
import { currentUser } from "../../reducers/current-user";
|
|
|
import { discussionList } from "../../reducers/discussion-count";
|
|
import { discussionList } from "../../reducers/discussion-count";
|
|
|
|
|
+import { IDiscussionCountWbw } from "../api/Comment";
|
|
|
|
|
|
|
|
interface IWidget {
|
|
interface IWidget {
|
|
|
initCount?: number;
|
|
initCount?: number;
|
|
@@ -15,6 +16,7 @@ interface IWidget {
|
|
|
hideCount?: boolean;
|
|
hideCount?: boolean;
|
|
|
hideInZero?: boolean;
|
|
hideInZero?: boolean;
|
|
|
onlyMe?: boolean;
|
|
onlyMe?: boolean;
|
|
|
|
|
+ wbw?: IDiscussionCountWbw;
|
|
|
}
|
|
}
|
|
|
const DiscussionButton = ({
|
|
const DiscussionButton = ({
|
|
|
initCount = 0,
|
|
initCount = 0,
|
|
@@ -23,12 +25,22 @@ const DiscussionButton = ({
|
|
|
hideCount = false,
|
|
hideCount = false,
|
|
|
hideInZero = false,
|
|
hideInZero = false,
|
|
|
onlyMe = false,
|
|
onlyMe = false,
|
|
|
|
|
+ wbw,
|
|
|
}: IWidget) => {
|
|
}: IWidget) => {
|
|
|
const user = useAppSelector(currentUser);
|
|
const user = useAppSelector(currentUser);
|
|
|
const discussions = useAppSelector(discussionList);
|
|
const discussions = useAppSelector(discussionList);
|
|
|
|
|
|
|
|
const all = discussions?.filter((value) => value.res_id === resId);
|
|
const all = discussions?.filter((value) => value.res_id === resId);
|
|
|
const my = all?.filter((value) => value.editor_uid === user?.id);
|
|
const my = all?.filter((value) => value.editor_uid === user?.id);
|
|
|
|
|
+ const withStudent = discussions?.filter(
|
|
|
|
|
+ (value) =>
|
|
|
|
|
+ value.wbw?.book_id === wbw?.book_id &&
|
|
|
|
|
+ value.wbw?.paragraph === wbw?.paragraph &&
|
|
|
|
|
+ value.wbw?.wid.toString() === wbw?.wid.toString()
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ console.debug("DiscussionButton", discussions, wbw, withStudent);
|
|
|
|
|
+
|
|
|
let currCount = initCount;
|
|
let currCount = initCount;
|
|
|
if (onlyMe) {
|
|
if (onlyMe) {
|
|
|
if (my) {
|
|
if (my) {
|
|
@@ -42,6 +54,9 @@ const DiscussionButton = ({
|
|
|
} else {
|
|
} else {
|
|
|
currCount = 0;
|
|
currCount = 0;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (withStudent) {
|
|
|
|
|
+ currCount += withStudent.length;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let myCount = false;
|
|
let myCount = false;
|