import React from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { get, map } from 'lodash'; import marked from 'marked'; import { ThreadService } from '../../services'; import { 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['threadId']); thread.replies = map([thread as any, ...thread.replies], (reply) => { // add the thread topic to the front of the list reply.content = marked(reply.content, { sanitize: true }); return reply; }); 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}
); }); } 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' }} />
); } }