starshard/peafowl
Template
1
Fork 0
mirror of https://github.com/starshardstudio/peafowl.git synced 2024-11-24 22:14:19 +00:00
peafowl/_includes/anime.tsx

197 lines
7.3 KiB
TypeScript
Raw Normal View History

2024-11-05 12:25:02 +00:00
import {formatDateIso} from "../_utils/date.ts"
2024-11-21 05:37:11 +00:00
import {AnimeData, AnimeIdentifier, AnimeProgress, animeProgressToClassName, animeProgressToIconDef, animeProgressToTitle} from "../_utils/anime.ts"
2024-11-05 12:25:02 +00:00
import {ReviewInfo} from "../_components/ReviewInfo.tsx"
export const layout = "base.tsx"
export default function(data: AnimeData, 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 nameOriginalRow = data.name_original ? (
2024-11-05 12:39:33 +00:00
<ReviewInfo.MetadataRow
className={"anime-nameoriginal"}
label={"Original name"}
>
<data value={data.name_original}>
{data.name_original}
</data>
</ReviewInfo.MetadataRow>
) : null
2024-11-05 12:39:33 +00:00
const nameSeparator = (data.name_original) ? <hr/> : null
2024-11-05 12:25:02 +00:00
const progressRow = data.progress ? (
<ReviewInfo.MetadataRow
className={`anime-progress ${animeProgressToClassName(data.progress)}`}
label={"Progress"}
icon={<i className={`fa-sharp fa-regular ${animeProgressToIconDef(data.progress)} ${data.active ? "fa-beat-fade" : ""}`}/>}
>
<data value={data.progress}>
{animeProgressToTitle(data.progress)}
</data>
{data.active &&
<>
,&nbsp;
<span className={"fa-fade"} style={{animationDelay: '-0.5s'}}>now watching</span>
</>
}
</ReviewInfo.MetadataRow>
) : null
const playedSeparator = (data.started_on || data.completed_on || data.mastered_on) ? <hr/> : null
const purchasedOnValue = formatDateIso(data.purchased_on)
const purchasedOnRow = purchasedOnValue ? (
<ReviewInfo.MetadataRow
className={`anime-purchasedon`}
label={"Purchased on"}
icon={<i className={`fa-sharp fa-regular ${animeProgressToIconDef(AnimeProgress.New)}`}/>}
>
<time dateTime={purchasedOnValue}>
{purchasedOnValue}
</time>
</ReviewInfo.MetadataRow>
) : null
const startedOnValue = formatDateIso(data.started_on)
const startedOnRow = startedOnValue ? (
<ReviewInfo.MetadataRow
className={`anime-startedon`}
label={"Started on"}
icon={<i className={`fa-sharp fa-regular ${animeProgressToIconDef(AnimeProgress.Started)}`}/>}
>
<time dateTime={startedOnValue}>
{startedOnValue}
</time>
</ReviewInfo.MetadataRow>
) : null
const completedOnValue = formatDateIso(data.completed_on)
const completedOnRow = completedOnValue ? (
<ReviewInfo.MetadataRow
className={`anime-completedon`}
label={"Completed on"}
icon={<i className={`fa-sharp fa-regular ${animeProgressToIconDef(AnimeProgress.Completed)}`}/>}
>
<time dateTime={completedOnValue}>
{completedOnValue}
</time>
</ReviewInfo.MetadataRow>
) : null
const masteredOnValue = formatDateIso(data.mastered_on)
const masteredOnRow = masteredOnValue ? (
<ReviewInfo.MetadataRow
className={`anime-masteredon`}
label={"Mastered on"}
icon={<i className={`fa-sharp fa-regular ${animeProgressToIconDef(AnimeProgress.Mastered)}`}/>}
>
<time dateTime={masteredOnValue}>
{masteredOnValue}
</time>
</ReviewInfo.MetadataRow>
) : null
2024-11-21 05:37:11 +00:00
const milestonesSeparator = ((data.identifiers?.length ?? 0) > 0) ? <hr/> : null
const identifiersRows = data.identifiers?.map((identifier: AnimeIdentifier, index: number) => {
switch(identifier.type) {
case "wikidata":
return (
<ReviewInfo.MetadataRow
key={index}
className={`review-identifier-wikidata`}
label={<span><i className={`fa-sharp fa-regular fa-barcode`}/>&nbsp;Wikidata</span>}
>
<a href={`https://www.wikidata.org/wiki/Q${identifier.q}`}>
Q{identifier.q}
</a>
</ReviewInfo.MetadataRow>
)
case "anidb":
return (
<ReviewInfo.MetadataRow
key={index}
className={`anime-identifier-anidb`}
label={<span><i className={`fa-sharp fa-regular fa-database`}/>&nbsp;AniDB</span>}
>
<a href={`https://anidb.net/anime/${identifier.aid}`}>
{identifier.aid}
</a>
</ReviewInfo.MetadataRow>
)
case "mal":
return (
<ReviewInfo.MetadataRow
key={index}
className={`anime-identifier-mal`}
label={<span><i className={`fa-sharp fa-regular fa-list-check`}/>&nbsp;MyAnimeList</span>}
>
<a href={`https://myanimelist.net/anime/${identifier.id}`}>
{identifier.id}
</a>
</ReviewInfo.MetadataRow>
)
case "ann":
return (
<ReviewInfo.MetadataRow
key={index}
className={`anime-identifier-ann`}
label={<span><i className={`fa-sharp fa-regular fa-circles-overlap`}/>&nbsp;Anime News Network</span>}
>
<a href={`https://www.animenewsnetwork.com/encyclopedia/anime.php?id=${identifier.id}`}>
{identifier.id}
</a>
</ReviewInfo.MetadataRow>
)
case "anilist":
return (
<ReviewInfo.MetadataRow
key={index}
className={`anime-identifier-anilist`}
label={<span><i className={`fa-sharp fa-regular fa-circles-overlap`}/>&nbsp;Anilist</span>}
>
<a href={`https://anilist.co/anime/${identifier.id}/`}>
{identifier.id}
</a>
</ReviewInfo.MetadataRow>
)
}
})
2024-11-05 12:25:02 +00:00
return (
<main id={"anime-main"}>
<ReviewInfo
name={data.name}
rating={data.rating}
metadata={<>
{dateRow}
{dateSeparator}
2024-11-05 17:01:34 +00:00
{nameOriginalRow}
{nameSeparator}
2024-11-05 12:25:02 +00:00
{progressRow}
{playedSeparator}
{purchasedOnRow}
{startedOnRow}
{completedOnRow}
{masteredOnRow}
2024-11-21 05:37:11 +00:00
{milestonesSeparator}
{identifiersRows}
2024-11-05 12:25:02 +00:00
</>}
>
{data.children}
</ReviewInfo>
</main>
)
}