Commit 94bd5f03 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'dev/async_yesno_modal' into 'dev/async'

migrate yesno modal

See merge request mycard/Neos!236
parents 12eb6029 ee4bb39f
Pipeline #22405 failed with stages
in 14 minutes and 34 seconds
...@@ -135,7 +135,7 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -135,7 +135,7 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "select_effect_yn": { case "select_effect_yn": {
onMsgSelectEffectYn(msg.select_effect_yn); await onMsgSelectEffectYn(msg.select_effect_yn);
break; break;
} }
...@@ -170,7 +170,7 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -170,7 +170,7 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "select_yes_no": { case "select_yes_no": {
onMsgSelectYesNo(msg.select_yes_no); await onMsgSelectYesNo(msg.select_yes_no);
break; break;
} }
......
import { fetchStrings, ygopro } from "@/api"; import { fetchStrings, ygopro } from "@/api";
import { CardMeta, fetchCard } from "@/api/cards"; import { CardMeta, fetchCard } from "@/api/cards";
import { messageStore } from "@/stores"; import { displayYesNoModal } from "@/ui/Duel/Message";
type MsgSelectEffectYn = ygopro.StocGameMessage.MsgSelectEffectYn; type MsgSelectEffectYn = ygopro.StocGameMessage.MsgSelectEffectYn;
...@@ -33,6 +33,5 @@ export default async (selectEffectYn: MsgSelectEffectYn) => { ...@@ -33,6 +33,5 @@ export default async (selectEffectYn: MsgSelectEffectYn) => {
const desc = fetchStrings("!system", effect_description); const desc = fetchStrings("!system", effect_description);
const meta = await fetchCard(code); const meta = await fetchCard(code);
messageStore.yesNoModal.msg = textGenerator(desc, meta, location); await displayYesNoModal(textGenerator(desc, meta, location));
messageStore.yesNoModal.isOpen = true;
}; };
import { getStrings, ygopro } from "@/api"; import { getStrings, ygopro } from "@/api";
import { messageStore } from "@/stores"; import { displayYesNoModal } from "@/ui/Duel/Message";
type MsgSelectYesNo = ygopro.StocGameMessage.MsgSelectYesNo; type MsgSelectYesNo = ygopro.StocGameMessage.MsgSelectYesNo;
...@@ -7,6 +7,6 @@ export default async (selectYesNo: MsgSelectYesNo) => { ...@@ -7,6 +7,6 @@ export default async (selectYesNo: MsgSelectYesNo) => {
const _player = selectYesNo.player; const _player = selectYesNo.player;
const effect_description = selectYesNo.effect_description; const effect_description = selectYesNo.effect_description;
messageStore.yesNoModal.msg = await getStrings(effect_description); const msg = await getStrings(effect_description);
messageStore.yesNoModal.isOpen = true; await displayYesNoModal(msg);
}; };
import type { ygopro } from "@/api"; import type { ygopro } from "@/api";
import { fetchCard, getCardStr } from "@/api/cards"; import { fetchCard, getCardStr } from "@/api/cards";
import { cardStore } from "@/stores"; import { cardStore } from "@/stores";
import type { Option } from "@/ui/Duel/Message/SelectActionsModal"; import type { Option } from "@/ui/Duel/Message";
const helper = async ( const helper = async (
{ {
......
...@@ -3,7 +3,6 @@ import { proxy } from "valtio"; ...@@ -3,7 +3,6 @@ import { proxy } from "valtio";
import type { ModalState } from "./types"; import type { ModalState } from "./types";
export const messageStore = proxy<ModalState>({ export const messageStore = proxy<ModalState>({
yesNoModal: { isOpen: false },
positionModal: { isOpen: false, positions: [] }, positionModal: { isOpen: false, positions: [] },
checkCounterModal: { checkCounterModal: {
isOpen: false, isOpen: false,
......
import type { CardMeta, ygopro } from "@/api"; import type { CardMeta, ygopro } from "@/api";
export interface ModalState { export interface ModalState {
// Yes or No弹窗
yesNoModal: {
isOpen: boolean;
msg?: string;
};
// 表示形式选择弹窗 // 表示形式选择弹窗
positionModal: { positionModal: {
isOpen: boolean; isOpen: boolean;
......
import { Button } from "antd"; import { Button } from "antd";
import React from "react"; import React from "react";
import { useSnapshot } from "valtio"; import { proxy, useSnapshot } from "valtio";
import { sendSelectEffectYnResponse } from "@/api"; import { sendSelectEffectYnResponse } from "@/api";
import { matStore, messageStore } from "@/stores"; import { matStore } from "@/stores";
import { DragModal } from "./DragModal"; import { NeosModal } from "../NeosModal";
const { yesNoModal } = messageStore; interface YesNoModalProps {
isOpen: boolean;
msg?: string;
}
const defaultProps = { isOpen: false };
export const YesNoModal = () => { const localStore = proxy<YesNoModalProps>(defaultProps);
const snapYesNoModal = useSnapshot(yesNoModal);
const isOpen = snapYesNoModal.isOpen; export const YesNoModal: React.FC = () => {
const msg = snapYesNoModal.msg; const { isOpen, msg } = useSnapshot(localStore);
const hint = useSnapshot(matStore.hint); const hint = useSnapshot(matStore.hint);
const preHintMsg = hint?.esHint || ""; const preHintMsg = hint?.esHint || "";
return ( return (
<DragModal <NeosModal
title={`${preHintMsg} ${msg}`} title={`${preHintMsg} ${msg}`}
open={isOpen} open={isOpen}
closable={false} closable={false}
...@@ -27,8 +31,7 @@ export const YesNoModal = () => { ...@@ -27,8 +31,7 @@ export const YesNoModal = () => {
<Button <Button
onClick={() => { onClick={() => {
sendSelectEffectYnResponse(true); sendSelectEffectYnResponse(true);
// dispatch(setYesNoModalIsOpen(false)); rs();
yesNoModal.isOpen = false;
}} }}
> >
Yes Yes
...@@ -36,8 +39,7 @@ export const YesNoModal = () => { ...@@ -36,8 +39,7 @@ export const YesNoModal = () => {
<Button <Button
onClick={() => { onClick={() => {
sendSelectEffectYnResponse(false); sendSelectEffectYnResponse(false);
// dispatch(setYesNoModalIsOpen(false)); rs();
yesNoModal.isOpen = false;
}} }}
> >
No No
...@@ -47,3 +49,12 @@ export const YesNoModal = () => { ...@@ -47,3 +49,12 @@ export const YesNoModal = () => {
/> />
); );
}; };
let rs: (arg?: any) => void = () => {};
export const displayYesNoModal = async (msg: string) => {
localStore.msg = msg;
localStore.isOpen = true;
await new Promise<void>((resolve) => (rs = resolve)); // 等待在组件内resolve
localStore.isOpen = false;
};
...@@ -8,6 +8,7 @@ export * from "./HintNotification"; ...@@ -8,6 +8,7 @@ export * from "./HintNotification";
export * from "./OptionModal"; export * from "./OptionModal";
export * from "./PositionModal"; export * from "./PositionModal";
export * from "./SelectActionsModal"; export * from "./SelectActionsModal";
export { type Option } from "./SelectCardsModal";
export * from "./SimpleSelectCardsModal"; export * from "./SimpleSelectCardsModal";
export * from "./SortCardModal"; export * from "./SortCardModal";
export * from "./YesNoModal"; export * from "./YesNoModal";
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