-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,36 @@ | ||
'use client' | ||
import { Content, Header } from '@components/NpcSideQuest/subcomponents' | ||
import npcs from '@data' | ||
import { useNpcLocalStorage } from '@hooks' | ||
import { Npc, NpcId } from '@types' | ||
import Head from 'next/head' | ||
import { NpcId } from '@types' | ||
import { notFound } from 'next/navigation' | ||
import { Metadata } from 'next' | ||
import { View } from './view' | ||
|
||
type PageProps = { | ||
params: { | ||
npc: NpcId | ||
} | ||
} | ||
|
||
type BaseNpcPageProps = { | ||
npcData: Npc | ||
export async function generateMetadata({ | ||
params, | ||
}: PageProps): Promise<Metadata> { | ||
const npcData = npcs.find((npc) => npc.id === params.npc) | ||
|
||
return { | ||
title: npcData?.name | ||
? `${npcData.name} / Elden Ring Quest Tracker` | ||
: 'Elden Ring Quest Tracker', | ||
} | ||
} | ||
|
||
export const generateStaticParams = async () => | ||
npcs.map((npc) => ({ npc: npc.id })) | ||
|
||
const getData = (npcId: NpcId) => npcs.find((npc) => npc.id === npcId) | ||
|
||
export default function NpcPage({ params }: PageProps) { | ||
const npcData = getData(params.npc) | ||
const npcData = npcs.find((npc) => npc.id === params.npc) | ||
|
||
if (!npcData) { | ||
return notFound() | ||
} | ||
|
||
return <BaseNpcPage npcData={npcData} /> | ||
} | ||
|
||
const BaseNpcPage = ({ npcData }: BaseNpcPageProps) => { | ||
const { localStorageValue, setLocalStorageTotal } = useNpcLocalStorage( | ||
npcData.id | ||
) | ||
|
||
const { | ||
description, | ||
failureConditions, | ||
id, | ||
image, | ||
link, | ||
name, | ||
rewards, | ||
steps, | ||
} = npcData | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>{`${name} / Elden Ring Quest Tracker`}</title> | ||
</Head> | ||
<Header | ||
description={description} | ||
isNpcComplete={!!localStorageValue?.total} | ||
link={link} | ||
name={name} | ||
toggleNpcComplete={(state) => setLocalStorageTotal(state)} | ||
image={image} | ||
/> | ||
<Content | ||
failureConditions={failureConditions} | ||
id={id} | ||
rewards={rewards} | ||
steps={steps} | ||
/> | ||
</> | ||
) | ||
return <View npcData={npcData} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client' | ||
|
||
import { Content } from '@components/NpcSideQuest/subcomponents/Content/Content' | ||
import { Header } from '@components/NpcSideQuest/subcomponents/Header/Header' | ||
import { useNpcLocalStorage } from '@hooks/useLocalStorage' | ||
import { Npc } from '@types/index' | ||
|
||
type ViewProps = { | ||
npcData: Npc | ||
} | ||
|
||
export const View = ({ npcData }: ViewProps) => { | ||
const { localStorageValue, setLocalStorageTotal } = useNpcLocalStorage( | ||
npcData.id | ||
) | ||
|
||
const { | ||
description, | ||
failureConditions, | ||
id, | ||
image, | ||
link, | ||
name, | ||
rewards, | ||
steps, | ||
} = npcData | ||
|
||
return ( | ||
<> | ||
<Header | ||
description={description} | ||
isNpcComplete={!!localStorageValue?.total} | ||
link={link} | ||
name={name} | ||
toggleNpcComplete={(state) => setLocalStorageTotal(state)} | ||
image={image} | ||
/> | ||
<Content | ||
failureConditions={failureConditions} | ||
id={id} | ||
rewards={rewards} | ||
steps={steps} | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.