Skip to content

Commit

Permalink
Use ItemList for DiscussionPage content (#3004)
Browse files Browse the repository at this point in the history
* Use ItemList for DiscussionPage content

* Don't import Mithril
  • Loading branch information
davwheat authored Aug 21, 2021
1 parent b8754c7 commit 656cc35
Showing 1 changed file with 75 additions and 23 deletions.
98 changes: 75 additions & 23 deletions js/src/forum/components/DiscussionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,88 @@ export default class DiscussionPage extends Page {
}

view() {
const discussion = this.discussion;

return (
<div className="DiscussionPage">
<DiscussionListPane state={app.discussions} />
<div className="DiscussionPage-discussion">
{discussion ? (
[
DiscussionHero.component({ discussion }),
<div className="container">
<nav className="DiscussionPage-nav">
<ul>{listItems(this.sidebarItems().toArray())}</ul>
</nav>
<div className="DiscussionPage-stream">
{PostStream.component({
discussion,
stream: this.stream,
onPositionChange: this.positionChanged.bind(this),
})}
</div>
</div>,
]
) : (
<LoadingIndicator />
)}
</div>
<div className="DiscussionPage-discussion">{this.discussion ? this.pageContent().toArray() : this.loadingItems().toArray()}</div>
</div>
);
}

/**
* List of components shown while the discussion is loading.
*
* @returns {ItemList}
*/
loadingItems() {
const items = new ItemList();

items.add('spinner', <LoadingIndicator />, 100);

return items;
}

/**
* Function that renders the `sidebarItems` ItemList.
*
* @returns {import('mithril').Children}
*/
sidebar() {
return (
<nav className="DiscussionPage-nav">
<ul>{listItems(this.sidebarItems().toArray())}</ul>
</nav>
);
}

/**
* Renders the discussion's hero.
*
* @returns {import('mithril').Children}
*/
hero() {
return <DiscussionHero discussion={this.discussion} />;
}

/**
* List of items rendered as the main page content.
*
* @returns {ItemList}
*/
pageContent() {
const items = new ItemList();

items.add('hero', this.hero(), 100);
items.add('main', <div className="container">{this.mainContent().toArray()}</div>, 10);

return items;
}

/**
* List of items rendered inside the main page content container.
*
* @returns {ItemList}
*/
mainContent() {
const items = new ItemList();

items.add('sidebar', this.sidebar(), 100);

items.add(
'poststream',
<div className="DiscussionPage-stream">
{PostStream.component({
discussion,
stream: this.stream,
onPositionChange: this.positionChanged.bind(this),
})}
</div>,
10
);

return items;
}

/**
* Load the discussion from the API or use the preloaded one.
*/
Expand Down

0 comments on commit 656cc35

Please sign in to comment.