Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuzuri247 committed Dec 21, 2024
1 parent 4c66d5c commit 96a2404
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 248 deletions.
5 changes: 1 addition & 4 deletions @/components/ui/alert.jsx → @/components/ui/alert.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import * as React from "react";



import * as React from "react"
export function Alert({
children,
className,
Expand Down
11 changes: 3 additions & 8 deletions app/api/games/route.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { NextResponse } from "next/server";
import dbConnect from "../../../lib/dbConnect";
import Games from "../../../model/Games";
Expand All @@ -6,12 +7,7 @@ export async function GET(req) {
await dbConnect();

try {
const { searchParams } = new URL(req.url);
const filter = searchParams.get("filter") || "";
const query = {
category: { $regex: new RegExp(filter, "i") },
};
const gameData = await Games.find(query).lean();
const gameData = await Games.find().lean();

return NextResponse.json(gameData, { status: 200 });
} catch (error) {
Expand All @@ -21,5 +17,4 @@ export async function GET(req) {
{ status: 500 },
);
}
}

}
2 changes: 1 addition & 1 deletion app/auth/error/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useSearchParams } from "next/navigation";
import { Suspense } from "react";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Alert, AlertDescription, AlertTitle } from "../../../@/components/ui/alert";
import { ExclamationTriangleIcon } from "@radix-ui/react-icons";

function ErrorContent() {
Expand Down
90 changes: 53 additions & 37 deletions app/games/page.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,70 @@
import Image from "next/image";
import Link from "next/link";
import { games } from "./data/index";
import Filter from "../../components/Filter";

export default async function page({searchParams}) {

let filterUrl
if(searchParams?.filter){
filterUrl = `${process.env.NEXT_PUBLIC_BASE_URL}/api/games?filter=${searchParams.filter}`
}else{
filterUrl = `${process.env.NEXT_PUBLIC_BASE_URL}/api/games`
export default async function Page({ searchParams }) {
let filterUrl;

if (searchParams?.filter) {
filterUrl = `${process.env.NEXT_PUBLIC_BASE_URL}/api/games?filter=${searchParams.filter}`;
} else {
filterUrl = `${process.env.NEXT_PUBLIC_BASE_URL}/api/games`;
}

const response = await fetch(`${filterUrl}`, {
method: "GET"
});
let gameData = [];
let errorMessage = '';

try {
const response = await fetch(filterUrl, {
method: "GET",
});

const gameData = await response.json()
if (!response.ok) {
throw new Error('Network response was not ok');
}

gameData = await response.json();
} catch (error) {
console.error("Fetch error:", error);
errorMessage = 'Failed to load games. Please try again later.';
}

const filterss = [{
name: 'FPS', value: 'fps'
}, {
name: 'Battle Royale', value: 'battle royale'
},{
name: "None", value: 'none'
}]
const filters = [
{ name: 'FPS', value: 'fps' },
{ name: 'Battle Royale', value: 'battle royale' },
{ name: "None", value: 'none' }
];

return (
<section className="px-[5%] xl:px-[12%] pt-10 pb-20 transition-all">
<div className="text-4xl font-semibold mb-10 flex items-center justify-between">
<div className="text-4xl font-semibold mb-10 flex items-center justify-between">
<h1>Games</h1>
<Filter filters={filterss} containerClasses={`border rounded-2xl`} />
<Filter filters={filters} containerClasses={`border rounded-2xl`} />
</div>

{errorMessage && <p className="text-red-500">{errorMessage}</p>}

<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-5 transition-all">
{gameData.map((game, index) => (
<div key={index} className="grid ">
<Link
href={`/games/${game._id}`}
className="relative h-64 w-full rounded-xl hover:scale-105 transition-all"
>
<Image
src={game.gameBannerPhoto}
alt={game.name}
fill
className="rounded-xl object-cover"
draggable="false"
/>
</Link>
</div>
))}
{Array.isArray(gameData) && gameData.length > 0 ? (
gameData.map((game) => (
<div key={game._id} className="grid">
<Link
href={`/games/${game._id}`}
className="relative h-64 w-full rounded-xl hover:scale-105 transition-all"
>
<Image
src={game.gameBannerPhoto}
alt={game.name}
fill
className="rounded-xl object-cover"
draggable="false"
/>
</Link>
</div>
))
) : (
<p>No games found.</p>
)}
</div>
</section>
);
Expand Down
5 changes: 5 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
eslint: {
ignoreDuringBuilds: true,
},
reactStrictMode: true,
swcMinify: true,
images: {
remotePatterns: [
{
Expand Down
Loading

0 comments on commit 96a2404

Please sign in to comment.