|
1 |
| -import { useNFT3Profile } from 'domains/data' |
2 |
| -import type { GetStaticPaths, GetStaticProps } from 'next' |
| 1 | +import { NFT3Client } from '@nft3sdk/client' |
| 2 | +import type { ProfileModel, WithMeta } from '@nft3sdk/client' |
| 3 | +import { useNFT3, useNFT3Profile } from 'domains/data' |
| 4 | +import type { GetServerSideProps } from 'next' |
3 | 5 | import { useEffect, Fragment } from 'react'
|
4 | 6 | import ProfileBoard from 'UI/profile-board'
|
5 |
| -import Head from 'next/head' |
| 7 | +import { NFT3Endpoint } from './_app' |
| 8 | +import type { HeaderProps } from 'components/Header' |
| 9 | +import Header from 'components/Header' |
6 | 10 |
|
7 |
| -export const getStaticProps: GetStaticProps = (props) => { |
8 |
| - const { id } = props.params |
9 |
| - return { |
10 |
| - props: { |
11 |
| - id: typeof id === 'string' ? id : id[0], |
12 |
| - }, |
| 11 | +export const getServerSideProps: GetServerSideProps = async (context) => { |
| 12 | + const { id } = context.params |
| 13 | + const didname = typeof id === 'string' ? id : id[0] |
| 14 | + const client = new NFT3Client(NFT3Endpoint) |
| 15 | + const did = client.did.convertName(didname) |
| 16 | + const promises = [] |
| 17 | + const data: any = { |
| 18 | + profile: undefined, |
13 | 19 | }
|
14 |
| -} |
| 20 | + promises.push(client.profile.info(did).then((profile) => (data.profile = profile))) |
| 21 | + |
| 22 | + await Promise.all(promises) |
15 | 23 |
|
16 |
| -export const getStaticPaths: GetStaticPaths = () => { |
17 | 24 | return {
|
18 |
| - paths: [], |
19 |
| - fallback: 'blocking', |
| 25 | + props: { |
| 26 | + id: didname, |
| 27 | + ...data, |
| 28 | + }, |
20 | 29 | }
|
21 | 30 | }
|
22 | 31 |
|
23 |
| -const IndexPage: FC<{ id: string }> = (props) => { |
24 |
| - const { setDidname } = useNFT3Profile() |
| 32 | +const IndexPage: FC<{ id: string; profile: WithMeta<ProfileModel> }> = (props) => { |
| 33 | + const { id, profile } = props |
| 34 | + const { format } = useNFT3() |
| 35 | + const { setDidname, setProfileInternal } = useNFT3Profile() |
25 | 36 |
|
26 | 37 | useEffect(() => {
|
27 |
| - setDidname(props.id) |
28 |
| - }, [props.id, setDidname]) |
| 38 | + setDidname(id) |
| 39 | + setProfileInternal(profile) |
| 40 | + }, [id, profile, setDidname, setProfileInternal]) |
| 41 | + |
| 42 | + const headerProps: HeaderProps = {} |
| 43 | + |
| 44 | + if (profile) { |
| 45 | + headerProps.title = `${id}.isme | NFT3 Pass` |
| 46 | + headerProps.description = profile.bio |
| 47 | + headerProps.ogDescription = headerProps.description |
| 48 | + headerProps.image = format(profile.avatar) |
| 49 | + } |
29 | 50 |
|
30 | 51 | return (
|
31 | 52 | <Fragment>
|
32 |
| - <Head> |
33 |
| - <title>{`${props.id}.isme | NFT3 Pass`}</title> |
34 |
| - </Head> |
| 53 | + <Header {...headerProps} /> |
35 | 54 | <ProfileBoard />
|
36 | 55 | </Fragment>
|
37 | 56 | )
|
|
0 commit comments