Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove get server props in edit page #25

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions pages/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { useRouter } from "next/router"
import * as yup from "yup"
import { useEffect, useState } from "react"
import { useEffect } from "react"
import { loadNFT } from "../services/backend"
import { useAccount } from "../hooks/useAccount"
import { Editor } from "../components/Editor"
import { Article } from "../types"
import { useAsync, useMountEffect } from "@react-hookz/web"
// todo: move to request center
const dweb_search_url = `https://dweb-search-api.anwen.cc/edit_meta`

interface EditArticleProps {
cid: string
nft: Article
}

export default function EditArticle({ cid, nft }: EditArticleProps) {
export default function EditArticle() {
const router = useRouter()
const account = useAccount()


const [info, actions] = useAsync(async () => {
const cid = router.query.cid as string || (new URLSearchParams(router.asPath.match(/cid=(.*)/g)[0])).get('cid')
if (!cid) return { cid: null, nft: null }
const nft = await loadNFT(cid)
return { cid, nft }
})

useMountEffect(actions.execute)

useEffect(() => {
if (!account) {
alert("No ETH Account, Please login")
Expand All @@ -26,23 +30,19 @@ export default function EditArticle({ cid, nft }: EditArticleProps) {
}, [])


if (!nft?.name)
if (info.status === 'loading') {
return <h1 className="py-10 px-20 text-3xl">Loading</h1>
}

if (!info.result?.nft?.name || !info.result?.cid)
return <h1 className="py-10 px-20 text-3xl">Article not found, cannot edit</h1>

return (
<div className="flex justify-center py-12">
<Editor account={account}
article={nft}
article={info.result?.nft}
publishLink={dweb_search_url}
cid={cid}/>
cid={info.result?.cid}/>
</div>
)
}

export async function getServerSideProps(context) {
const cid = context.query.cid
const nft = await loadNFT(cid)
return {
props: { cid, nft }
}
}