1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-02-05 16:44:19 +01:00
ipfs-boards/pages/b/[board]/index.js

36 lines
870 B
JavaScript
Raw Permalink Normal View History

2019-10-22 23:38:21 +02:00
import React from 'react'
import { openBoard, refreshInfo } from '../../../components/system'
import Board from '../../../components/Board'
2019-10-22 23:38:21 +02:00
class BoardPage extends React.PureComponent {
2019-10-26 23:58:20 +02:00
state = { posts: [] }
componentDidMount() {
this.refreshPosts()
}
async refreshPosts() {
const { boardId } = this.props
if (boardId) {
const board = await openBoard(boardId)
this.setState({ posts: board.posts })
} else {
throw new Error('Missing boardId')
}
2019-10-26 23:58:20 +02:00
}
render() {
const { boardId } = this.props
const posts = this.state.posts || this.props.posts
return <Board boardId={boardId} posts={posts} />
2019-10-26 23:58:20 +02:00
}
}
BoardPage.getInitialProps = async ({ query }) => {
await refreshInfo()
2019-10-26 23:58:20 +02:00
const board = await openBoard(query.board)
return { posts: await board.posts, boardId: query.board }
2019-10-22 23:38:21 +02:00
}
export default BoardPage