Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
feat: modify game play functions
Browse files Browse the repository at this point in the history
  • Loading branch information
izaakwalz committed Jul 6, 2024
1 parent 8d1da02 commit 50564a5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
6 changes: 5 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
eslint: {
ignoreDuringBuilds: true
}
};

export default nextConfig;
43 changes: 32 additions & 11 deletions src/app/(dashboard)/home/_components/live-game-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,30 @@ type GameType = 0 | 1;

export default function LiveGamePlay({ type }: { type: GameType }) {
const [openGameSheet, setOpenGameSheet] = useState<boolean>(false);

const [propertyDisplay, setPropertyDisplay] = useState(null);
const [display, setDisplay] = useState<'start' | 'play' | 'success' | 'fail'>('start');

function closeGameSheet() {
setOpenGameSheet(false);
}

const game: IGamePlaySection = {
start: <StartGame type={type} setDisplay={setDisplay} close={closeGameSheet} />,
start: (
<StartGame
type={type}
setDisplay={setDisplay}
close={closeGameSheet}
setPropertyDisplay={setPropertyDisplay}
/>
),
play: <GameMode setDisplay={setDisplay} close={closeGameSheet} />,
success: <GuessPass close={closeGameSheet} />,
fail: <GuessFail close={closeGameSheet} />
};

console.log(propertyDisplay);

return (
<Sheet open={openGameSheet} onOpenChange={setOpenGameSheet}>
<SheetTrigger asChild>
Expand Down Expand Up @@ -67,24 +78,34 @@ export default function LiveGamePlay({ type }: { type: GameType }) {
interface GameProps {
type: GameType;
setDisplay: Dispatch<SetStateAction<'start' | 'play' | 'success' | 'fail'>>;
setPropertyDisplay: Dispatch<SetStateAction<any>>;
close: () => void;
}

function StartGame({ type, close, setDisplay }: GameProps) {
function StartGame({ type, close, setDisplay, setPropertyDisplay }: GameProps) {
const { address } = useSubstrateContext();
const [isPending, startTransition] = useTransition();

function onPlay() {
startTransition(async () => {
await playGame(type, address);
setDisplay('play');
});
const [isLoading, setIsLoading] = useState(false);

// const [isPending, startTransition] = useTransition();

async function onPlay() {
try {
setIsLoading(true);
await playGame(type, address, data => {
setPropertyDisplay(data);
setDisplay('play');
});
setIsLoading(false);
} catch (error) {
console.log(error);
setIsLoading(false);
}
}

return (
<div className="space-y-[44px]">
<div className="flex items-center justify-between">
<Button variant={'text'} onClick={close} className="p-0" disabled={isPending}>
<Button variant={'text'} onClick={close} className="p-0" disabled={isLoading}>
<Icons.CaretLeft className="size-6" />
Return
</Button>
Expand All @@ -97,7 +118,7 @@ function StartGame({ type, close, setDisplay }: GameProps) {
<Button
className="size-[250px] rounded-full p-10 font-heading text-[2.84569rem] font-bold shadow-game"
onClick={onPlay}
disabled={isPending}
disabled={isLoading}
>
Start <br /> Game
</Button>
Expand Down

0 comments on commit 50564a5

Please sign in to comment.