Skip to content

Commit

Permalink
feat: kill toast upon draw + pop up card drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraviolet10 authored and norswap committed Feb 26, 2024
1 parent b63a0ec commit 2e4d0fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/webapp/src/components/hand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const Hand = ({

return (
<div
className={`${className} py-4 flex flex-row items-center justify-evenly bottom-0 w-[95%] space-x-2`}
className={`${className} ${
isLastCardGlowing ? "translate-y-0" : null
} py-4 flex flex-row items-center justify-evenly bottom-0 w-[95%] space-x-2`}
ref={setNodeRef}
onMouseEnter={() => {
setIsFocused(true)
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/hooks/useScrollBox.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useEffect, useCallback, RefObject } from "react"
import throttle from "lodash/throttle"
import { toast } from "sonner"

const timing = (1 / 60) * 1000

Expand Down Expand Up @@ -106,6 +107,8 @@ function useScrollBox(scrollRef: RefObject<HTMLDivElement>, cards: readonly bigi

const triggerLastCardGlow = useCallback(() => {
setIsLastCardGlowing(true)
// dismiss the toast displaying draw status
toast.dismiss("DRAW_CARD_TOAST")
setTimeout(() => {
setIsLastCardGlowing(false)
}, 2500)
Expand Down
10 changes: 7 additions & 3 deletions packages/webapp/src/pages/play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const Play: FablePage = ({ isHydrated }) => {
// Automatically submit the card draw transaction when it's our turn
if (gameData && currentPlayer(gameData) === playerAddress && !cantDrawCard) {
toast.promise(doDrawCard, {
id: "DRAW_CARD_TOAST",
loading: "Your Turn - Drawing Card...",
success: () => {
if (showDrawButton) setShowDrawButton(false)
Expand All @@ -129,7 +130,8 @@ const Play: FablePage = ({ isHydrated }) => {
error: () => {
if(!showDrawButton) setShowDrawButton(true)
return null as any // don't trigger the toast
}
},
dismissible: true
})
}
}, [cancellationHandler, cantDrawCard, gameID, playerAddress, doDrawCard, gameData, showDrawButton])
Expand Down Expand Up @@ -223,7 +225,7 @@ const Play: FablePage = ({ isHydrated }) => {
cards={playerHand as readonly bigint[]}
setLoading={setLoading}
cancellationHandler={cancellationHandler}
className="absolute left-0 right-0 mx-auto z-[100] translate-y-1/2 transition-all duration-500 rounded-xl ease-in-out hover:translate-y-0"
className={`absolute left-0 right-0 mx-auto z-[100] translate-y-1/2 transition-all duration-500 rounded-xl ease-in-out hover:translate-y-0`}
/>
<div className="grid-col-1 relative mx-6 mb-6 grid grow grid-rows-[6]">
<PlayerBoard
Expand All @@ -239,11 +241,13 @@ const Play: FablePage = ({ isHydrated }) => {
className="absolute right-96 bottom-1/2 z-50 !translate-y-1/2 rounded-lg border-[.1rem] border-base-300 font-mono hover:scale-105"
onClick={() => {
toast.promise(doDrawCard, {
id: "DRAW_CARD_TOAST",
loading: "Drawing Card...",
success: () => {
if (showDrawButton) setShowDrawButton(false)
return "Card Drawn Successfully!"
}
},
dismissible: true
})
}}
>
Expand Down

0 comments on commit 2e4d0fe

Please sign in to comment.