starshard/peafowl
Template
1
Fork 0
mirror of https://github.com/starshardstudio/peafowl.git synced 2024-11-25 06:24:20 +00:00
peafowl/_components/GameTable.tsx

112 lines
3.8 KiB
TypeScript
Raw Normal View History

2024-06-16 11:49:13 +00:00
import {GameData} from "../_utils/game.ts"
import {GameRow, GameRowColumnKind, gameRowColumnKindDefault, GameRowColumnPriority} from "./GameRow.tsx"
export type GameTableProps = {
2024-07-07 02:45:11 +00:00
id?: string,
2024-06-16 11:49:13 +00:00
games: GameData[],
columns?: GameRowColumnKind[]
priority?: GameRowColumnPriority
}
2024-07-07 02:45:11 +00:00
export function GameTable({id, games, columns = gameRowColumnKindDefault, priority}: GameTableProps) {
2024-06-16 11:49:13 +00:00
const colElements = columns.map((column, index) => {
switch(column) {
case "rating": return (
<col key={index} className={`review-rating`}/>
)
case "progress": return (
<col key={index} className={`game-progress`}/>
)
case "name": return (
<col key={index} className={`review-name`}/>
)
case "hascontent": return (
<col key={index} className={`review-hascontent`}/>
)
case "date": return (
<col key={index} className={`review-date`}/>
)
case "hoursplayed": return (
<col key={index} className={`review-hoursplayed`}/>
)
}
})
const thElements = columns.map((column, index) => {
switch(column) {
case "rating": return (
<th key={index} scope={"col"} className={`review-rating`}>
<abbr title={"The rating of the game, from 1 to 100."}>
<i className={`fa-sharp fa-solid fa-thumbs-up`}/>
</abbr>
</th>
)
case "progress": return (
<th key={index} scope={"col"} className={`game-progress`}>
<abbr title={"The progress that has been made in the game."}>
<i className={`fa-sharp fa-solid fa-bars-progress`}/>
</abbr>
</th>
)
case "name": return (
<th key={index} scope={"col"} className={`review-name`}>
<abbr title={"The title of the game."}>
Title
</abbr>
</th>
)
2024-07-07 02:45:11 +00:00
case "namesort": return (
<th key={index} scope={"col"} className={`review-namesort`} hidden={true}>
<abbr title={"The title to sort the game as."}>
Sort by
</abbr>
</th>
)
case "hascontent":
return (
<th key={index} scope={"col"} className={`review-hascontent`}>
<abbr title={"Whether the review has textual content, or just metadata."}>
2024-06-16 11:49:13 +00:00
<i className={`fa-sharp fa-regular fa-bars-sort`}/>
</abbr>
</th>
)
case "date": return (
<th key={index} scope={"col"} className={`review-date`}>
<abbr title={"The date of the last update of the review."}>
Date
</abbr>
</th>
)
case "hoursplayed": return (
<th key={index} scope={"col"} className={`game-hoursplayed`}>
<abbr title={"How many hours the game has been played for."}>
Playtime
</abbr>
</th>
)
}
})
const trTdElements = games.map((game: GameData) => (
<GameRow key={game.url} game={game} columns={columns} priority={priority}/>
))
return (
2024-07-07 02:45:11 +00:00
<table id={id}>
2024-06-16 11:49:13 +00:00
<colgroup>
{colElements}
</colgroup>
<thead>
<tr>
{thElements}
</tr>
</thead>
<tbody>
{trTdElements}
</tbody>
</table>
)
}