Commit 56493c78 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'optimize/notification' into 'main'

optimize notification

See merge request mycard/Neos!407
parents 739cf62b fea8d981
import { message } from "antd"; import { MessageOutlined } from "@ant-design/icons";
import { message, notification } from "antd";
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { useSnapshot } from "valtio"; import { useSnapshot } from "valtio";
...@@ -6,6 +7,7 @@ import { fetchStrings, Region } from "@/api"; ...@@ -6,6 +7,7 @@ import { fetchStrings, Region } from "@/api";
import { Phase2StringCodeMap } from "@/common"; import { Phase2StringCodeMap } from "@/common";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { HandResult, matStore } from "@/stores"; import { HandResult, matStore } from "@/stores";
import { useChat } from "@/ui/Shared";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
...@@ -13,16 +15,21 @@ const NeosConfig = useConfig(); ...@@ -13,16 +15,21 @@ const NeosConfig = useConfig();
let globalMsgApi: ReturnType<typeof message.useMessage>[0] | undefined; let globalMsgApi: ReturnType<typeof message.useMessage>[0] | undefined;
export const HintNotification = () => { export const HintNotification = () => {
const snap = useSnapshot(matStore); const matSnap = useSnapshot(matStore);
const hintState = snap.hint; const hintState = matSnap.hint;
const toss = snap.tossResult; const toss = matSnap.tossResult;
const handResults = snap.handResults; const handResults = matSnap.handResults;
const currentPhase = snap.phase.currentPhase; const currentPhase = matSnap.phase.currentPhase;
const error = snap.error; const error = matSnap.error;
const { dialogs } = useChat(true);
const [msgApi, msgContextHolder] = message.useMessage({ const [msgApi, msgContextHolder] = message.useMessage({
maxCount: NeosConfig.ui.hint.maxCount, maxCount: NeosConfig.ui.hint.maxCount,
}); });
const [notiApi, notiContextHolder] = notification.useNotification({
maxCount: NeosConfig.ui.hint.maxCount,
});
globalMsgApi = msgApi; globalMsgApi = msgApi;
useEffect(() => { useEffect(() => {
if (hintState && hintState.msg) { if (hintState && hintState.msg) {
...@@ -68,7 +75,23 @@ export const HintNotification = () => { ...@@ -68,7 +75,23 @@ export const HintNotification = () => {
} }
}, [error]); }, [error]);
return <>{msgContextHolder}</>; useEffect(() => {
const latest = dialogs.at(-1);
if (latest) {
notiApi.open({
message: latest.name,
description: latest.content,
icon: <MessageOutlined />,
});
}
}, [dialogs]);
return (
<>
{msgContextHolder}
{notiContextHolder}
</>
);
}; };
// 防抖的waiting msg // 防抖的waiting msg
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment