Updates to deal with new categories msg
This commit is contained in:
parent
57a065abd1
commit
48210b9efd
@ -1,3 +1,4 @@
|
|||||||
|
import { Fragment } from "react";
|
||||||
import { Container, Button, Stack } from "react-bootstrap";
|
import { Container, Button, Stack } from "react-bootstrap";
|
||||||
|
|
||||||
import { useAppSelector } from "../hooks";
|
import { useAppSelector } from "../hooks";
|
||||||
@ -9,12 +10,12 @@ const CluesDisplay = () => {
|
|||||||
<Container>
|
<Container>
|
||||||
<Stack gap={3} className="text-center">
|
<Stack gap={3} className="text-center">
|
||||||
{categories.map(({ name }) => (
|
{categories.map(({ name }) => (
|
||||||
<>
|
<Fragment key={name}>
|
||||||
<h2>{name}</h2>
|
<h2>{name}</h2>
|
||||||
{[200, 400, 600, 800, 1000].map((value) => (
|
{[200, 400, 600, 800, 1000].map((value) => (
|
||||||
<Button key={value}>{value}</Button>
|
<Button key={value}>{value}</Button>
|
||||||
))}
|
))}
|
||||||
</>
|
</Fragment>
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Container>
|
</Container>
|
||||||
|
@ -2,7 +2,7 @@ import { io } from "socket.io-client";
|
|||||||
import store from "./store";
|
import store from "./store";
|
||||||
import { setRoomCode } from "./store/socketSlice";
|
import { setRoomCode } from "./store/socketSlice";
|
||||||
import { addContestant } from "./store/displaySlice";
|
import { addContestant } from "./store/displaySlice";
|
||||||
import { addCategory } from "./store/cluesSlice";
|
import { setCategories } from "./store/cluesSlice";
|
||||||
|
|
||||||
export const socket = io(`${window.location.hostname}:5000`);
|
export const socket = io(`${window.location.hostname}:5000`);
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ export const setup = () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
socket.on("categories", (data: string[]) =>
|
socket.on("categories", (data: Record<string, Clue>) => {
|
||||||
data.forEach((category) => store.dispatch(addCategory(category)))
|
store.dispatch(setCategories(data));
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@ interface Category {
|
|||||||
interface Clue {
|
interface Clue {
|
||||||
value: number;
|
value: number;
|
||||||
question: string;
|
question: string;
|
||||||
answer?: string;
|
answer: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: Category[] = [];
|
const initialState: Category[] = [];
|
||||||
@ -18,12 +18,15 @@ export const cluesSlice = createSlice({
|
|||||||
name: "clues",
|
name: "clues",
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
addCategory: (state, { payload }: PayloadAction<string>) =>
|
setCategories: (state, action: PayloadAction<Record<string, Clue[]>>) =>
|
||||||
(state = [...state, { name: payload, clues: [] }]),
|
Object.entries(action.payload).map(([name, clues]) => ({
|
||||||
|
name,
|
||||||
|
clues,
|
||||||
|
})),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { addCategory } = cluesSlice.actions;
|
export const { setCategories } = cluesSlice.actions;
|
||||||
export const selectCategories = (state: RootState) => state.clues;
|
export const selectCategories = (state: RootState) => state.clues;
|
||||||
|
|
||||||
export default cluesSlice.reducer;
|
export default cluesSlice.reducer;
|
||||||
|
Loading…
Reference in New Issue
Block a user