Skip to content

Commit

Permalink
Varaman: change game over modal varaman
Browse files Browse the repository at this point in the history
  • Loading branch information
faizov committed Jun 19, 2024
1 parent c7e8368 commit ffd1cf2
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 56 deletions.
1 change: 1 addition & 0 deletions frontend/apps/vara-man/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@polkadot/types": "10.11.2",
"@polkadot/util": "12.3.2",
"@polkadot/wasm-crypto": "7.2.2",
"@radix-ui/react-dialog": "1.0.5",
"@radix-ui/react-scroll-area": "1.0.3",
"@radix-ui/react-tabs": "1.0.3",
"@testing-library/jest-dom": "5.16.4",
Expand Down
34 changes: 34 additions & 0 deletions frontend/apps/vara-man/src/components/ui/modal/modal2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as Dialog from '@radix-ui/react-dialog';
import { ReactNode } from 'react';
// import { CrossIcon } from '@/assets/images';

export function Modal({
open,
onOpenChange,
children,
}: {
open?: boolean;
onOpenChange?: (open: boolean) => void;
children: ReactNode;
}) {
return (
<Dialog.Root open={open} onOpenChange={onOpenChange}>
{children}
</Dialog.Root>
);
}

function ModalContent({ children }: { children: ReactNode }) {
return (
<Dialog.Portal>
<Dialog.Overlay className="fixed inset-0 bg-black/50 data-[state=closed]:animate-[dialog-overlay-hide_200ms] data-[state=open]:animate-[dialog-overlay-show_200ms] backdrop-blur-lg" />
<Dialog.Content className="fixed left-1/2 top-1/2 w-full max-w-md -translate-x-1/2 -translate-y-1/2 rounded-md bg-white p-8 text-gray-900 shadow data-[state=closed]:animate-[dialog-content-hide_200ms] data-[state=open]:animate-[dialog-content-show_200ms]">
{children}
</Dialog.Content>
</Dialog.Portal>
);
}

Modal.Button = Dialog.Trigger;
Modal.Close = Dialog.Close;
Modal.Content = ModalContent;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAtom } from 'jotai';

import { Button, Modal } from '@/components';
import { Button } from '@/components';
import { Icons } from '@/components/ui/icons';
import { useGame } from '@/app/context/ctx-game';

Expand All @@ -10,6 +10,7 @@ import { useNavigate, useSearchParams } from 'react-router-dom';
import { IGameLevel } from '@/app/types/game';
import { GAME_OVER, COINS } from '@/feature/game/consts';
import { calculatePoints } from '@/feature/game/utils/calculatePoints';
import { Modal } from '@/components/ui/modal/modal2';

export const GameOverModal = ({ restartGame }: any) => {
const [searchParams] = useSearchParams();
Expand All @@ -33,34 +34,37 @@ export const GameOverModal = ({ restartGame }: any) => {

return (
<div>
<Modal onClose={() => null}>
<div className="flex flex-col justify-center gap-5 text-center">
<div>
<h3 className="text-3xl font-semibold">Game Over</h3>
<p className="text-[#555756] mt-2">You're doing great, keep it up!</p>
<Modal open={true}>
<Modal.Content>
<div className="flex flex-col justify-center gap-5 text-center">
<div>
<h3 className="text-3xl font-semibold">Game Over</h3>
<p className="text-[#555756] mt-2">You're doing great, keep it up!</p>
</div>
<div className="bg-[#F7F9FA] w-full p-5 font-medium flex gap-5 justify-center items-center">
Your score:
<span className="flex items-center gap-2 font-semibold">
<Icons.statsCoins />
{score}
</span>
</div>
<div className="flex justify-evenly gap-6">
<Button
className="w-full"
variant="gray"
onClick={() => {
onResetGame();
navigate('/');
}}
disabled={isPending}>
Close
</Button>
<Button className="w-full" onClick={() => onResetGame()} isLoading={isPending} disabled={isPending}>
Play again
</Button>
</div>
</div>
<div className="bg-[#F7F9FA] w-full p-5 font-medium flex gap-5 justify-center items-center">
Your score:
<span className="flex items-center gap-2 font-semibold">
<Icons.statsCoins />
{score}
</span>
</div>
<div className="flex justify-evenly">
<Button
variant="gray"
onClick={() => {
onResetGame();
navigate('/');
}}
disabled={isPending}>
Close
</Button>
<Button onClick={() => onResetGame()} isLoading={isPending} disabled={isPending}>
Play again
</Button>
</div>
</div>
</Modal.Content>
</Modal>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@


import { Modal } from '@/components';
import { Modal } from '@/components/ui/modal/modal2';
import { COINS } from '@/feature/game/consts';
import { Button } from '@gear-js/vara-ui';
import { useAtom } from 'jotai';

type GamePlayAgainModalProps = {
setIsOpenPlayAgain: (_: boolean) => void
restartGame: () => void
}
setIsOpenPlayAgain: (_: boolean) => void;
restartGame: () => void;
};

export const GamePlayAgainModal = ({ setIsOpenPlayAgain, restartGame }: GamePlayAgainModalProps) => {
const [, setCoins] = useAtom(COINS)
const [, setCoins] = useAtom(COINS);

return (
<Modal onClose={() => null}>
<div className='flex flex-col items-center'>
<h2 className='typo-h2' >Game over</h2>
<div className="flex flex-col gap-5 mt-5">
<p className="text-[#555756]">
You're doing great, keep it up!
</p>
<div className="flex gap-10">
<Button text="Play Again" className="w-full" onClick={() => {
setIsOpenPlayAgain(false)
restartGame()
setCoins({ gold: 0, silver: 0 })
}} />
</div>
</div>
</div>
</Modal>
)
}
return (
<Modal open={true}>
<Modal.Content>
<div className="flex flex-col items-center">
<h2 className="typo-h2">Game over</h2>
<div className="flex flex-col gap-5 mt-5">
<p className="text-[#555756]">You're doing great, keep it up!</p>
<div className="flex gap-10">
<Button
text="Play Again"
className="w-full"
onClick={() => {
setIsOpenPlayAgain(false);
restartGame();
setCoins({ gold: 0, silver: 0 });
}}
/>
</div>
</div>
</div>
</Modal.Content>
</Modal>
);
};
3 changes: 2 additions & 1 deletion frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5384,7 +5384,7 @@ __metadata:
languageName: node
linkType: hard

"@radix-ui/react-dialog@npm:^1.0.5":
"@radix-ui/react-dialog@npm:1.0.5, @radix-ui/react-dialog@npm:^1.0.5":
version: 1.0.5
resolution: "@radix-ui/react-dialog@npm:1.0.5"
dependencies:
Expand Down Expand Up @@ -24212,6 +24212,7 @@ __metadata:
"@polkadot/types": "npm:10.11.2"
"@polkadot/util": "npm:12.3.2"
"@polkadot/wasm-crypto": "npm:7.2.2"
"@radix-ui/react-dialog": "npm:1.0.5"
"@radix-ui/react-scroll-area": "npm:1.0.3"
"@radix-ui/react-tabs": "npm:1.0.3"
"@testing-library/jest-dom": "npm:5.16.4"
Expand Down

0 comments on commit ffd1cf2

Please sign in to comment.