import React from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { get } from 'lodash'; import { ThreadService } from '../../services'; import { ForumNav, Portrait, ScrollToTop } from '../../components'; import { ThreadModel } from '../../model'; import './thread.scss'; interface Props extends RouteComponentProps {} interface State { thread?: ThreadModel; } export class Thread extends React.Component { constructor(props: Props) { super(props); this.state = {}; } componentDidMount() { this.getThreads(); } private async getThreads() { const thread = await ThreadService.getThread(this.props.match.params['id']); thread.replies = [thread as any, ...thread.replies]; // add the thread topic to the front of the list this.setState({ thread }); } renderReplies(): any { return this.state.thread!.replies.map((reply, index) => { return (
Tyren
Blizzard Poster
{`${index + 1}. `}{this.state.thread!.title} | {reply.inserted_at}
{/* TODO: xss sanitization */}
{reply.content}
); }); } private navigateForumIndex() { this.props.history.push(`/f/${this.state.thread!.category_id}`); } render() { const replies = get(this.state, 'thread.replies'); return (
Topic: | 12/20/2005 1:11:44 AM PST
this.navigateForumIndex()} style={{ cursor: 'pointer' }} />
{replies && this.renderReplies()}
this.navigateForumIndex()} style={{ cursor: 'pointer', float: 'right' }} />
); } }