Skip to content

Commit

Permalink
Merge pull request #73 from daithihearn/enhancements
Browse files Browse the repository at this point in the history
Minor enhancements
  • Loading branch information
daithihearn authored Jan 14, 2023
2 parents 0d1d5e7 + 38fe390 commit cb4e65b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 52 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
"react-router": "^6.6.2",
"react-router-config": "^5.1.1",
"react-router-dom": "^6.6.2",
"react-simple-pull-to-refresh": "^1.3.3",
"react-stomp-hooks": "2.1.0",
"react-viewer": "^3.2.2",
"reactstrap": "9.1.5",
"semantic-ui-css": "^2.4.1",
"simple-line-icons": "^2.5.5",
"styled-components": "^5.2.3",
"typescript": "^4.9.4",
"use-sound": "^4.0.1",
"uuid-random": "^1.3.2"
},
"devDependencies": {
Expand Down
57 changes: 25 additions & 32 deletions src/components/Game/WebsocketManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,7 @@ import { Actions, BuyCardsEvent } from "../../model/Events"
import { useSnackbar } from "notistack"
import { clearSelectedCards, updateMyCards } from "../../caches/MyCardsSlice"
import { clearAutoPlay } from "../../caches/AutoPlaySlice"

// const shuffleSound = new Audio("../../assets/sounds/shuffle.ogg")
// const playCardSound = new Audio("../../assets/sounds/play_card.ogg")
// const alertSound = new Audio("../../assets/sounds/alert.ogg")
// const callSound = new Audio("../../assets/sounds/call.ogg")
// const passSound = new Audio("../../assets/sounds/pass.ogg")

// const playShuffleSound = () => {
// shuffleSound.play().catch(() => console.error("Error playing shuffle sound!"))
// }

// const playPlayCardSound = () => {
// playCardSound
// .play()
// .catch(() => console.error("Error playing play card sound!"))
// }

// const playAlertSound = () => {
// alertSound.play().catch(() => console.error("Error playing alert sound!"))
// }

// const playCallSound = () => {
// callSound.play().catch(() => console.error("Error playing call sound!"))
// }

// const playPassSound = () => {
// passSound.play().catch(() => console.error("Error playing pass sound!"))
// }
import useSound from "use-sound"

interface ActionEvent {
type: Actions
Expand All @@ -47,6 +20,26 @@ interface ActionEvent {
const WebsocketHandler = () => {
const dispatch = useAppDispatch()

const [shuffleSound] = useSound("../../assets/sounds/shuffle.ogg", {
volume: 0.25,
})

const [playCardSound] = useSound("../../assets/sounds/play_card.ogg", {
volume: 0.25,
})

// const [alertSound] = useSound("../../assets/sounds/alert.ogg", {
// volume: 0.25,
// })

const [callSound] = useSound("../../assets/sounds/call.ogg", {
volume: 0.25,
})

const [passSound] = useSound("../../assets/sounds/pass.ogg", {
volume: 0.25,
})

const playerProfiles = useAppSelector(getPlayerProfiles)
const { enqueueSnackbar } = useSnackbar()

Expand Down Expand Up @@ -88,14 +81,14 @@ const WebsocketHandler = () => {
(type: Actions, payload: unknown) => {
switch (type) {
case "DEAL":
// playShuffleSound()
shuffleSound()
reloadCards(payload)
break
case "CHOOSE_FROM_DUMMY":
case "BUY_CARDS":
case "LAST_CARD_PLAYED":
case "CARD_PLAYED":
// playPlayCardSound()
playCardSound()
reloadCards(payload)
break
case "REPLAY":
Expand All @@ -120,11 +113,11 @@ const WebsocketHandler = () => {
reloadCards(payload)
break
case "CALL":
// playCallSound()
callSound()
reloadCards(payload)
break
case "PASS":
// playPassSound()
passSound()
reloadCards(payload)
break
}
Expand Down
27 changes: 14 additions & 13 deletions src/components/MyGames/MyGames.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ const MyGames = () => {
}

const columns: TableColumn<Game>[] = [
{
cell: (row) => (
<Link to={`/game/${row.id}`}>
<Button
type="button"
color={parsePlayButtonColour(row, myProfile.id!)}
>
{parsePlayButtonLabel(row, myProfile.id!)}
</Button>
</Link>
),
center: true,
},
{ name: "Name", selector: (row) => row.name, sortable: true },
{
name: "Date",
Expand All @@ -103,19 +116,7 @@ const MyGames = () => {
),
center: true,
},
{
cell: (row) => (
<Link to={`/game/${row.id}`}>
<Button
type="button"
color={parsePlayButtonColour(row, myProfile.id!)}
>
{parsePlayButtonLabel(row, myProfile.id!)}
</Button>
</Link>
),
center: true,
},

{
cell: (row) => (
<Button
Expand Down
14 changes: 11 additions & 3 deletions src/pages/Game/Game.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect } from "react"
import React, { useCallback, useEffect } from "react"
import GameWrapper from "../../components/Game/GameWrapper"
import GameOver from "../../components/Game/GameOver"
import GameService from "../../services/GameService"
import PullToRefresh from "react-simple-pull-to-refresh"

import { withAuthenticationRequired } from "@auth0/auth0-react"

Expand Down Expand Up @@ -34,8 +35,15 @@ const Game = () => {
}
}, [id])

const handleRefresh = useCallback(async () => {
if (id)
await dispatch(GameService.refreshGameState(id)).catch((e: Error) =>
enqueueSnackbar(e.message, { variant: "error" })
)
}, [id])

return (
<>
<PullToRefresh onRefresh={handleRefresh}>
<div className="app carpet">
<div className="game_wrap">
<div className="game_container">
Expand All @@ -44,7 +52,7 @@ const Game = () => {
</div>
</div>
</div>
</>
</PullToRefresh>
)
}

Expand Down
27 changes: 23 additions & 4 deletions src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import React, { useCallback } from "react"

import { Card, CardGroup, CardHeader } from "reactstrap"

Expand All @@ -7,15 +7,34 @@ import StartNewGame from "../../components/StartNewGame/StartNewGame"
import MyGames from "../../components/MyGames/MyGames"
import GameStats from "../../components/GameStats/GameStats"
import { withAuthenticationRequired } from "@auth0/auth0-react"
import PullToRefresh from "react-simple-pull-to-refresh"

import { useAppSelector } from "../../caches/hooks"
import { useAppDispatch, useAppSelector } from "../../caches/hooks"
import { getMyProfile } from "../../caches/MyProfileSlice"
import GameService from "../../services/GameService"
import { useSnackbar } from "notistack"
import StatsService from "../../services/StatsService"

const Home = () => {
const dispatch = useAppDispatch()
const myProfile = useAppSelector(getMyProfile)
const { enqueueSnackbar } = useSnackbar()

const handleRefresh = useCallback(async () => {
if (myProfile.isAdmin)
dispatch(GameService.getAllPlayers()).catch((e: Error) =>
enqueueSnackbar(e.message, { variant: "error" })
)

dispatch(GameService.getAll())

dispatch(StatsService.gameStatsForPlayer()).catch((e: Error) =>
enqueueSnackbar(e.message, { variant: "error" })
)
}, [])

return (
<>
<PullToRefresh onRefresh={handleRefresh}>
<div className="app carpet">
<DataLoader />
<div className="game_wrap">
Expand Down Expand Up @@ -47,7 +66,7 @@ const Home = () => {
</div>
</div>
</div>
</>
</PullToRefresh>
)
}

Expand Down

0 comments on commit cb4e65b

Please sign in to comment.