Skip to content

Commit 95225db

Browse files
author
Brocken
authored
Merge pull request #37 from wedinc/feat/mobpro
change using app router
2 parents 3b02779 + 55f37e1 commit 95225db

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react'
2+
3+
export type CardProps = {
4+
by: string
5+
descendants: number
6+
id: number
7+
score: number
8+
time: number
9+
title: string
10+
type: 'job' | 'story' | 'comment' | 'poll'
11+
url: string
12+
}
13+
14+
const Card: React.FC<CardProps> = ({ by, descendants, id, score, time, title, type, url }) => {
15+
return (
16+
<div className='bg-white rounded-lg shadow-lg p-6'>
17+
<h2 className='text-2xl font-bold mb-2'>
18+
{id}: {title}
19+
</h2>
20+
<p className='text-gray-600 mb-2'>By: {by}</p>
21+
<p className='text-gray-600 mb-2'>Score: {score}</p>
22+
<p className='text-gray-600 mb-2'>Type: {type}</p>
23+
<p className='text-gray-600 mb-2'>Time: {new Date(time * 1000).toLocaleString()}</p>
24+
<p className='text-gray-600 mb-2'>
25+
URL:{' '}
26+
<a href={url} className='text-blue-500 hover:underline'>
27+
{url}
28+
</a>
29+
</p>
30+
<p className='text-gray-600'>Got {descendants} comments</p>
31+
</div>
32+
)
33+
}
34+
35+
export default Card

app/caramel/[id]/page.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Link from 'next/link'
2+
import Card from './_components/Card'
3+
// before routing: import Card, { CardProps } from '@/components/Card'
4+
5+
export default async function Article({ params }: { params: { id: string } }) {
6+
const res = await fetch(`https://hacker-news.firebaseio.com/v0/item/${params.id}.json`)
7+
const article = await res.json()
8+
9+
return (
10+
<div className='bg-[#bc611e] p-8'>
11+
{article ? <Card {...article} /> : <div />}
12+
<Link href='/caramel' className='btn btn-primary'>
13+
Back
14+
</Link>
15+
</div>
16+
)
17+
}

pages/caramel/[id].tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)