From aeb1af0393d255d032e9c7b6ebb3979324765ba2 Mon Sep 17 00:00:00 2001 From: Pathe SENE Date: Thu, 2 Nov 2023 11:57:33 +0000 Subject: [PATCH] fix: change data access methods from json response --- baloot/src/App.js | 1 + baloot/src/components/TakesGroupView.js | 4 ++-- baloot/src/utils/messageStore.js | 13 +++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/baloot/src/App.js b/baloot/src/App.js index 33f2ea9..64759bd 100644 --- a/baloot/src/App.js +++ b/baloot/src/App.js @@ -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" }), ); diff --git a/baloot/src/components/TakesGroupView.js b/baloot/src/components/TakesGroupView.js index 9c205c7..f7133ff 100644 --- a/baloot/src/components/TakesGroupView.js +++ b/baloot/src/components/TakesGroupView.js @@ -6,8 +6,8 @@ function TakesGroupView({ onClickHandler, playerID, takes }) { {takes.map((t) => { return ( - ); })} diff --git a/baloot/src/utils/messageStore.js b/baloot/src/utils/messageStore.js index 5908884..a3c4d79 100644 --- a/baloot/src/utils/messageStore.js +++ b/baloot/src/utils/messageStore.js @@ -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");