1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 17:36:38 +02:00

update IndexPage to clear discussions & refresh params using custom route solution

This commit is contained in:
David Sevilla Martin
2020-08-11 11:44:50 -04:00
committed by Franz Liedke
parent b1d948becc
commit b0cbe277c2
2 changed files with 23 additions and 10 deletions

View File

@@ -29,14 +29,6 @@ export default class IndexPage extends Page {
this.lastDiscussion = app.previous.get('discussion');
}
// If the user is coming from the discussion list, then they have either
// just switched one of the parameters (filter, sort, search) or they
// probably want to refresh the results. We will clear the discussion list
// cache so that results are reloaded.
if (app.previous.matches(IndexPage)) {
app.discussions.clear();
}
app.discussions.refreshParams(app.search.params());
app.history.push('index', app.translator.trans('core.forum.header.back_to_index_tooltip'));
@@ -44,6 +36,18 @@ export default class IndexPage extends Page {
this.bodyClass = 'App--index';
}
static onroutematch() {
// If the user is coming from the discussion list, then they have either
// just switched one of the parameters (filter, sort, search) or they
// probably want to refresh the results. We will clear the discussion list
// cache so that results are reloaded.
if (app.current.matches(IndexPage)) {
app.discussions.clear();
app.discussions.refreshParams(app.search.params());
}
}
view() {
return (
<div className="IndexPage">

View File

@@ -5,6 +5,15 @@ import DiscussionsUserPage from './components/DiscussionsUserPage';
import SettingsPage from './components/SettingsPage';
import NotificationsPage from './components/NotificationsPage';
const match = (component) => ({
onmatch: () => {
component.onroutematch();
return component;
},
render: (vnode) => vnode,
});
/**
* The `routes` initializer defines the forum app's routes.
*
@@ -12,7 +21,7 @@ import NotificationsPage from './components/NotificationsPage';
*/
export default function (app) {
app.routes = {
index: { path: '/all', component: IndexPage },
index: { path: '/all', component: match(IndexPage) },
discussion: { path: '/d/:id', component: DiscussionPage },
'discussion.near': { path: '/d/:id/:near', component: DiscussionPage },
@@ -24,7 +33,7 @@ export default function (app) {
settings: { path: '/settings', component: SettingsPage },
notifications: { path: '/notifications', component: NotificationsPage },
'index.filter': { path: '/:filter', component: IndexPage },
'index.filter': { path: '/:filter', component: match(IndexPage) },
};
/**