Skip to content

Commit aecdd4a

Browse files
committed
refactor: create article item component
1 parent 8f593af commit aecdd4a

File tree

5 files changed

+50
-43
lines changed

5 files changed

+50
-43
lines changed

components/ArticleItem.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { memo } from "react"
2+
3+
interface ArticleItemProps {
4+
imageURL: string,
5+
name: string
6+
tags: string
7+
authors: string
8+
path: string
9+
}
10+
11+
export const ArticleItem = memo<ArticleItemProps>(({ imageURL, tags, authors, name, path }) => {
12+
return (
13+
<div className="p-4 md:w-1/3">
14+
<div className="h-full border-2 border-gray-200 border-opacity-60 rounded-lg overflow-hidden">
15+
<img className="lg:h-48 md:h-36 w-full object-cover object-center" src={imageURL} alt={name} />
16+
<div className="p-6">
17+
<h2 className="tracking-widest text-xs title-font font-medium text-gray-400 mb-1">{ tags }</h2>
18+
<h1 className="title-font text-lg font-medium text-gray-900 mb-3">{ name }</h1>
19+
<p className="leading-relaxed mb-3">{ authors }</p>
20+
<div className="flex items-center flex-wrap ">
21+
<a className="text-indigo-500 inline-flex items-center md:mb-2 lg:mb-0" href={"/article?cid=" + path}>Goto
22+
<svg className="w-4 h-4 ml-2" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2"
23+
fill="none" strokeLinecap="round" strokeLinejoin="round">
24+
<path d="M5 12h14"/>
25+
<path d="M12 5l7 7-7 7"/>
26+
</svg>
27+
</a>
28+
</div>
29+
</div>
30+
</div>
31+
</div>
32+
)
33+
})
34+
35+
ArticleItem.displayName = 'ArticleItem'

pages/_app.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function App({ Component, pageProps }) {
186186
active ? "bg-blue-500 text-gray-300" : "text-gray-900"
187187
} group flex rounded-md items-center w-full px-2 py-2 text-sm`}
188188
>
189-
id: {getBrief(account)}
189+
ID: {getBrief(account)}
190190
</button>
191191
)}
192192
</Menu.Item>

pages/articles-all.js

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useState } from "react"
22
import axios from "axios"
33
import { Layout } from "../components/Layout"
4+
import { ArticleItem } from "../components/ArticleItem"
45

56
let ethAccount
67

@@ -28,27 +29,12 @@ export default function MyAssets() {
2829

2930
return (
3031
<Layout>
31-
<div className="flex justify-center">
32-
<div className="p-4">
33-
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 pt-4">
34-
{nfts.map((nft, i) => (
35-
<div key={i} className="border shadow rounded-xl overflow-hidden">
36-
<img src={nft.image} className="rounded" />
37-
<div className="p-4">
38-
<a href={"/article?cid=" + nft.path}>
39-
<p className="text-2xl font-semibold">{nft.name}</p>
40-
</a>
41-
<p className="text-2xl font-semibold">
42-
By:
43-
<a href={"/articles?author=" + nft.eth}>{nft.authors}</a>
44-
</p>
45-
Tags: {nft.tags}
46-
</div>
47-
</div>
48-
))}
49-
</div>
50-
</div>
51-
</div>
32+
<section className="text-gray-600 body-font flex flex-wrap -m-4 justify-start m-6">
33+
{nfts.map((nft, i) => (
34+
<ArticleItem key={i} imageURL={nft.image} name={nft.name} tags={nft.tags} authors={nft.authors} path={nft.path}/>
35+
))}
36+
37+
</section>
5238
</Layout>
5339
)
5440
}

pages/articles-my.js

+6-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useState } from "react"
22
import axios from "axios"
33
import { useAccount } from "../hooks/useAccount"
44
import { Layout } from "../components/Layout"
5+
import { ArticleItem } from "../components/ArticleItem"
56

67
export default function MyAssets() {
78
const [nfts, setNfts] = useState([])
@@ -27,26 +28,11 @@ export default function MyAssets() {
2728

2829
return (
2930
<Layout>
30-
<div className="flex justify-center">
31-
<div className="p-4">
32-
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 pt-4">
33-
{nfts.map((nft, i) => (
34-
<div key={i} className="border shadow rounded-xl overflow-hidden">
35-
<img src={nft.image} className="rounded" />
36-
<div className="p-4">
37-
<a href={"/article?cid=" + nft.path}>
38-
<p className="text-2xl font-semibold">{nft.name}</p>
39-
</a>
40-
<p className="text-2xl font-semibold">
41-
By:
42-
<a href={"/articles?author=" + nft.eth}>{nft.authors}</a>
43-
</p>
44-
</div>
45-
</div>
46-
))}
47-
</div>
48-
</div>
49-
</div>
31+
<section className="text-gray-600 body-font flex flex-wrap -m-4 m-6">
32+
{nfts.map((nft, i) => (
33+
<ArticleItem key={i} imageURL={nft.image} name={nft.name} tags={nft.tags} authors={nft.authors} path={nft.path}/>
34+
))}
35+
</section>
5036
</Layout>
5137
)
5238
}

pages/create-draft.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Editor } from "../components/Editor"
33
export default function CreateDraft() {
44
const account = 'testaccout'
55
return (
6-
<div className="flex justify-center py-16 min-h-screen">
6+
<div className="flex justify-center py-16">
77
<Editor account={account} />
88
</div>
99
)

0 commit comments

Comments
 (0)