Skip to content

Commit

Permalink
feat: upgrade next version
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogeveen committed Mar 3, 2024
1 parent ed864f3 commit 5bc8b2a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 117 deletions.
65 changes: 15 additions & 50 deletions app/[npc]/page.tsx
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} />
}
46 changes: 46 additions & 0 deletions app/[npc]/view.tsx
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'

Check failure on line 6 in app/[npc]/view.tsx

View workflow job for this annotation

GitHub Actions / Lint | Typecheck

Cannot import type declaration files. Consider importing 'index' instead of '@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}
/>
</>
)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@types/react": "18.2.61",
"@types/react-dom": "18.2.4",
"@vercel/analytics": "^1.0.1",
"next": "13.5.1",
"next": "14.1.1",
"normalize.css": "^8.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
Loading

0 comments on commit 5bc8b2a

Please sign in to comment.