1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 23:47:32 +02:00

Fix m.withAttr for input value, show search results, fix some old m.route code

TODO: Fix "SyntaxError: '> li:not(.Dropdown-header)' is not a valid selector" when hovering search results in navbar
This commit is contained in:
David Sevilla Martin
2019-10-22 19:05:51 -04:00
parent c037598537
commit b885346029
10 changed files with 37 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ import prop from 'mithril/stream';
export default () => { export default () => {
m.withAttr = (key: string, cb: Function) => function () { m.withAttr = (key: string, cb: Function) => function () {
cb(this.getAttribute(key)); cb(this.getAttribute(key) || this[key]);
}; };
m.prop = prop; m.prop = prop;

View File

@@ -16,6 +16,8 @@ export default class Forum extends Application {
'user.posts': { path: '/u/:username', component: PostsUserPage }, 'user.posts': { path: '/u/:username', component: PostsUserPage },
'user.discussions': { path: '/u/:username', component: PostsUserPage }, 'user.discussions': { path: '/u/:username', component: PostsUserPage },
'settings': { path: '/u/:username', component: PostsUserPage }, 'settings': { path: '/u/:username', component: PostsUserPage },
'discussion': { path: '/d/:id', IndexPage },
}; };
/** /**

View File

@@ -43,10 +43,10 @@ export default class DiscussionsSearchSource extends SearchSource {
return ( return (
<li className="DiscussionSearchResult" data-index={'discussions' + discussion.id()}> <li className="DiscussionSearchResult" data-index={'discussions' + discussion.id()}>
<a href={app.route.discussion(discussion, mostRelevantPost && mostRelevantPost.number())} config={m.route}> <m.route.Link href={app.route.discussion(discussion, mostRelevantPost && mostRelevantPost.number())}>
<div className="DiscussionSearchResult-title">{highlight(discussion.title(), query)}</div> <div className="DiscussionSearchResult-title">{highlight(discussion.title(), query)}</div>
{mostRelevantPost ? <div className="DiscussionSearchResult-excerpt">{highlight(mostRelevantPost.contentPlain(), query, 100)}</div> : ''} {mostRelevantPost ? <div className="DiscussionSearchResult-excerpt">{highlight(mostRelevantPost.contentPlain(), query, 100)}</div> : ''}
</a> </m.route.Link>
</li> </li>
); );
}) })

View File

@@ -76,12 +76,11 @@ export default class NotificationList extends Component {
<div className="NotificationGroup"> <div className="NotificationGroup">
{group.discussion {group.discussion
? ( ? (
<a className="NotificationGroup-header" <m.route.Link className="NotificationGroup-header"
href={app.route.discussion(group.discussion)} href={app.route.discussion(group.discussion)}>
config={m.route}>
{badges && badges.length ? <ul className="NotificationGroup-badges badges">{listItems(badges)}</ul> : ''} {badges && badges.length ? <ul className="NotificationGroup-badges badges">{listItems(badges)}</ul> : ''}
{group.discussion.title()} {group.discussion.title()}
</a> </m.route.Link>
) : ( ) : (
<div className="NotificationGroup-header"> <div className="NotificationGroup-header">
{app.forum.attribute('title')} {app.forum.attribute('title')}

View File

@@ -54,7 +54,7 @@ export default class NotificationsDropdown extends Dropdown {
} }
goToRoute() { goToRoute() {
m.route(app.route('notifications')); m.route.set(app.route('notifications'));
} }
getUnreadCount() { getUnreadCount() {

View File

@@ -33,7 +33,13 @@ export default class PostsUserPage extends UserPage {
oninit(vnode) { oninit(vnode) {
super.oninit(vnode); super.oninit(vnode);
this.loadUser(m.route.param('username')); this.loadUser(vnode.attrs.username);
}
onupdate(vnode) {
super.onupdate(vnode);
this.loadUser(vnode.attrs.username);
} }
content() { content() {
@@ -69,7 +75,7 @@ export default class PostsUserPage extends UserPage {
{this.posts.map(post => ( {this.posts.map(post => (
<li> <li>
<div className="PostsUserPage-discussion"> <div className="PostsUserPage-discussion">
{app.translator.trans('core.forum.user.in_discussion_text', {discussion: <a href={app.route.post(post)} oncreate={m.route}>{post.discussion().title()}</a>})} {app.translator.trans('core.forum.user.in_discussion_text', {discussion: <m.route.Link href={app.route.post(post)}>{post.discussion().title()}</m.route.Link>})}
</div> </div>
{CommentPost.component({post})} {CommentPost.component({post})}
</li> </li>

View File

@@ -185,7 +185,7 @@ export default class Search extends Component {
this.loadingSources = 0; this.loadingSources = 0;
if (this.value()) { if (this.value()) {
m.route(this.getItem(this.index).find('a').attr('href')); m.route.set(this.getItem(this.index).find('a').attr('href'));
} else { } else {
this.clear(); this.clear();
} }

View File

@@ -48,10 +48,10 @@ export default class UserCard extends Component<UserCardProps> {
{this.props.editable {this.props.editable
? [AvatarEditor.component({user, className: 'UserCard-avatar'}), username(user)] ? [AvatarEditor.component({user, className: 'UserCard-avatar'}), username(user)]
: ( : (
<a href={app.route.user(user)} oncreate={m.route}> <m.route.Link href={app.route.user(user)}>
<div className="UserCard-avatar">{avatar(user)}</div> <div className="UserCard-avatar">{avatar(user)}</div>
{username(user)} {username(user)}
</a> </m.route.Link>
)} )}
</h2> </h2>

View File

@@ -22,6 +22,11 @@ export default abstract class UserPage extends Page {
user: User; user: User;
bodyClass: string = 'App--user'; bodyClass: string = 'App--user';
/**
* The username of the currently loaded user
*/
username: string;
view() { view() {
return ( return (
<div className="UserPage"> <div className="UserPage">
@@ -54,7 +59,6 @@ export default abstract class UserPage extends Page {
*/ */
abstract content(); abstract content();
/** /**
* Initialize the component with a user, and trigger the loading of their * Initialize the component with a user, and trigger the loading of their
* activity feed. * activity feed.
@@ -74,6 +78,10 @@ export default abstract class UserPage extends Page {
loadUser(username: string) { loadUser(username: string) {
const lowercaseUsername = username.toLowerCase(); const lowercaseUsername = username.toLowerCase();
if (lowercaseUsername == this.username) return;
this.username = lowercaseUsername;
app.store.all('users').some(user => { app.store.all('users').some(user => {
if (user.username().toLowerCase() === lowercaseUsername && user.joinTime()) { if (user.username().toLowerCase() === lowercaseUsername && user.joinTime()) {
this.show(user); this.show(user);

View File

@@ -37,14 +37,20 @@ export default class UsersSearchSource extends SearchSource {
<li className="Dropdown-header">{app.translator.trans('core.forum.search.users_heading')}</li>, <li className="Dropdown-header">{app.translator.trans('core.forum.search.users_heading')}</li>,
results.map(user => { results.map(user => {
const name = username(user); const name = username(user);
if (!name.children) {
name.children = [name.text];
delete name.text;
}
name.children[0] = highlight(name.children[0], query); name.children[0] = highlight(name.children[0], query);
return ( return (
<li className="UserSearchResult" data-index={'users' + user.id()}> <li className="UserSearchResult" data-index={'users' + user.id()}>
<a href={app.route.user(user)} oncreate={m.route}> <m.route.Link href={app.route.user(user)}>
{avatar(user)} {avatar(user)}
{name} {name}
</a> </m.route.Link>
</li> </li>
); );
}) })