Commit 385774df authored by Chunchi Che's avatar Chunchi Che

reset stores when duel end

parent 96426b81
Pipeline #22695 passed with stages
in 10 minutes and 43 seconds
......@@ -26,3 +26,15 @@ devtools(matStore, { name: "mat", enabled: true });
devtools(cardStore, { name: "card", enabled: true });
devtools(placeStore, { name: "place", enabled: true });
devtools(replayStore, { name: "replay", enabled: true });
// 重置所有`Store`
export const resetUniverse = () => {
cardStore.reset();
chatStore.reset();
joinStore.reset();
matStore.reset();
moraStore.reset();
playerStore.reset();
playerStore.reset();
replayStore.reset();
};
import { proxy } from "valtio";
export interface MoraState {
import { NeosStore } from "./shared";
export interface MoraState extends NeosStore {
duelStart: boolean;
selectHandAble: boolean;
selectTpAble: boolean;
}
export const moraStore = proxy<MoraState>({
const initialState = {
duelStart: false,
selectHandAble: false,
selectTpAble: false,
};
export const moraStore = proxy<MoraState>({
...initialState,
reset() {
Object.entries(initialState).forEach((key) => {
// @ts-ignore
moraStore[key] = initialState[key];
});
},
});
import "./index.scss";
import React, { CSSProperties } from "react";
import { useNavigate } from "react-router-dom";
import { proxy, useSnapshot } from "valtio";
import { fetchStrings } from "@/api";
import { matStore, replayStore } from "@/stores";
import { matStore, replayStore, resetUniverse } from "@/stores";
import { NeosModal } from "../NeosModal";
......@@ -25,6 +26,13 @@ export const EndModal: React.FC = () => {
const { isOpen, isWin, reason } = useSnapshot(localStore);
const { isReplay } = useSnapshot(matStore);
const navigate = useNavigate();
const onReturn = () => {
rs();
resetUniverse();
navigate("/");
};
return (
<NeosModal
title={fetchStrings("!system", 1500)}
......@@ -38,12 +46,9 @@ export const EndModal: React.FC = () => {
// download the replay file
window.open(URL.createObjectURL(blob));
}
rs();
}}
onCancel={() => {
// TODO: reset all stores, and navigate to home
rs();
onReturn();
}}
onCancel={onReturn}
>
<div className="end-container">
<p
......
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