From 8f8b3a5caf0cfcbc81839f765140ceaea606435a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20Akg=C3=BCl?= <s86116@bht-berlin.de> Date: Wed, 24 May 2023 17:58:58 +0200 Subject: [PATCH] fix deployment url 2 --- app/(content)/(gaming)/games/[gameid]/page.tsx | 13 +++++++++++-- components/InfiniteScroll.tsx | 6 +----- lib/utils.ts | 9 --------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/(content)/(gaming)/games/[gameid]/page.tsx b/app/(content)/(gaming)/games/[gameid]/page.tsx index 68c198d..7504036 100644 --- a/app/(content)/(gaming)/games/[gameid]/page.tsx +++ b/app/(content)/(gaming)/games/[gameid]/page.tsx @@ -10,8 +10,17 @@ export default async function GameDetail({ params }: { params: { gameid: string <div> <h1>Game Detail</h1> <h1>{data[0].name}</h1> - <Image src={data[0].cover.url} alt={data[0].name} width={264} height={374} priority={true} /> + <Image src={data[0].cover.url} alt={data[0].name} width={264} height={374} priority={true} style={{ width: 'auto', height: 'auto' }} /> <p>{data[0].summary}</p> </div> ) -} \ No newline at end of file +} + +// pre-renders static paths for all fetched games for faster page loads +export async function generateStaticParams() { + const games = await getGames() + + return games.map((game) => ({ + gameid: game.id.toString(), + })); +} diff --git a/components/InfiniteScroll.tsx b/components/InfiniteScroll.tsx index 77b72b1..895e83e 100644 --- a/components/InfiniteScroll.tsx +++ b/components/InfiniteScroll.tsx @@ -2,14 +2,12 @@ import Game from "@/components/Game"; import { Card } from "@/components/ui/card"; -import { getBaseURL } from "@/lib/utils"; import { IGame } from "@/types/igdb-types"; import { useInfiniteQuery } from "@tanstack/react-query"; import { Fragment } from "react"; import InfiniteScroll from "react-infinite-scroll-component"; export function InfiniteScrollGames() { - console.log(getBaseURL()) const { status, data, @@ -19,9 +17,7 @@ export function InfiniteScrollGames() { } = useInfiniteQuery( ['infiniteGames'], async ({ pageParam = 1 }) => - await fetch( - `${getBaseURL()}/api/games/?page=${pageParam}`, - { cache: 'force-cache', } + await fetch(`/api/games/?page=${pageParam}`, ).then((result) => result.json() as Promise<IGame[]>), { getNextPageParam: (lastPage, pages) => { diff --git a/lib/utils.ts b/lib/utils.ts index b28079d..fefbdee 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -13,15 +13,6 @@ export function getImageURL(hashId: string, size: string): string { return `${IGDB_IMG_BASE_URL}/t_${size}_2x/${hashId}.jpg` } -// returns the base url for the current environment, even considering current port -export function getBaseURL(): string { - return process.env.NODE_ENV === 'production' - ? process.env.NEXT_PUBLIC_APP_URL ?? '' - : (typeof window !== 'undefined' - ? `http://${window.location.hostname}:${window.location.port}` - : 'http://localhost:3000') -} - // calculates the offset for the query export function calculateOffset(page: number, limit: number): number { return (page - 1) * limit -- GitLab