2019-10-22 23:38:21 +02:00
|
|
|
import React from 'react'
|
2019-11-13 01:02:56 +01:00
|
|
|
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}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
}
|
2019-10-22 23:38:21 +02:00
|
|
|
|
2019-11-13 01:02:56 +01:00
|
|
|
PostPage.getInitialProps = async ({ query }) => {
|
|
|
|
const board = await openBoard(query.board)
|
|
|
|
return {
|
|
|
|
post: findPost(board.posts, query.post),
|
|
|
|
boardId: query.board,
|
|
|
|
postId: query.post
|
|
|
|
}
|
2019-10-22 23:38:21 +02:00
|
|
|
}
|
|
|
|
|
2019-11-13 01:02:56 +01:00
|
|
|
export default PostPage
|