Skip to content
Snippets Groups Projects
Commit 8f8b3a5c authored by Yusuf Akgül's avatar Yusuf Akgül :hatching_chick:
Browse files

fix deployment url 2

parent f793a351
No related branches found
No related tags found
No related merge requests found
Pipeline #34324 passed
...@@ -10,8 +10,17 @@ export default async function GameDetail({ params }: { params: { gameid: string ...@@ -10,8 +10,17 @@ export default async function GameDetail({ params }: { params: { gameid: string
<div> <div>
<h1>Game Detail</h1> <h1>Game Detail</h1>
<h1>{data[0].name}</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> <p>{data[0].summary}</p>
</div> </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(),
}));
}
...@@ -2,14 +2,12 @@ ...@@ -2,14 +2,12 @@
import Game from "@/components/Game"; import Game from "@/components/Game";
import { Card } from "@/components/ui/card"; import { Card } from "@/components/ui/card";
import { getBaseURL } from "@/lib/utils";
import { IGame } from "@/types/igdb-types"; import { IGame } from "@/types/igdb-types";
import { useInfiniteQuery } from "@tanstack/react-query"; import { useInfiniteQuery } from "@tanstack/react-query";
import { Fragment } from "react"; import { Fragment } from "react";
import InfiniteScroll from "react-infinite-scroll-component"; import InfiniteScroll from "react-infinite-scroll-component";
export function InfiniteScrollGames() { export function InfiniteScrollGames() {
console.log(getBaseURL())
const { const {
status, status,
data, data,
...@@ -19,9 +17,7 @@ export function InfiniteScrollGames() { ...@@ -19,9 +17,7 @@ export function InfiniteScrollGames() {
} = useInfiniteQuery( } = useInfiniteQuery(
['infiniteGames'], ['infiniteGames'],
async ({ pageParam = 1 }) => async ({ pageParam = 1 }) =>
await fetch( await fetch(`/api/games/?page=${pageParam}`,
`${getBaseURL()}/api/games/?page=${pageParam}`,
{ cache: 'force-cache', }
).then((result) => result.json() as Promise<IGame[]>), ).then((result) => result.json() as Promise<IGame[]>),
{ {
getNextPageParam: (lastPage, pages) => { getNextPageParam: (lastPage, pages) => {
......
...@@ -13,15 +13,6 @@ export function getImageURL(hashId: string, size: string): string { ...@@ -13,15 +13,6 @@ export function getImageURL(hashId: string, size: string): string {
return `${IGDB_IMG_BASE_URL}/t_${size}_2x/${hashId}.jpg` 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 // calculates the offset for the query
export function calculateOffset(page: number, limit: number): number { export function calculateOffset(page: number, limit: number): number {
return (page - 1) * limit return (page - 1) * limit
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment