1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-29 15:34:19 +01:00
ipfs-boards/pages/b/[board]/p/[post].js

47 lines
1.0 KiB
JavaScript

import React from 'react'
import { openBoard } from '../../../../components/system'
import Post from '../../../../components/Post'
const findPost = (posts, id) => {
const results = posts.filter(p => p.multihash === id)
if (results.length > 0) return results[0]
return undefined
}
class PostPage extends React.PureComponent {
state = {
post: undefined
}
componentDidMount() {
this.refreshPost()
}
async refreshPost() {
const { boardId, postId } = this.props
const board = await openBoard(boardId)
const post = findPost(board.posts, postId)
this.setState({ post })
}
render() {
const { post: postProp, boardId } = this.props
const { post } = this.state
return <Post
post={post || postProp}
boardId={boardId}
/>
}
}
PostPage.getInitialProps = async ({ query }) => {
const board = await openBoard(query.board)
return {
post: findPost(board.posts, query.post),
boardId: query.board,
postId: query.post
}
}
export default PostPage