Skip to content

Commit

Permalink
Merge pull request #93 from Ashutoshbind15/main
Browse files Browse the repository at this point in the history
add the functionality to move to the next map on victory
  • Loading branch information
webdevcody authored Oct 18, 2024
2 parents 436f95e + f253f68 commit 036a89d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/play/[level]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Link from "next/link";
import { ChevronLeftIcon } from "@radix-ui/react-icons";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import TestMode from "./test-mode";
import { useRouter } from "next/navigation";

export default function PlayLevelPage({
params,
Expand Down Expand Up @@ -42,6 +43,9 @@ export default function PlayLevelPage({
mapId: map?._id,
});

const lastLevel = useQuery(api.maps.lastLevel);
const router = useRouter();

if (!map) {
return (
<div className="container mx-auto min-h-screen flex flex-col items-center py-12 pb-24 gap-8">
Expand Down Expand Up @@ -242,9 +246,27 @@ export default function PlayLevelPage({
</Button>
</>
) : (
<Button onClick={handleRetryClicked} className="h-10">
Retry
</Button>
<div className="flex items-center gap-x-3">
<Button onClick={handleRetryClicked} className="h-10">
Retry
</Button>
{gameResult && gameResult === "WON" ? (
<Button
onClick={() => {
if (lastLevel && level + 1 <= lastLevel) {
router.push(`/play/${level + 1}`);
} else {
router.push("/play");
}
}}
className="h-10"
>
{lastLevel && level + 1 <= lastLevel
? "Next Night"
: "Back to Night Selection"}
</Button>
) : null}
</div>
)}
</div>

Expand Down
11 changes: 11 additions & 0 deletions convex/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,14 @@ export const testAIModel = action({
};
},
});

export const lastLevel = query({
handler: async (ctx) => {
const lastMap = await ctx.db
.query("maps")
.withIndex("by_level")
.order("desc")
.first();
return lastMap?.level ?? 0;
},
});

0 comments on commit 036a89d

Please sign in to comment.