feat: update search page and improve details
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useCallback, useState } from "react"
|
||||
import Image from "next/image"
|
||||
import {
|
||||
Gamepad2Icon,
|
||||
@@ -61,20 +61,23 @@ export function GamePageClient({
|
||||
platformSupport: PlatformSupport[]
|
||||
}) {
|
||||
const [activeTab, setActiveTab] = useState<TabKey>("overview")
|
||||
const [imgError, setImgError] = useState(false)
|
||||
const handleImgError = useCallback(() => setImgError(true), [])
|
||||
|
||||
const headerImage = game.headerImage || game.capsuleImage
|
||||
const headerImage = game.capsuleImage || game.headerImage
|
||||
|
||||
return (
|
||||
<section className="w-full flex flex-col">
|
||||
{/* Hero */}
|
||||
<div className="relative w-full h-48 sm:h-64 md:h-80 overflow-hidden">
|
||||
{headerImage ? (
|
||||
{headerImage && !imgError ? (
|
||||
<Image
|
||||
src={headerImage}
|
||||
alt={game.title}
|
||||
fill
|
||||
className="object-cover"
|
||||
priority
|
||||
onError={handleImgError}
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full h-full bg-text/10 flex items-center justify-center">
|
||||
|
||||
@@ -39,23 +39,27 @@ async function createGameStub(steamAppId: number) {
|
||||
const data = (await res.json()) as Record<
|
||||
string,
|
||||
{ success: boolean; data: {
|
||||
type?: string
|
||||
name: string
|
||||
developers?: string[]
|
||||
publishers?: string[]
|
||||
genres?: { description: string }[]
|
||||
header_image?: string
|
||||
capsule_imagev5?: string
|
||||
short_description?: string
|
||||
} }
|
||||
>
|
||||
const entry = data[String(steamAppId)]
|
||||
if (entry?.success && entry.data) {
|
||||
// Reject non-games (DLCs, soundtracks, demos, etc.)
|
||||
if (entry.data.type && entry.data.type !== "game") {
|
||||
notFound()
|
||||
}
|
||||
title = entry.data.name
|
||||
developer = entry.data.developers?.[0] ?? null
|
||||
publisher = entry.data.publishers?.[0] ?? null
|
||||
genres = entry.data.genres?.map((g) => g.description) ?? []
|
||||
headerImage = entry.data.header_image ?? null
|
||||
capsuleImage = entry.data.capsule_imagev5 ?? entry.data.header_image ?? null
|
||||
capsuleImage = `https://cdn.akamai.steamstatic.com/steam/apps/${steamAppId}/library_600x900.jpg`
|
||||
description = entry.data.short_description ?? null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user