Skip to content

Commit 43cf8fb

Browse files
authored
fix: remove get sever props in edit (#25)
1 parent 8c42ffd commit 43cf8fb

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

pages/edit.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import { useRouter } from "next/router"
2-
import * as yup from "yup"
3-
import { useEffect, useState } from "react"
2+
import { useEffect } from "react"
43
import { loadNFT } from "../services/backend"
54
import { useAccount } from "../hooks/useAccount"
65
import { Editor } from "../components/Editor"
7-
import { Article } from "../types"
6+
import { useAsync, useMountEffect } from "@react-hookz/web"
87
// todo: move to request center
98
const dweb_search_url = `https://dweb-search-api.anwen.cc/edit_meta`
109

11-
interface EditArticleProps {
12-
cid: string
13-
nft: Article
14-
}
15-
16-
export default function EditArticle({ cid, nft }: EditArticleProps) {
10+
export default function EditArticle() {
1711
const router = useRouter()
1812
const account = useAccount()
1913

14+
15+
const [info, actions] = useAsync(async () => {
16+
const cid = router.query.cid as string || (new URLSearchParams(router.asPath.match(/cid=(.*)/g)[0])).get('cid')
17+
if (!cid) return { cid: null, nft: null }
18+
const nft = await loadNFT(cid)
19+
return { cid, nft }
20+
})
21+
22+
useMountEffect(actions.execute)
23+
2024
useEffect(() => {
2125
if (!account) {
2226
alert("No ETH Account, Please login")
@@ -26,23 +30,19 @@ export default function EditArticle({ cid, nft }: EditArticleProps) {
2630
}, [])
2731

2832

29-
if (!nft?.name)
33+
if (info.status === 'loading') {
34+
return <h1 className="py-10 px-20 text-3xl">Loading</h1>
35+
}
36+
37+
if (!info.result?.nft?.name || !info.result?.cid)
3038
return <h1 className="py-10 px-20 text-3xl">Article not found, cannot edit</h1>
3139

3240
return (
3341
<div className="flex justify-center py-12">
3442
<Editor account={account}
35-
article={nft}
43+
article={info.result?.nft}
3644
publishLink={dweb_search_url}
37-
cid={cid}/>
45+
cid={info.result?.cid}/>
3846
</div>
3947
)
4048
}
41-
42-
export async function getServerSideProps(context) {
43-
const cid = context.query.cid
44-
const nft = await loadNFT(cid)
45-
return {
46-
props: { cid, nft }
47-
}
48-
}

0 commit comments

Comments
 (0)