starshard/peafowl
Template
1
Fork 0
mirror of https://github.com/starshardstudio/peafowl.git synced 2024-11-22 04:54:19 +00:00
peafowl/_components/GameRow.tsx

108 lines
4 KiB
TypeScript
Raw Normal View History

2024-06-16 11:49:13 +00:00
import {formatDateIso} from "../_utils/date.ts"
import {GameData} from "../_utils/game.ts"
import {Progress, progressToClassName, progressToIconDef, progressToTitle} from "../_utils/progress.ts"
import {ratingToClassName} from "../_utils/rating.ts"
2024-07-07 02:45:11 +00:00
export type GameRowColumnKind = "rating" | "progress" | "name" | "namesort" | "hascontent" | "date" | "hoursplayed"
2024-06-16 11:49:13 +00:00
export type GameRowColumnPriority = undefined | "rating" | "progress" | "mixed"
2024-07-07 02:45:11 +00:00
export const gameRowColumnKindDefault: GameRowColumnKind[] = ["rating", "name", "namesort", "hascontent", "date", "progress", "hoursplayed"]
2024-06-16 11:49:13 +00:00
export type GameRowProps = {
game: GameData,
columns?: GameRowColumnKind[]
priority?: GameRowColumnPriority
}
export function GameRow({game, columns = gameRowColumnKindDefault, priority}: GameRowProps) {
const activeClass: string = game.active ? "review-active" : ""
const activeClassFa: string = game.active ? "fa-beat-fade" : ""
const ratingText: string = game.rating ? `${game.rating}` : ""
const ratingClass: string = ratingToClassName(game.rating)
const progressClass: string = progressToClassName(game.progress)
const progressIcon: string = progressToIconDef(game.progress)
const progressTitle: string = progressToTitle(game.progress)
const priorityClass: string = priority ? `priority-${priority}` : ""
const columnsElements = columns.map((kind, index) => {
switch(kind) {
case "rating": {
return (
<td key={index} className={`review-rating ${ratingClass}`}>
<data value={ratingText}>
{ratingText}
</data>
</td>
)
}
case "progress": {
return (
<td key={index} className={`game-progress ${progressClass}`}>
<data value={game.progress ?? Progress.Unset} title={progressTitle}>
{progressIcon && <i className={`fa-sharp fa-regular ${progressIcon} ${activeClassFa}`}></i>}
</data>
</td>
)
}
case "name": {
return (
<td key={index} className={`review-name`}>
<a href={game.url}>
<data value={game.name ?? ""}>
{game.name}
</data>
</a>
</td>
)
}
2024-07-07 02:45:11 +00:00
case "namesort": {
return (
<td key={index} className={`review-namesort`} hidden={true}>
<data value={game.name ?? ""}/>
</td>
)
}
2024-06-16 11:49:13 +00:00
case "hascontent": {
return (
<td key={index} className={`review-hascontent`}>
<data value={game.content ? "true" : "false"}>
{game.content && <i className={"fa-sharp fa-regular fa-bars-sort"}/>}
2024-06-16 11:49:13 +00:00
</data>
</td>
)
}
case "date": {
const date = formatDateIso(game.date)
return (
<td key={index} className={`review-date`}>
<time dateTime={date ?? ""}>
{date}
</time>
</td>
)
}
case "hoursplayed": {
return (
<td key={index} className={`game-hoursplayed`}>
<data value={game.hours_played ?? ""}>
{(game.hours_played ?? 0) > 0 ? `${game.hours_played} h` : ""}
</data>
</td>
)
}
}
})
return (
<tr className={`game ${activeClass} ${ratingClass} ${progressClass} ${priorityClass}`}>
{columnsElements}
</tr>
)
}