Skip to content

Commit

Permalink
Changes room_id and gameName to room_name or roomName
Browse files Browse the repository at this point in the history
  • Loading branch information
MWoodshop committed Oct 20, 2023
1 parent f7fdb43 commit 8c78022
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ function App() {
<Header />
<LandingPage />
</>
}
}
/>
<Route path='/roomID' element={<Story/>}/>
<Route path='/room/:roomName' element={
<Route path='/room/:gameName' element={
<>
<RoomOne />
<Chat />
</>
} />
</Routes>

</div>
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/Chat/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export default function Chat() {
const [allMessages, setAllMessages] = useState([]);
const [subscription, setSubscription] = useState(null);
const [hasNickname, setHasNickname] = useState(false);
const { roomName } = useParams();
const { gameName } = useParams();

useEffect(() => {
const nicknameExist = localStorage.getItem(`nickname_${roomName}`);
const nicknameExist = localStorage.getItem(`nickname_${gameName}`);
if (nicknameExist) {
setNickname(nicknameExist);
setHasNickname(true);
Expand All @@ -23,7 +23,7 @@ export default function Chat() {
'ws://localhost:3000/cable'
);
const newSubscription = cable.subscriptions.create(
{ channel: 'GameChannel', room: roomName },
{ channel: 'GameChannel', game: gameName },
{
received: (data) => {
setAllMessages((allMessages) => [
Expand All @@ -40,7 +40,7 @@ export default function Chat() {
cable.disconnect()
newSubscription.unsubscribe()
}
}, [roomName]);
}, [gameName]);

const handleSubmitMessage = (e) => {
subscription.send({
Expand All @@ -51,7 +51,7 @@ export default function Chat() {
};

const handleNickname = () => {
localStorage.setItem(`nickname_${roomName}`, nickname);
localStorage.setItem(`nickname_${gameName}`, nickname);
setHasNickname(true);
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/Story/Story.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default function Story() {

const startGame = async () => {
try {
const roomName = await fetchGameLink();
navigate(`/room/${roomName.game_name}`);
const gameName = await fetchGameLink();
navigate(`/room/${gameName.room_name}`);
} catch (err) {
console.log(`${err.message}`);
}
Expand Down

0 comments on commit 8c78022

Please sign in to comment.