Commit b4cfa173 authored by Chunchi Che's avatar Chunchi Che

fix redux

parent d898ab28
Pipeline #17234 failed with stage
in 2 minutes
...@@ -2848,9 +2848,8 @@ ...@@ -2848,9 +2848,8 @@
}, },
"node_modules/@reduxjs/toolkit": { "node_modules/@reduxjs/toolkit": {
"version": "1.8.6", "version": "1.8.6",
"resolved": "http://bnpm.byted.org/@reduxjs/toolkit/-/toolkit-1.8.6.tgz", "resolved": "https://registry.npmjs.org/@reduxjs/toolkit/-/toolkit-1.8.6.tgz",
"integrity": "sha512-4Ia/Loc6WLmdSOzi7k5ff7dLK8CgG2b8aqpLsCAJhazAzGdp//YBUSaj0ceW6a3kDBDNRrq5CRwyCS0wBiL1ig==", "integrity": "sha512-4Ia/Loc6WLmdSOzi7k5ff7dLK8CgG2b8aqpLsCAJhazAzGdp//YBUSaj0ceW6a3kDBDNRrq5CRwyCS0wBiL1ig==",
"license": "MIT",
"dependencies": { "dependencies": {
"immer": "^9.0.7", "immer": "^9.0.7",
"redux": "^4.1.2", "redux": "^4.1.2",
...@@ -17559,7 +17558,7 @@ ...@@ -17559,7 +17558,7 @@
}, },
"@reduxjs/toolkit": { "@reduxjs/toolkit": {
"version": "1.8.6", "version": "1.8.6",
"resolved": "http://bnpm.byted.org/@reduxjs/toolkit/-/toolkit-1.8.6.tgz", "resolved": "https://registry.npmjs.org/@reduxjs/toolkit/-/toolkit-1.8.6.tgz",
"integrity": "sha512-4Ia/Loc6WLmdSOzi7k5ff7dLK8CgG2b8aqpLsCAJhazAzGdp//YBUSaj0ceW6a3kDBDNRrq5CRwyCS0wBiL1ig==", "integrity": "sha512-4Ia/Loc6WLmdSOzi7k5ff7dLK8CgG2b8aqpLsCAJhazAzGdp//YBUSaj0ceW6a3kDBDNRrq5CRwyCS0wBiL1ig==",
"requires": { "requires": {
"immer": "^9.0.7", "immer": "^9.0.7",
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import type { RootState, AppDispatch } from "./store";
// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch: () => AppDispatch = useDispatch;
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { RootState } from "../store"; import { RootState } from "../store";
const initialState = ""; export interface chatState {
message: string;
}
const initialState: chatState = {
message: "",
};
const chatSlice = createSlice({ const chatSlice = createSlice({
name: "chat", name: "chat",
initialState, initialState,
reducers: { reducers: {
postChat: (state, action: PayloadAction<string>) => { postChat: (state, action: PayloadAction<string>) => {
state = action.payload; state.message = action.payload;
}, },
}, },
}); });
export const { postChat } = chatSlice.actions; export const { postChat } = chatSlice.actions;
export const selectChat = (state: RootState) => state.chat; export const selectChat = (state: RootState) => state.chat.message;
export default chatSlice.reducer; export default chatSlice.reducer;
import { createSlice } from "@reduxjs/toolkit"; import { createSlice } from "@reduxjs/toolkit";
import { RootState } from "../store"; import { RootState } from "../store";
const initialState = false; export interface JoinState {
value: boolean;
}
const initialState: JoinState = {
value: false,
};
const joinedSlice = createSlice({ const joinedSlice = createSlice({
name: "join", name: "join",
initialState, initialState,
reducers: { reducers: {
setJoined(state) { setJoined: (state) => {
state = true; state.value = true;
}, },
setUnJoined(state) { setUnJoined: (state) => {
state = false; state.value = false;
}, },
}, },
}); });
export const { setJoined, setUnJoined } = joinedSlice.actions; export const { setJoined, setUnJoined } = joinedSlice.actions;
export const selectJoined = (state: RootState) => state.join; export const selectJoined = (state: RootState) => state.join.value;
export default joinedSlice.reducer; export default joinedSlice.reducer;
...@@ -3,7 +3,7 @@ import { useParams } from "react-router-dom"; ...@@ -3,7 +3,7 @@ import { useParams } from "react-router-dom";
import { ygopro } from "../api/idl/ocgcore"; import { ygopro } from "../api/idl/ocgcore";
import { fetchDeck, IDeck } from "../api/Card"; import { fetchDeck, IDeck } from "../api/Card";
import "../css/WaitRoom.css"; import "../css/WaitRoom.css";
import { useDispatch, useSelector } from "react-redux"; import { useAppDispatch, useAppSelector } from "../hook";
import { setJoined, selectJoined } from "../reducers/joinSlice"; import { setJoined, selectJoined } from "../reducers/joinSlice";
import { postChat, selectChat } from "../reducers/chatSlice"; import { postChat, selectChat } from "../reducers/chatSlice";
...@@ -32,7 +32,7 @@ export default function WaitRoom() { ...@@ -32,7 +32,7 @@ export default function WaitRoom() {
const ws = useRef<WebSocket | null>(null); const ws = useRef<WebSocket | null>(null);
const dispatch = useDispatch(); const dispatch = useAppDispatch();
const { player, passWd, ip } = params; const { player, passWd, ip } = params;
...@@ -229,8 +229,8 @@ export default function WaitRoom() { ...@@ -229,8 +229,8 @@ export default function WaitRoom() {
}; };
}, [ws]); }, [ws]);
const joined = useSelector(selectJoined); const joined = useAppSelector(selectJoined);
const chat = useSelector(selectChat); const chat = useAppSelector(selectChat);
const handleChoseDeck = async () => { const handleChoseDeck = async () => {
if (ws.current) { if (ws.current) {
......
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