import React from 'react'; import { Link, RouteComponentProps } from 'react-router-dom'; import { get } from 'lodash'; import { ThreadService } from '../../services'; import { ForumNav, LoginButton, ScrollToTop } from '../../components'; import { ThreadModel } from '../../model'; import './forum.scss'; interface Props extends RouteComponentProps {} interface State { threads: ThreadModel[]; } export class Forum extends React.Component { constructor(props: Props) { super(props); this.state = { threads: [], }; } componentDidMount() { this.getThreads(); } private async getThreads() { const threads = await ThreadService.getCategoryThreads(this.props.match.params['id']); this.setState({ threads }); } renderHeader() { return (
); } renderBody() { return (
{this.renderTable()}
); } renderCell(content: JSX.Element | string, style: any, center?: boolean, header?: boolean) { let classNames: string = ''; classNames += center && ' forum-cell--center'; classNames += header ? ' forum-cell--header' : ' forum-cell--body'; return
{content}
; } renderThreadRows() { return this.state.threads.map((thread, index) => { return (
{this.renderCell('flag', { maxWidth: '50px' })} {this.renderCell({thread.title}, { minWidth: '200px' })} {this.renderCell({thread.user.battletag}, { maxWidth: '150px' })} {this.renderCell({thread.reply_count}, { maxWidth: '150px' }, true)} {this.renderCell({thread.view_count}, { maxWidth: '150px' }, true)} {this.renderCell(by {get(thread, 'last_reply.battletag')}, { maxWidth: '200px' })}
); }); } renderTable() { return (
Test
{this.renderCell(, { maxWidth: '50px' }, true, true)} {this.renderCell(Subject, { minWidth: '200px' }, false, true)} {this.renderCell(Author, { maxWidth: '150px' }, true, true)} {this.renderCell(Replies, { maxWidth: '150px' }, true, true)} {this.renderCell(Views, { maxWidth: '150px' }, true, true)} {this.renderCell(Last Post, { maxWidth: '200px' }, true, true)}
{this.renderThreadRows()}
); } render() { return ( {this.renderHeader()} {this.renderBody()} ); } }