diff --git a/client/app/model/index.ts b/client/app/model/index.ts index 6ba47fd..49d7b20 100644 --- a/client/app/model/index.ts +++ b/client/app/model/index.ts @@ -1,2 +1,4 @@ export * from './category'; +export * from './reply'; +export * from './thread'; export * from './user'; diff --git a/client/app/model/reply.ts b/client/app/model/reply.ts new file mode 100644 index 0000000..244c875 --- /dev/null +++ b/client/app/model/reply.ts @@ -0,0 +1,10 @@ +export interface RepyModel { + content: string; + edited: boolean; + id: number; + inserted_at: string; + quote: boolean; + thread_id: number; + updated_at: string; + user_id: number; +} diff --git a/client/app/model/thread.ts b/client/app/model/thread.ts new file mode 100644 index 0000000..cb96a26 --- /dev/null +++ b/client/app/model/thread.ts @@ -0,0 +1,20 @@ +import { RepyModel } from './reply'; + +export interface ThreadModel { + category_id: number; + content: string; + title: string; + edited: boolean; + id: number; + inserted_at: string; + last_reply: { id: number; battletag: string }; + last_reply_id: number; + locked: boolean; + replies: RepyModel[]; + reply_count: number; + sticky: boolean; + updated_at: string; + user: { id: number; battletag: string }; + user_id: number; + view_count: number; +} diff --git a/client/app/pages/forum/forum.tsx b/client/app/pages/forum/forum.tsx index 57f70fe..1b3923f 100644 --- a/client/app/pages/forum/forum.tsx +++ b/client/app/pages/forum/forum.tsx @@ -1,18 +1,32 @@ import React from 'react'; import { Link, RouteComponentProps } from 'react-router-dom'; +import { get } from 'lodash'; +import { ThreadService } from '../../services'; import { LoginButton } from '../../components'; +import { ThreadModel } from '../../model'; import './forum.scss'; interface Props extends RouteComponentProps {} -interface State {} +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() { @@ -59,15 +73,15 @@ export class Forum extends React.Component { } renderThreadRows() { - return Array(40).fill('test 123').map((thread, index) => { + return this.state.threads.map((thread, index) => { return (
- {this.renderCell(thread, { maxWidth: '50px' })} - {this.renderCell(This is a test subject that could be really long, { minWidth: '200px' })} - {this.renderCell(thread, { maxWidth: '150px' })} - {this.renderCell(thread, { maxWidth: '150px' }, true)} - {this.renderCell(thread, { maxWidth: '150px' }, true)} - {this.renderCell(by thread, { maxWidth: '200px' })} + {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' })}
); }); diff --git a/client/app/pages/index.ts b/client/app/pages/index.ts index 45a4002..6bba6e4 100644 --- a/client/app/pages/index.ts +++ b/client/app/pages/index.ts @@ -3,5 +3,6 @@ export * from './home/home'; export * from './not-found/not-found'; export * from './oauth/oauth'; export * from './realms/realms'; +export * from './thread/thread'; export * from './user-account/user-account'; diff --git a/client/app/pages/thread/thread.tsx b/client/app/pages/thread/thread.tsx new file mode 100644 index 0000000..afc3569 --- /dev/null +++ b/client/app/pages/thread/thread.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { RouteComponentProps } from 'react-router-dom'; +import { ThreadService } from '../../services'; + +interface Props extends RouteComponentProps {} + +interface State {} + +export class Thread extends React.Component { + + componentDidMount() { + this.getThreads(); + } + + private async getThreads() { + const thread = await ThreadService.getThread(this.props.match.params['id']); + console.log(thread); + } + + render() { + return ( +
+ ); + } +} diff --git a/client/app/routes.tsx b/client/app/routes.tsx index b0f15e4..1a5947a 100644 --- a/client/app/routes.tsx +++ b/client/app/routes.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { BrowserRouter, Route, Switch } from 'react-router-dom'; import { Provider } from 'mobx-react'; import { Footer, Header } from './components'; -import { Forum, Home, NotFound, Oauth, Realms, UserAccount } from './pages'; +import { Forum, Home, NotFound, Oauth, Realms, Thread, UserAccount } from './pages'; import { stores } from './stores/stores'; // styling @@ -26,6 +26,7 @@ export class Routes extends React.Component { +