Skip to content

Commit

Permalink
fix: grade can not set zero
Browse files Browse the repository at this point in the history
  • Loading branch information
hqer927 committed Feb 24, 2025
1 parent a2abe55 commit 91feabd
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import React, { FC, useEffect } from "react";
import { Button, Modal } from "antd";
import { useTranslate } from "@netless/flat-i18n";
import { SVGGood } from "../../FlatIcons/icons/SVGGood";

export interface StopClassConfirmModalProps {
visible: boolean;
Expand Down Expand Up @@ -41,6 +40,8 @@ export interface CloseRoomConfirmModalProps {
hangLoading: boolean;
stopLoading: boolean;
rateModal?: React.ReactNode;
showRateModal?: boolean;
setShowRateModal?: (show: boolean) => void;
onHang: () => void;
onStop: () => void;
onCancel: () => void;
Expand All @@ -56,35 +57,14 @@ export const CloseRoomConfirmModal: FC<CloseRoomConfirmModalProps> = ({
hangLoading,
stopLoading,
rateModal,
showRateModal,
setShowRateModal,
onHang,
onStop,
onCancel,
setGrade,
}) => {
const t = useTranslate();
const [loading, setLoading] = React.useState(false);
const [showRateModal, setShowRateModal] = React.useState(false);
const [open, setOpen] = React.useState(visible);
const handleOk = async () => {
setLoading(true);
try {
if (setGrade) {
await setGrade();
}
setLoading(false);
setShowRateModal(false);
onStop();
} catch (error) {
console.error(error);
setLoading(false);
setShowRateModal(false);
onCancel();
}
};
const handCancel = async () => {
setShowRateModal(false);
onStop();
};
useEffect(() => {
setOpen(visible);
}, [visible]);
Expand All @@ -103,7 +83,7 @@ export const CloseRoomConfirmModal: FC<CloseRoomConfirmModalProps> = ({
loading={stopLoading}
type="primary"
onClick={() => {
if (rateModal) {
if (setShowRateModal) {
setShowRateModal(true);
setOpen(false);
} else {
Expand All @@ -121,26 +101,7 @@ export const CloseRoomConfirmModal: FC<CloseRoomConfirmModalProps> = ({
>
<p>{t("exit-room-tips")}</p>
</Modal>
{showRateModal && (
<Modal
footer={[
<Button key="submit" loading={loading} type="primary" onClick={handleOk}>
{t("home-page-AI-teacher-modal.rate.submit")}
</Button>,
]}
open={true}
title={
<div style={{ display: "flex", alignItems: "stretch" }}>
<span>{t("home-page-AI-teacher-modal.rate.title")} </span>
<SVGGood />
</div>
}
onCancel={handCancel}
onOk={handleOk}
>
{rateModal}
</Modal>
)}
{(showRateModal && rateModal) || null}
</>
);
};
Expand Down
83 changes: 63 additions & 20 deletions packages/flat-pages/src/AIPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "./AIPage.less";
import React, { useContext, useEffect, useMemo, useState } from "react";
import { useTranslate } from "@netless/flat-i18n";
import { observer } from "mobx-react-lite";
import { message, Popover } from "antd";
import { Button, message, Modal, Popover } from "antd";
import {
NetworkStatus,
TopBar,
Expand All @@ -17,6 +17,7 @@ import {
SVGWhiteBoardOff,
SVGRate,
SVGAIChatMsgCC,
SVGGood,
} from "flat-components";

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

const isRealtimeSideOpen = !whiteboardStore.isRightSideClose;
const [value, setValue] = useState(0);
const [grade, setGrade] = useState(0);
const [isFirst, setIsFirst] = useState(false);
const [show, setShow] = useState(true);
const [showRateModal, setShowRateModal] = React.useState(false);
const [loading, setLoading] = React.useState(false);

useEffect(() => {
if (classroomStore.userWindowsMode === "normal") {
Expand Down Expand Up @@ -107,6 +110,25 @@ export const AIPage = withClassroomStore<AIPageProps>(
}
return null;
}, [classroomStore.isHasAIUser]);
const handleOk: () => Promise<void> = async () => {
setLoading(true);
try {
await setGradeRoom({
roomUUID: classroomStore.roomUUID,
userUUID: classroomStore.userUUID,
grade,
});
setLoading(false);
setShowRateModal(false);
exitConfirmModalProps.onStopClass();
} catch (error) {
console.error(error);
setLoading(false);
setShowRateModal(false);
exitConfirmModalProps.onCancel();
}
};

return (
(aiUser && (
<div className="ai-page-class-page-container">
Expand Down Expand Up @@ -135,25 +157,46 @@ export const AIPage = withClassroomStore<AIPageProps>(
<ExitRoomConfirm
isCreator={classroomStore.isCreator}
rateModal={
<Rate
character={<SVGRate active={value > 3} />}
className="ai-page-rate-ui"
style={{ color: value > 3 ? "#FE4D00" : "#007AFF" }}
value={value}
onHoverChange={(value: number) => {
if (value) {
setValue(value);
}
}}
/>
<Modal
closable={false}
footer={[
<Button
key="submit"
disabled={grade <= 0}
loading={loading}
type="primary"
onClick={handleOk}
>
{t("home-page-AI-teacher-modal.rate.submit")}
</Button>,
]}
maskClosable={false}
open={true}
title={
<div style={{ display: "flex", alignItems: "stretch" }}>
<span>
{t("home-page-AI-teacher-modal.rate.title")}{" "}
</span>
<SVGGood />
</div>
}
onOk={handleOk}
>
<Rate
character={<SVGRate active={grade > 3} />}
className="ai-page-rate-ui"
style={{ color: grade > 3 ? "#FE4D00" : "#007AFF" }}
value={grade}
onHoverChange={(grade: number) => {
if (grade) {
setGrade(grade);
}
}}
/>
</Modal>
}
setGrade={() => {
return setGradeRoom({
roomUUID: classroomStore.roomUUID,
userUUID: classroomStore.userUUID,
grade: value,
});
}}
setShowRateModal={setShowRateModal}
showRateModal={showRateModal}
{...exitConfirmModalProps}
/>
<RoomStatusStoppedModal
Expand Down
6 changes: 6 additions & 0 deletions packages/flat-pages/src/components/ExitRoomConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface ExitRoomConfirmProps {
isReturnLoading: boolean;
isStopLoading: boolean;
rateModal?: React.ReactNode;
showRateModal?: boolean;
setShowRateModal?: (showRateModal: boolean) => void;
onReturnMain: () => Promise<void>;
onStopClass: () => Promise<void>;
onCancel: () => void;
Expand Down Expand Up @@ -120,6 +122,8 @@ export const ExitRoomConfirm = observer<Omit<ExitRoomConfirmProps, "confirm">>(
isReturnLoading,
isStopLoading,
rateModal,
showRateModal,
setShowRateModal,
onReturnMain,
onStopClass,
...restProps
Expand All @@ -130,6 +134,8 @@ export const ExitRoomConfirm = observer<Omit<ExitRoomConfirmProps, "confirm">>(
{...restProps}
hangLoading={isReturnLoading}
rateModal={rateModal}
setShowRateModal={setShowRateModal}
showRateModal={showRateModal}
stopLoading={isStopLoading}
onHang={onReturnMain}
onStop={onStopClass}
Expand Down

0 comments on commit 91feabd

Please sign in to comment.