Skip to content

Commit

Permalink
Merge pull request #73 from z-korp/submenu-mobile
Browse files Browse the repository at this point in the history
Submenu mobile
  • Loading branch information
Matth26 authored Nov 29, 2024
2 parents 022946a + 2faed68 commit 248f2eb
Show file tree
Hide file tree
Showing 9 changed files with 788 additions and 583 deletions.
3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"@dojoengine/state": "1.0.0",
"@dojoengine/torii-client": "1.0.0",
"@dojoengine/utils": "1.0.0",
"@egjs/flicking-plugins": "^4.7.1",
"@egjs/react-flicking": "^4.11.4",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@fortawesome/fontawesome-svg-core": "^6.6.0",
Expand Down Expand Up @@ -84,6 +86,7 @@
"rxjs": "^7.8.1",
"sonner": "^1.5.0",
"starknet": "6.11.0",
"swiper": "^11.1.15",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"tsparticles": "^3.5.0",
Expand Down
1,127 changes: 557 additions & 570 deletions client/pnpm-lock.yaml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions client/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,14 @@ body[style*="pointer-events: none"] #controller {
body[style*="pointer-events: none"] #controller * {
pointer-events: auto !important;
}

.swiper {
width: 280px;
height: 400px;
}

.swiper-slide {
display: flex;
align-items: center;
justify-content: center;
}
2 changes: 1 addition & 1 deletion client/src/ui/components/GameModeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const GameModeCard: React.FC<GameModeCardProps> = ({
}, [mode]);

