a few fixes here & there - cache typehinting moved to Forum.ts, don't use button link in PostUser

This commit is contained in:
David Sevilla Martin 2020-02-07 09:36:38 -05:00
parent 2a66dc5572
commit f24aafd47b
No known key found for this signature in database
GPG Key ID: F764F1417E16B15F
6 changed files with 21 additions and 25 deletions

View File

@ -67,9 +67,7 @@ export default abstract class Application {
* A local cache that can be used to store data at the application level, so
* that is persists between different routes.
*/
cache = {
notifications: null,
};
cache: { [key: string]: any } = {};
routes = {};
@ -243,10 +241,6 @@ export default abstract class Application {
// Now make the request. If it's a failure, inspect the error that was
// returned and show an alert containing its contents.
// const deferred = m.deferred();
// return new Promise((resolve, reject) => )
return m.request(options).then(
res => res,
error => {

View File

@ -12,6 +12,8 @@ export default class Model {
*/
data: any;
payload: any;
/**
* The time at which the model's data was last updated. Watching the value
* of this property is a fast way to retain/cache a subtree if data hasn't

View File

@ -17,6 +17,7 @@ import CommentPost from './components/CommentPost';
import User from '../common/models/User';
import Post from '../common/models/Post';
import Discussion from '../common/models/Discussion';
import Notification from '../common/models/Notification';
export default class Forum extends Application {
routes = {
@ -40,6 +41,12 @@ export default class Forum extends Application {
*/
history: History = new History();
cache: {
notifications?: Notification[];
discussionList?: DiscussionList;
[key: string]: any;
} = {};
postComponents = {
comment: CommentPost,
// discussionRenamed: DiscussionRenamedPost

View File

@ -35,21 +35,14 @@ export default class CommentPost extends Post {
}
content() {
// Note: we avoid using JSX for the <ul> below because it results in some
// weirdness in Mithril.js 0.1.x (see flarum/core#975). This workaround can
// be reverted when we upgrade to Mithril 1.0.
return super
.content()
.concat([
<header className="Post-header">{m('ul', listItems(this.headerItems().toArray()))}</header>,
<div className="Post-body">
{this.isEditing() ? (
<div className="Post-preview" config={this.configPreview.bind(this)} />
) : (
m.trust(this.props.post.contentHtml())
)}
</div>,
]);
return super.content().concat([
<header className="Post-header">
<ul>{listItems(this.headerItems().toArray())}</ul>
</header>,
<div className="Post-body">
{this.isEditing() ? <div className="Post-preview" config={this.configPreview.bind(this)} /> : m.trust(this.props.post.contentHtml())}
</div>,
]);
}
onupdate(vnode) {

View File

@ -43,11 +43,11 @@ export default class PostUser extends Component<PostProps> {
return (
<div className="PostUser">
<h3>
<LinkButton href={app.route.user(user)}>
<m.route.Link href={app.route.user(user)}>
{avatar(user, { className: 'PostUser-avatar' })}
{userOnline(user)}
{username(user)}
</LinkButton>
</m.route.Link>
</h3>
<ul className="PostUser-badges badges">{listItems(user.badges().toArray())}</ul>
{card}

View File

@ -43,7 +43,7 @@ export default class History {
* @param {String} [url] The URL of the route. The current URL will be used if
* not provided.
*/
push(name: string, title: string, url: string = m.route.get()) {
push(name: string, title?: string, url: string = m.route.get()) {
// If we're pushing an item with the same name as second-to-top item in the
// stack, we will assume that the user has clicked the 'back' button in
// their browser. In this case, we don't want to push a new item, so we will