mirror of
https://github.com/flarum/core.git
synced 2025-08-07 08:56:38 +02:00
Fix preview functionality of ReplyComposer and EditPostComposer
- options= true means that the init method of DiscussionPage will not be recalled (as per patchMithril - DiscussionPage now caches the previous route, and compares it to the current one onupdate. If the route has change. We update this cached prevRoute in positionChanged to avoid unneessary goToNumber calls.
This commit is contained in:
committed by
Franz Liedke
parent
090df13e7f
commit
ca0f8f2d72
@@ -47,29 +47,11 @@ export default class DiscussionPage extends Page {
|
||||
app.history.push('discussion');
|
||||
|
||||
this.bodyClass = 'App--discussion';
|
||||
|
||||
this.prevRoute = m.route.get();
|
||||
}
|
||||
|
||||
onremove(vnode) {
|
||||
// If we have routed to the same discussion as we were viewing previously,
|
||||
// cancel the unloading of this controller and instead prompt the post
|
||||
// stream to jump to the new 'near' param.
|
||||
if (this.discussion) {
|
||||
const idParam = m.route.param('id');
|
||||
|
||||
if (idParam && idParam.split('-')[0] === this.discussion.id()) {
|
||||
//e.preventDefault();
|
||||
|
||||
const near = m.route.param('near') || '1';
|
||||
|
||||
if (near !== String(this.near)) {
|
||||
this.stream.goToNumber(near);
|
||||
}
|
||||
|
||||
this.near = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If we are indeed navigating away from this discussion, then disable the
|
||||
// discussion list pane. Also, if we're composing a reply to this
|
||||
// discussion, minimize the composer – unless it's empty, in which case
|
||||
@@ -121,6 +103,29 @@ export default class DiscussionPage extends Page {
|
||||
}
|
||||
}
|
||||
|
||||
onupdate(vnode) {
|
||||
if (m.route.get() !== this.prevRoute) {
|
||||
this.prevRoute = m.route.get();
|
||||
|
||||
// If we have routed to the same discussion as we were viewing previously,
|
||||
// cancel the unloading of this controller and instead prompt the post
|
||||
// stream to jump to the new 'near' param.
|
||||
if (this.discussion) {
|
||||
const idParam = m.route.param('id');
|
||||
|
||||
if (idParam && idParam.split('-')[0] === this.discussion.id()) {
|
||||
const near = m.route.param('near') || '1';
|
||||
|
||||
if (near !== String(this.near)) {
|
||||
this.stream.goToNumber(near);
|
||||
}
|
||||
|
||||
this.near = near;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the discussion from the API or use the preloaded one.
|
||||
*/
|
||||
@@ -245,6 +250,7 @@ export default class DiscussionPage extends Page {
|
||||
// replace it into the window's history and our own history stack.
|
||||
const url = app.route.discussion(discussion, (this.near = startNumber));
|
||||
|
||||
this.prevRoute = url;
|
||||
m.route.set(url);
|
||||
window.history.replaceState(null, document.title, url);
|
||||
|
||||
|
@@ -39,7 +39,7 @@ export default class EditPostComposer extends ComposerBody {
|
||||
'title',
|
||||
<h3>
|
||||
{icon('fas fa-pencil-alt')}{' '}
|
||||
<a route={app.route.discussion(post.discussion(), post.number())} onclick={minimizeComposerIfFullScreen}>
|
||||
<a route={app.route.discussion(post.discussion(), post.number())} onclick={minimizeComposerIfFullScreen} options={true}>
|
||||
{app.translator.trans('core.forum.composer_edit.post_link', { number: post.number(), discussion: post.discussion().title() })}
|
||||
</a>
|
||||
</h3>
|
||||
|
@@ -36,7 +36,7 @@ export default class ReplyComposer extends ComposerBody {
|
||||
'title',
|
||||
<h3>
|
||||
{icon('fas fa-reply')}{' '}
|
||||
<a route={app.route.discussion(discussion)} onclick={minimizeComposerIfFullScreen}>
|
||||
<a route={app.route.discussion(discussion)} onclick={minimizeComposerIfFullScreen} options={true}>
|
||||
{discussion.title()}
|
||||
{''}
|
||||
</a>
|
||||
|
Reference in New Issue
Block a user