Skip to content

Commit 5d393ac

Browse files
committed
fix: set grade can not 0
1 parent 0f6e296 commit 5d393ac

File tree

3 files changed

+75
-65
lines changed

3 files changed

+75
-65
lines changed

packages/flat-components/src/components/ClassroomPage/ExitRoomConfirmModal/index.tsx

+6-45
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import React, { FC, useEffect } from "react";
44
import { Button, Modal } from "antd";
55
import { useTranslate } from "@netless/flat-i18n";
6-
import { SVGGood } from "../../FlatIcons/icons/SVGGood";
76

87
export interface StopClassConfirmModalProps {
98
visible: boolean;
@@ -41,6 +40,8 @@ export interface CloseRoomConfirmModalProps {
4140
hangLoading: boolean;
4241
stopLoading: boolean;
4342
rateModal?: React.ReactNode;
43+
showRateModal?: boolean;
44+
setShowRateModal?: (show: boolean) => void;
4445
onHang: () => void;
4546
onStop: () => void;
4647
onCancel: () => void;
@@ -56,35 +57,14 @@ export const CloseRoomConfirmModal: FC<CloseRoomConfirmModalProps> = ({
5657
hangLoading,
5758
stopLoading,
5859
rateModal,
60+
showRateModal,
61+
setShowRateModal,
5962
onHang,
6063
onStop,
6164
onCancel,
62-
setGrade,
6365
}) => {
6466
const t = useTranslate();
65-
const [loading, setLoading] = React.useState(false);
66-
const [showRateModal, setShowRateModal] = React.useState(false);
6767
const [open, setOpen] = React.useState(visible);
68-
const handleOk = async () => {
69-
setLoading(true);
70-
try {
71-
if (setGrade) {
72-
await setGrade();
73-
}
74-
setLoading(false);
75-
setShowRateModal(false);
76-
onStop();
77-
} catch (error) {
78-
console.error(error);
79-
setLoading(false);
80-
setShowRateModal(false);
81-
onCancel();
82-
}
83-
};
84-
const handCancel = async () => {
85-
setShowRateModal(false);
86-
onStop();
87-
};
8868
useEffect(() => {
8969
setOpen(visible);
9070
}, [visible]);
@@ -103,7 +83,7 @@ export const CloseRoomConfirmModal: FC<CloseRoomConfirmModalProps> = ({
10383
loading={stopLoading}
10484
type="primary"
10585
onClick={() => {
106-
if (rateModal) {
86+
if (setShowRateModal) {
10787
setShowRateModal(true);
10888
setOpen(false);
10989
} else {
@@ -121,26 +101,7 @@ export const CloseRoomConfirmModal: FC<CloseRoomConfirmModalProps> = ({
121101
>
122102
<p>{t("exit-room-tips")}</p>
123103
</Modal>
124-
{showRateModal && (
125-
<Modal
126-
footer={[
127-
<Button key="submit" loading={loading} type="primary" onClick={handleOk}>
128-
{t("home-page-AI-teacher-modal.rate.submit")}
129-
</Button>,
130-
]}
131-
open={true}
132-
title={
133-
<div style={{ display: "flex", alignItems: "stretch" }}>
134-
<span>{t("home-page-AI-teacher-modal.rate.title")} </span>
135-
<SVGGood />
136-
</div>
137-
}
138-
onCancel={handCancel}
139-
onOk={handleOk}
140-
>
141-
{rateModal}
142-
</Modal>
143-
)}
104+
{(showRateModal && rateModal) || null}
144105
</>
145106
);
146107
};

packages/flat-pages/src/AIPage/index.tsx

+63-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import "./AIPage.less";
33
import React, { useContext, useEffect, useMemo, useState } from "react";
44
import { useTranslate } from "@netless/flat-i18n";
55
import { observer } from "mobx-react-lite";
6-
import { message, Popover } from "antd";
6+
import { Button, message, Modal, Popover } from "antd";
77
import {
88
NetworkStatus,
99
TopBar,
@@ -17,6 +17,7 @@ import {
1717
SVGWhiteBoardOff,
1818
SVGRate,
1919
SVGAIChatMsgCC,
20+
SVGGood,
2021
} from "flat-components";
2122

2223
import { RealtimePanel } from "../components/RealtimePanel";
@@ -55,9 +56,11 @@ export const AIPage = withClassroomStore<AIPageProps>(
5556
const { confirm, ...exitConfirmModalProps } = useExitRoomConfirmModal(classroomStore);
5657

5758
const isRealtimeSideOpen = !whiteboardStore.isRightSideClose;
58-
const [value, setValue] = useState(0);
59+
const [grade, setGrade] = useState(0);
5960
const [isFirst, setIsFirst] = useState(false);
6061
const [show, setShow] = useState(true);
62+
const [showRateModal, setShowRateModal] = React.useState(false);
63+
const [loading, setLoading] = React.useState(false);
6164

6265
useEffect(() => {
6366
if (classroomStore.userWindowsMode === "normal") {
@@ -107,6 +110,25 @@ export const AIPage = withClassroomStore<AIPageProps>(
107110
}
108111
return null;
109112
}, [classroomStore.isHasAIUser]);
113+
const handleOk: () => Promise<void> = async () => {
114+
setLoading(true);
115+
try {
116+
await setGradeRoom({
117+
roomUUID: classroomStore.roomUUID,
118+
userUUID: classroomStore.userUUID,
119+
grade,
120+
});
121+
setLoading(false);
122+
setShowRateModal(false);
123+
exitConfirmModalProps.onStopClass();
124+
} catch (error) {
125+
console.error(error);
126+
setLoading(false);
127+
setShowRateModal(false);
128+
exitConfirmModalProps.onCancel();
129+
}
130+
};
131+
110132
return (
111133
(aiUser && (
112134
<div className="ai-page-class-page-container">
@@ -135,25 +157,46 @@ export const AIPage = withClassroomStore<AIPageProps>(
135157
<ExitRoomConfirm
136158
isCreator={classroomStore.isCreator}
137159
rateModal={
138-
<Rate
139-
character={<SVGRate active={value > 3} />}
140-
className="ai-page-rate-ui"
141-
style={{ color: value > 3 ? "#FE4D00" : "#007AFF" }}
142-
value={value}
143-
onHoverChange={(value: number) => {
144-
if (value) {
145-
setValue(value);
146-
}
147-
}}
148-
/>
160+
<Modal
161+
closable={false}
162+
footer={[
163+
<Button
164+
key="submit"
165+
disabled={grade <= 0}
166+
loading={loading}
167+
type="primary"
168+
onClick={handleOk}
169+
>
170+
{t("home-page-AI-teacher-modal.rate.submit")}
171+
</Button>,
172+
]}
173+
maskClosable={false}
174+
open={true}
175+
title={
176+
<div style={{ display: "flex", alignItems: "stretch" }}>
177+
<span>
178+
{t("home-page-AI-teacher-modal.rate.title")}{" "}
179+
</span>
180+
<SVGGood />
181+
</div>
182+
}
183+
onOk={handleOk}
184+
>
185+
<Rate
186+
character={<SVGRate active={grade > 3} />}
187+
className="ai-page-rate-ui"
188+
style={{ color: grade > 3 ? "#FE4D00" : "#007AFF" }}
189+
value={grade}
190+
onHoverChange={(grade: number) => {
191+
if (grade) {
192+
setGrade(grade);
193+
}
194+
}}
195+
/>
196+
</Modal>
149197
}
150-
setGrade={() => {
151-
return setGradeRoom({
152-
roomUUID: classroomStore.roomUUID,
153-
userUUID: classroomStore.userUUID,
154-
grade: value,
155-
});
156-
}}
198+
setShowRateModal={setShowRateModal}
199+
showRateModal={showRateModal}
157200
{...exitConfirmModalProps}
158201
/>
159202
<RoomStatusStoppedModal

packages/flat-pages/src/components/ExitRoomConfirm.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface ExitRoomConfirmProps {
2323
isReturnLoading: boolean;
2424
isStopLoading: boolean;
2525
rateModal?: React.ReactNode;
26+
showRateModal?: boolean;
27+
setShowRateModal?: (showRateModal: boolean) => void;
2628
onReturnMain: () => Promise<void>;
2729
onStopClass: () => Promise<void>;
2830
onCancel: () => void;
@@ -120,6 +122,8 @@ export const ExitRoomConfirm = observer<Omit<ExitRoomConfirmProps, "confirm">>(
120122
isReturnLoading,
121123
isStopLoading,
122124
rateModal,
125+
showRateModal,
126+
setShowRateModal,
123127
onReturnMain,
124128
onStopClass,
125129
...restProps
@@ -130,6 +134,8 @@ export const ExitRoomConfirm = observer<Omit<ExitRoomConfirmProps, "confirm">>(
130134
{...restProps}
131135
hangLoading={isReturnLoading}
132136
rateModal={rateModal}
137+
setShowRateModal={setShowRateModal}
138+
showRateModal={showRateModal}
133139
stopLoading={isStopLoading}
134140
onHang={onReturnMain}
135141
onStop={onStopClass}

0 commit comments

Comments
 (0)