1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 01:16:52 +02:00

replace config and href with route on Notification and NotificationList

This commit is contained in:
Alexander Skvortsov
2020-08-10 00:42:49 -04:00
committed by Franz Liedke
parent 16a6f82e8f
commit 5d34124a02
2 changed files with 23 additions and 22 deletions

View File

@@ -22,12 +22,8 @@ export default class Notification extends Component {
return ( return (
<a <a
className={'Notification Notification--' + notification.contentType() + ' ' + (!notification.isRead() ? 'unread' : '')} className={'Notification Notification--' + notification.contentType() + ' ' + (!notification.isRead() ? 'unread' : '')}
href={href} route={href}
config={function (element, isInitialized) { onclick={this.markAsRead.bind(this)}
if (href.indexOf('://') === -1) m.route.apply(this, arguments);
if (!isInitialized) $(element).click(this.markAsRead.bind(this));
}}
> >
{!notification.isRead() && {!notification.isRead() &&
Button.component({ Button.component({

View File

@@ -63,7 +63,7 @@ export default class NotificationList extends Component {
return ( return (
<div className="NotificationGroup"> <div className="NotificationGroup">
{group.discussion ? ( {group.discussion ? (
<a className="NotificationGroup-header" href={app.route.discussion(group.discussion)} config={m.route}> <a className="NotificationGroup-header" route={app.route.discussion(group.discussion)}>
{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> </a>
@@ -97,26 +97,31 @@ export default class NotificationList extends Component {
oncreate(vnode) { oncreate(vnode) {
super.oncreate(vnode); super.oncreate(vnode);
const $notifications = this.$('.NotificationList-content');
const $scrollParent = $notifications.css('overflow') === 'auto' ? $notifications : $(window);
$scrollParent.on('scroll', this.scrollHandler.bind(this));
}
onremove() {
const $notifications = this.$('.NotificationList-content');
const $scrollParent = $notifications.css('overflow') === 'auto' ? $notifications : $(window);
$scrollParent.off('scroll', this.scrollHandler.bind(this));
}
scrollHandler() {
const state = this.attrs.state; const state = this.attrs.state;
const scrollTop = $scrollParent.scrollTop();
const viewportHeight = $scrollParent.height();
const $notifications = this.$('.NotificationList-content'); const $notifications = this.$('.NotificationList-content');
const $scrollParent = $notifications.css('overflow') === 'auto' ? $notifications : $(window); const $scrollParent = $notifications.css('overflow') === 'auto' ? $notifications : $(window);
const scrollHandler = () => { const contentTop = $scrollParent === $notifications ? 0 : $notifications.offset().top;
const scrollTop = $scrollParent.scrollTop(); const contentHeight = $notifications[0].scrollHeight;
const viewportHeight = $scrollParent.height();
const contentTop = $scrollParent === $notifications ? 0 : $notifications.offset().top;
const contentHeight = $notifications[0].scrollHeight;
if (state.hasMoreResults() && !state.isLoading() && scrollTop + viewportHeight >= contentTop + contentHeight) { if (state.hasMoreResults() && !state.isLoading() && scrollTop + viewportHeight >= contentTop + contentHeight) {
state.loadMore(); state.loadMore();
} }
};
$scrollParent.on('scroll', scrollHandler);
context.onunload = () => {
$scrollParent.off('scroll', scrollHandler);
};
} }
} }