Skip to content

Commit

Permalink
fix: change data access methods from json response
Browse files Browse the repository at this point in the history
  • Loading branch information
PapePathe committed Nov 2, 2023
1 parent c7aa932 commit aeb1af0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions baloot/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function App() {
}, [dragItem, dragOverItem, playingCards, setPlayingCards]);
const handleClickSendMessage = useCallback(
(take, pid) => {
console.log(take, pid);
sendMessage(
JSON.stringify({ player_id: `${pid}`, gametake: take, id: "2" }),
);
Expand Down
4 changes: 2 additions & 2 deletions baloot/src/components/TakesGroupView.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function TakesGroupView({ onClickHandler, playerID, takes }) {
<ButtonGroup size="sm" isAttached variant="outline" spacing={1}>
{takes.map((t) => {
return (
<Button onClick={(e) => onClickHandler(t.Name, playerID)}>
{t.Name}
<Button onClick={(e) => onClickHandler(t.name, playerID)}>
{t.name}
</Button>
);
})}
Expand Down
13 changes: 7 additions & 6 deletions baloot/src/utils/messageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@ const messageStore = (
setCards,
setTakes,
) => {
console.log(lastJsonMessage);
if (lastJsonMessage !== null) {
if (lastJsonMessage !== {}) {
switch (lastJsonMessage.id) {
case 1:
setPlayerID((prev) => lastJsonMessage.player.id);
setCards((prev) => lastJsonMessage.player.hand.Cards);
setTakes((prev) => lastJsonMessage.available_takes);
setCards((prev) => lastJsonMessage.player.hand.cards);
setTakes((prev) => lastJsonMessage.availableTakes);
break;
case 2:
setCards((prev) => []);
setTakes((prev) => []);
setPlayerTakes((prev) => []);
setPlayingCards((prev) => lastJsonMessage.player.playing_hand.Cards);
setGametake((prev) => lastJsonMessage.gametake.Name);
setPlayingCards((prev) => lastJsonMessage.player.playingHand.cards);
setGametake((prev) => lastJsonMessage.gametake.name);
break;
case 5:
setPlayerTakes((prev) => [...prev, lastJsonMessage.take]);
setTakes((prev) => lastJsonMessage.available_takes);
setTakes((prev) => lastJsonMessage.availableTakes);
break;
case 6:
setDeck((prev) => lastJsonMessage.deck);
setPlayingCards((prev) => lastJsonMessage.player.playing_hand.Cards);
setPlayingCards((prev) => lastJsonMessage.player.playingHand.cards);
break;
default:
throw new Error("Error message id not found");
Expand Down

0 comments on commit aeb1af0

Please sign in to comment.