1
0
mirror of https://github.com/flarum/core.git synced 2025-07-31 13:40:20 +02:00

Merge branch 'evented-api'

This commit is contained in:
Toby Zerner
2015-07-21 10:40:38 +09:30
175 changed files with 1626 additions and 1453 deletions

View File

@@ -31,7 +31,7 @@ export default class DiscussionHero extends Component {
const badges = discussion.badges().toArray();
if (badges.length) {
items.add('badges', <ul className="DiscussionHero-badges">{listItems(badges)}</ul>);
items.add('badges', <ul className="DiscussionHero-badges badges">{listItems(badges)}</ul>);
}
items.add('title', <h2 className="DiscussionHero-title">{discussion.title()}</h2>);

View File

@@ -82,8 +82,9 @@ export default class DiscussionList extends Component {
* discussion results.
*
* @return {Object}
* @api
*/
params() {
requestParams() {
const params = Object.assign({include: ['startUser', 'lastUser']}, this.props.params);
params.sort = this.sortMap()[params.sort];
@@ -111,8 +112,8 @@ export default class DiscussionList extends Component {
if (this.props.params.q) {
map.relevance = '';
}
map.recent = '-lastTime';
map.replies = '-commentsCount';
map.latest = '-lastTime';
map.top = '-commentsCount';
map.newest = '-startTime';
map.oldest = '+startTime';
@@ -150,7 +151,7 @@ export default class DiscussionList extends Component {
return m.deferred().resolve(preloadedDiscussions).promise;
}
const params = this.params();
const params = this.requestParams();
params.page = {offset};
params.include = params.include.join(',');

View File

@@ -1,5 +1,4 @@
import Notification from 'flarum/components/Notification';
import username from 'flarum/helpers/username';
/**
* The `DiscussionRenamedNotification` component displays a notification which

View File

@@ -13,15 +13,18 @@ export default class DiscussionRenamedPost extends EventPost {
return 'pencil';
}
description() {
descriptionKey() {
return 'core.discussion_renamed_post';
}
descriptionData() {
const post = this.props.post;
const oldTitle = post.content()[0];
const newTitle = post.content()[1];
return app.trans('core.discussion_renamed', {
user: this.props.post.user(),
return {
old: <strong className="DiscussionRenamedPost-old">{oldTitle}</strong>,
new: <strong className="DiscussionRenamedPost-new">{newTitle}</strong>
});
};
}
}

View File

@@ -1,4 +1,5 @@
import Post from 'flarum/components/Post';
import { ucfirst } from 'flarum/utils/string';
import usernameHelper from 'flarum/helpers/username';
import icon from 'flarum/helpers/icon';
@@ -16,19 +17,24 @@ import icon from 'flarum/helpers/icon';
export default class EventPost extends Post {
attrs() {
return {
className: 'EventPost EventPost--' + this.props.post.contentType()
className: 'EventPost ' + ucfirst(this.props.post.contentType()) + 'Post'
};
}
content() {
const user = this.props.post.user();
const username = usernameHelper(user);
const data = Object.assign(this.descriptionData(), {
user,
username: user
? <a className="EventPost-user" href={app.route.user(user)} config={m.route}>{username}</a>
: username
});
return [
icon(this.icon(), {className: 'EventPost-icon'}),
<div class="EventPost-info">
{user ? <a className="EventPost-user" href={app.route.user(user)} config={m.route}>{username}</a> : username}{' '}
{this.description()}
{app.trans(this.descriptionKey(), data)}
</div>
];
}
@@ -39,13 +45,24 @@ export default class EventPost extends Post {
* @return {String}
*/
icon() {
return '';
}
/**
* Get the description of the event.
* Get the translation key for the description of the event.
*
* @return {VirtualElement}
* @return {String}
*/
description() {
descriptionKey() {
return '';
}
/**
* Get the translation data for the description of the event.
*
* @return {Object}
*/
descriptionData() {
return {};
}
}

View File

@@ -74,7 +74,7 @@ export default class NotificationGrid extends Component {
{this.types.map(type => (
<tr>
<td className="NotificationGrid-groupToggle" onclick={this.toggleType.bind(this, type.name)}>
{type.label}
{icon(type.icon)} {type.label}
</td>
{this.methods.map(method => (
<td className="NotificationGrid-checkbox">
@@ -181,7 +181,8 @@ export default class NotificationGrid extends Component {
items.add('discussionRenamed', {
name: 'discussionRenamed',
label: [icon('pencil'), ' ', app.trans('core.notify_discussion_renamed')]
icon: 'pencil',
label: app.trans('core.notify_discussion_renamed')
});
return items;

View File

@@ -167,7 +167,11 @@ class PostStream extends mixin(Component, evented) {
posts() {
return this.discussion.postIds()
.slice(this.visibleStart, this.visibleEnd)
.map(id => app.store.getById('posts', id));
.map(id => {
const post = app.store.getById('posts', id);
return post && post.discussion() ? post : null;
});
}
view() {
@@ -365,10 +369,10 @@ class PostStream extends mixin(Component, evented) {
this.discussion.postIds().slice(start, end).forEach(id => {
const post = app.store.getById('posts', id);
if (!post) {
loadIds.push(id);
} else {
if (post && post.discussion()) {
loaded.push(post);
} else {
loadIds.push(id);
}
});