Commit ffb387c3 authored by Chunchi Che's avatar Chunchi Che

fix crash

parent ca83bae4
Pipeline #23216 passed with stages
in 10 minutes and 1 second
......@@ -25,11 +25,11 @@ import {
const NeosConfig = useConfig();
export const loader: LoaderFunction = async () => {
getLoginStatus();
initDeck();
initSqlite();
initWASM();
initForbidden();
await getLoginStatus();
await initDeck();
await initSqlite();
await initWASM();
await initForbidden();
return null;
};
......
......@@ -11,7 +11,7 @@ import { useSnapshot } from "valtio";
import { match } from "@/api";
import { useConfig } from "@/config";
import { accountStore, deckStore, IDeck, roomStore } from "@/stores";
import { accountStore, deckStore, roomStore } from "@/stores";
import { Background, IconFont, Select } from "@/ui/Shared";
import styles from "./index.module.scss";
......@@ -27,12 +27,12 @@ export const Component: React.FC = () => {
const [server, setServer] = useState(
`${serverList[0].ip}:${serverList[0].port}`,
);
const { decks } = useSnapshot(deckStore);
const [deck, setDeck] = useState<IDeck>(JSON.parse(JSON.stringify(decks[0])));
const { decks } = deckStore;
const [deckName, setDeckName] = useState(decks.at(0)?.deckName ?? "");
const user = accountStore.user;
const { joined } = useSnapshot(roomStore);
const [singleLoading, setSingleLoading] = useState(false); // 单人模式的loading状态
const [matchLoading, setMatchLoading] = useState(false);
const [matchLoading, setMatchLoading] = useState(false); // 匹配模式的loading状态
const navigate = useNavigate();
// 竞技匹配
......@@ -107,13 +107,13 @@ export const Component: React.FC = () => {
<Select
title="卡组"
showSearch
value={deck.deckName}
value={deckName}
style={{ width: 200 }}
onChange={(value) => {
// @ts-ignore
const item = deckStore.get(value);
if (item) {
setDeck(item);
setDeckName(item.deckName);
} else {
message.error(`Deck ${value} not found`);
}
......
......@@ -43,8 +43,10 @@ export const Component: React.FC = () => {
const { message } = App.useApp();
const { user } = useSnapshot(accountStore);
const [collapsed, setCollapsed] = useState(false);
const { decks } = useSnapshot(deckStore);
const [deck, setDeck] = useState<IDeck>(JSON.parse(JSON.stringify(decks[0])));
const { decks } = deckStore;
const defaultDeck =
decks.length > 0 ? JSON.parse(JSON.stringify(decks[0])) : undefined;
const [deck, setDeck] = useState<IDeck | undefined>(defaultDeck);
const room = useSnapshot(roomStore);
const { errorMsg } = room;
const me = room.getMePlayer();
......@@ -104,12 +106,16 @@ export const Component: React.FC = () => {
className={styles["btn-join"]}
onClick={() => {
if (me?.state === PlayerState.NO_READY) {
if (deck) {
sendUpdateDeck(deck);
// 设置side里面的卡组
sideStore.deck = deck;
// 设置额外卡组数据
window.myExtraDeckCodes = [...deck.extra];
sendHsReady();
} else {
message.error("请先选择卡组");
}
} else {
sendHsNotReady();
}
......
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