starshard/peafowl
Template
1
Fork 0
mirror of https://github.com/starshardstudio/peafowl.git synced 2024-11-28 16:04:18 +00:00
peafowl/_includes/game.tsx

162 lines
5.6 KiB
TypeScript
Raw Normal View History

2024-06-16 11:49:13 +00:00
import {formatDateIso} from "../_utils/date.ts"
2024-11-05 12:22:02 +00:00
import {GameData, GameIdentifier, GameProgress, gameProgressToClassName, gameProgressToIconDef, gameProgressToTitle} from "../_utils/game.ts"
2024-06-16 11:49:13 +00:00
import {ReviewInfo} from "../_components/ReviewInfo.tsx"
export const layout = "base.tsx"
export default function(data: GameData, helpers: Lume.Helpers) {
const dateRow = (
<ReviewInfo.MetadataRow
className={"review-date"}
label={"Last updated"}
>
{formatDateIso(data.date)}
</ReviewInfo.MetadataRow>
)
const dateSeparator = (data.progress || data.hours_played) ? <hr/> : null
const progressRow = data.progress ? (
<ReviewInfo.MetadataRow
2024-11-05 12:11:03 +00:00
className={`game-progress ${gameProgressToClassName(data.progress)}`}
2024-06-16 11:49:13 +00:00
label={"Progress"}
2024-11-05 12:11:03 +00:00
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(data.progress)} ${data.active ? "fa-beat-fade" : ""}`}/>}
2024-06-16 11:49:13 +00:00
>
<data value={data.progress}>
2024-11-05 12:11:03 +00:00
{gameProgressToTitle(data.progress)}
2024-06-16 11:49:13 +00:00
</data>
{data.active &&
<>
,&nbsp;
<span className={"fa-fade"} style={{animationDelay: '-0.5s'}}>now playing</span>
</>
}
</ReviewInfo.MetadataRow>
) : null
const hoursPlayedRow = data.hours_played ? (
<ReviewInfo.MetadataRow
className={`game-hoursplayed`}
label={"Playtime"}
>
<data value={data.hours_played}>
{data.hours_played}
</data>
&nbsp;
h
</ReviewInfo.MetadataRow>
) : null
const playedSeparator = (data.purchased_on || data.started_on || data.beaten_on || data.completed_on || data.mastered_on) ? <hr/> : null
const purchasedOnValue = formatDateIso(data.purchased_on)
const purchasedOnRow = purchasedOnValue ? (
<ReviewInfo.MetadataRow
className={`game-purchasedon`}
label={"Purchased on"}
2024-11-05 12:11:03 +00:00
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.New)}`}/>}
2024-06-16 11:49:13 +00:00
>
<time dateTime={purchasedOnValue}>
{purchasedOnValue}
</time>
</ReviewInfo.MetadataRow>
) : null
const startedOnValue = formatDateIso(data.started_on)
const startedOnRow = startedOnValue ? (
<ReviewInfo.MetadataRow
className={`game-startedon`}
label={"Started on"}
2024-11-05 12:11:03 +00:00
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.Started)}`}/>}
2024-06-16 11:49:13 +00:00
>
<time dateTime={startedOnValue}>
{startedOnValue}
</time>
</ReviewInfo.MetadataRow>
) : null
const beatenOnValue = formatDateIso(data.beaten_on)
const beatenOnRow = beatenOnValue ? (
<ReviewInfo.MetadataRow
className={`game-beatenon`}
label={"Beaten on"}
2024-11-05 12:11:03 +00:00
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.Beaten)}`}/>}
2024-06-16 11:49:13 +00:00
>
<time dateTime={beatenOnValue}>
{beatenOnValue}
</time>
</ReviewInfo.MetadataRow>
) : null
const completedOnValue = formatDateIso(data.completed_on)
const completedOnRow = completedOnValue ? (
<ReviewInfo.MetadataRow
className={`game-completedon`}
label={"Completed on"}
2024-11-05 12:11:03 +00:00
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.Completed)}`}/>}
2024-06-16 11:49:13 +00:00
>
<time dateTime={completedOnValue}>
{completedOnValue}
</time>
</ReviewInfo.MetadataRow>
) : null
const masteredOnValue = formatDateIso(data.mastered_on)
const masteredOnRow = masteredOnValue ? (
<ReviewInfo.MetadataRow
className={`game-masteredon`}
label={"Mastered on"}
2024-11-05 12:11:03 +00:00
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.Mastered)}`}/>}
2024-06-16 11:49:13 +00:00
>
<time dateTime={masteredOnValue}>
{masteredOnValue}
</time>
</ReviewInfo.MetadataRow>
) : null
const milestonesSeparator = ((data.identifiers?.length ?? 0) > 0) ? <hr/> : null
const identifiersRows = data.identifiers?.map((identifier: GameIdentifier, index: number) => {
switch(identifier.type) {
2024-06-16 11:49:13 +00:00
case "steam":
return (
<ReviewInfo.MetadataRow
key={index}
className={`game-identifier-steam`}
label={<span><i className={`fa-brands fa-steam`}/>&nbsp;Steam</span>}
>
<a href={`https://store.steampowered.com/app/${identifier.appid}/`}>
{identifier.name ?? identifier.appid}
</a>
</ReviewInfo.MetadataRow>
)
}
})
return (
<main id={"game-main"}>
<ReviewInfo
name={data.name}
rating={data.rating}
metadata={<>
{dateRow}
{dateSeparator}
{progressRow}
{hoursPlayedRow}
{playedSeparator}
{purchasedOnRow}
{startedOnRow}
{beatenOnRow}
{completedOnRow}
{masteredOnRow}
{milestonesSeparator}
{identifiersRows}
</>}
>
{data.children}
</ReviewInfo>
</main>
)
}