return (
<Card className="w-full max-w-sm bg-gray-900 text-white border-0 relative font-semibold md:font-normal">
<Card className="w-full h-full max-w-sm bg-gray-900 text-white border-0 relative font-semibold md:font-normal">
{isMdOrLarger &&
(mode === ModeType.Daily || mode === ModeType.Normal) && (
<div className="absolute top-0 bg-white text-black text-xs px-2 py-1 rounded-br-lg rounded-tl-xl">
Expand Down
146 changes: 146 additions & 0 deletions client/src/ui/components/GameModeCardMobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import React, { useMemo } from "react";
import { Hourglass, Trophy, Coins, Zap, HelpCircle } from "lucide-react";
import {
Card,
CardContent,
CardFooter,
CardHeader,
CardTitle,
} from "../elements/card";
import { ModeType } from "@/dojo/game/types/mode";
import { useSettings } from "@/hooks/useSettings";
import useTournament from "@/hooks/useTournament";
import { Start } from "../actions/Start";
import TournamentTimer from "./TournamentTimer";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "../elements/tooltip";
import { useMediaQuery } from "react-responsive";
import { formatPrize } from "@/utils/price";
import NftImage from "./ImageNFTZkube";

const { VITE_PUBLIC_GAME_TOKEN_SYMBOL } = import.meta.env;

interface GameModeCardProps {
mode: ModeType;
handleGameMode: () => void;
}

const GameModeCardMobile: React.FC<GameModeCardProps> = ({
mode,
handleGameMode,
}) => {
const { settings } = useSettings();

const { endTimestamp, tournament } = useTournament(mode);

const potentialWin = useMemo(() => {
if (!tournament) return formatPrize(0n, VITE_PUBLIC_GAME_TOKEN_SYMBOL);
return formatPrize(tournament.prize, VITE_PUBLIC_GAME_TOKEN_SYMBOL);
}, [tournament]);

const cost = useMemo(() => {
if (!settings) return formatPrize(0n, VITE_PUBLIC_GAME_TOKEN_SYMBOL);
const weiCost = settings.game_price;
return formatPrize(weiCost, VITE_PUBLIC_GAME_TOKEN_SYMBOL);
}, [settings]);

const difficultyRule = useMemo(() => {
switch (mode) {
case ModeType.Daily:
return {
name: "Pro Mode",
description:
"A fixed high-difficulty challenge that tests your skills at their peak.",
};
case ModeType.Normal:
return {
name: "Escalation Mode",
description:
"Difficulty increases over time, pushing you to adapt and improve.",
};
case ModeType.Free:
return {
name: "Escalation Mode",
description:
"Difficulty increases over time, pushing you to adapt and improve.",
};
default:
return {
name: "Normal Mode",
description:
"A standard mode with a fixed difficulty level for consistent play.",
};
}
}, [mode]);

return (
<Card className="w-full h-full bg-gray-800 text-white border-2 border-white">
<CardHeader className="pt-4 pb-10 md:pb-4">
<CardTitle className="text-2xl md:text-2xl font-bold text-center">
{mode}
</CardTitle>
</CardHeader>
<CardContent className="space-y-2 text-sm md:text-base pb-4">
<div className="flex items-center space-x-2 gap-2">
<Coins className="h-5 w-5 flex-shrink-0" />
<div className="flex-grow flex justify-between items-center">
<span className="font-semibold">Cost</span>
<div className="text-slate-300">
{mode === ModeType.Free ? (
"Free"
) : (
<div className="flex items-center gap-3 -mr-1">
{cost.withImage} <p>or</p>
<div className="flex items-center gap-1">
<p>1</p>
<NftImage />
</div>
</div>
)}
</div>
</div>
</div>

<div className="flex items-center space-x-2 gap-2">
<Zap className="h-5 w-5 flex-shrink-0" />
<div className="flex-grow flex justify-between items-center">
<span className="font-semibold">Difficulty</span>
<span className="flex items-center text-slate-300 relative">
{difficultyRule.name}
</span>
</div>
</div>

{(mode === ModeType.Daily || mode === ModeType.Normal) && (
<>
<div className="flex items-center space-x-2 w-full gap-2">
<Hourglass className="h-5 w-5 flex-shrink-0" />
<div className="flex-grow flex justify-between items-center">
<span className="font-semibold">Ends in</span>
<div className="text-slate-300">
<TournamentTimer mode={mode} endTimestamp={endTimestamp} />
</div>
</div>
</div>
<div className="flex items-center space-x-2 w-full gap-2">
<Trophy className="h-5 w-5 flex-shrink-0" />
<div className="flex-grow flex justify-between items-center">
<span className="font-semibold">Prize Pool</span>
{potentialWin.withImage}
</div>
</div>
</>
)}
</CardContent>
<CardFooter className="mt-8">
<Start mode={mode} handleGameMode={handleGameMode} />
</CardFooter>
</Card>
);
};

export default GameModeCardMobile;
2 changes: 1 addition & 1 deletion client/src/ui/components/HeaderNftBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const HeaderNftBalance = React.memo(() => {

if (account) {
return (
<span className="text-xs font-semibold md:font-normal flex items-center ">
<span className="text-xs font-semibold md:font-normal flex items-center">
{`${balance}`} <NftImage />
</span>
);
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/components/MobileHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const MobileHeader = ({ onStartTutorial }: MobileHeaderProps) => {
{!!player && account ? (
<div className="flex gap-3 items-center">
<DropdownMenu>
<DropdownMenuTrigger>
<DropdownMenuTrigger asChild>
<Button variant={"outline"}>
<FontAwesomeIcon icon={faCoins} />
</Button>
Expand Down
48 changes: 48 additions & 0 deletions client/src/ui/components/Swipper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Swiper, SwiperSlide } from "swiper/react";

import "swiper/css";
import "swiper/css/effect-cards";

import "@/index.css";

import { EffectCards } from "swiper/modules";
import { ModeType } from "@/dojo/game/types/mode";
import GameModeCardMobile from "./GameModeCardMobile";

interface SwiperProps {
setIsGameOn: (isOn: string) => void;
}

export default function Swipper({ setIsGameOn }: SwiperProps) {
return (
<>
<Swiper
effect={"cards"}
grabCursor={true}
modules={[EffectCards]}
className="mySwiper"
initialSlide={1}
>
<SwiperSlide>
<GameModeCardMobile
mode={ModeType.Free}
handleGameMode={() => setIsGameOn("isOn")}
/>
</SwiperSlide>

<SwiperSlide>
<GameModeCardMobile
mode={ModeType.Daily}
handleGameMode={() => setIsGameOn("isOn")}
/>
</SwiperSlide>
<SwiperSlide>
<GameModeCardMobile
mode={ModeType.Normal}
handleGameMode={() => setIsGameOn("isOn")}
/>
</SwiperSlide>
</Swiper>
</>
);
}
30 changes: 20 additions & 10 deletions client/src/ui/screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ import MaxComboIcon from "../components/MaxComboIcon";
import GameModeCard from "../components/GameModeCard";
import useAccountCustom from "@/hooks/useAccountCustom";
import { useMediaQuery } from "react-responsive";
import { Start } from "../actions/Start";
import { ChevronLeft } from "lucide-react";
import CollectiveTreasureChest from "../components/TreasureChest";
import GameOverDialog from "../components/GameOverDialog";
import useViewport from "@/hooks/useViewport";
import { TweetPreview } from "../components/TweetPreview";
import { useGrid } from "@/hooks/useGrid";
import Tutorial from "../components/Tutorial/Tutorial";
import Swipper from "../components/Swipper";
import HeaderBalance from "../components/HeaderBalance";

export const Home = () => {
useViewport();
Expand Down Expand Up @@ -231,15 +232,24 @@ export const Home = () => {

const renderMobileView = () => (
<div className="flex flex-col w-full gap-4 px-4 mt-4">
<Start mode={ModeType.Free} handleGameMode={handlePlay} />
<Dialog>
<DialogTrigger asChild>
<Button
className="w-full bg-primary text-white text-lg py-6 border-4 shadow-lg bg-sky-900 font-sans rounded-none"
variant="brutal"
>
Play !
</Button>
</DialogTrigger>
<DialogContent className="w-[95%] flex flex-col justify-center p-8">
<DialogHeader className="flex flex-row gap-3 items-center justify-center w-full space-y-0">
<HeaderBalance />
</DialogHeader>

<Swipper setIsGameOn={() => setIsGameOn("isOn")}></Swipper>
</DialogContent>
</Dialog>

<Button
variant={"brutal"}
onClick={handleTournaments}
className="w-full bg-primary text-secondary text-lg py-6 border-4 shadow-lg bg-sky-200 font-sans rounded-none"
>
<p>Tournaments</p>
</Button>
<Button
variant={"brutal"}
onClick={() => setChestIsOpen(true)}
Expand All @@ -261,7 +271,7 @@ export const Home = () => {
<Dialog open={isSigning} modal>
<DialogContent
aria-describedby={undefined}
className="flex flex-col items-center justify-center p-6 "
className="flex flex-col items-center justify-center p-6"
>
<p className="mt-8 mb-7">Aligning the blocks for your signup...</p>
</DialogContent>
Expand Down

0 comments on commit 248f2eb

Please sign in to comment.