Skip to content

Commit

Permalink
change using app router
Browse files Browse the repository at this point in the history
  • Loading branch information
Brocken committed Dec 8, 2023
1 parent 3b02779 commit 55f37e1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
35 changes: 35 additions & 0 deletions app/caramel/[id]/_components/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react'

export type CardProps = {
by: string
descendants: number
id: number
score: number
time: number
title: string
type: 'job' | 'story' | 'comment' | 'poll'
url: string
}

const Card: React.FC<CardProps> = ({ by, descendants, id, score, time, title, type, url }) => {
return (
<div className='bg-white rounded-lg shadow-lg p-6'>
<h2 className='text-2xl font-bold mb-2'>
{id}: {title}
</h2>
<p className='text-gray-600 mb-2'>By: {by}</p>
<p className='text-gray-600 mb-2'>Score: {score}</p>
<p className='text-gray-600 mb-2'>Type: {type}</p>
<p className='text-gray-600 mb-2'>Time: {new Date(time * 1000).toLocaleString()}</p>
<p className='text-gray-600 mb-2'>
URL:{' '}
<a href={url} className='text-blue-500 hover:underline'>
{url}
</a>
</p>
<p className='text-gray-600'>Got {descendants} comments</p>
</div>
)
}

export default Card
17 changes: 17 additions & 0 deletions app/caramel/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Link from 'next/link'
import Card from './_components/Card'
// before routing: import Card, { CardProps } from '@/components/Card'

export default async function Article({ params }: { params: { id: string } }) {
const res = await fetch(`https://hacker-news.firebaseio.com/v0/item/${params.id}.json`)
const article = await res.json()

return (
<div className='bg-[#bc611e] p-8'>
{article ? <Card {...article} /> : <div />}
<Link href='/caramel' className='btn btn-primary'>
Back
</Link>
</div>
)
}
29 changes: 0 additions & 29 deletions pages/caramel/[id].tsx

This file was deleted.

0 comments on commit 55f37e1

Please sign in to comment.