client/posts: remember search for prev/next post
This commit is contained in:
parent
4ec826d0a5
commit
39c0c4f338
3 changed files with 37 additions and 12 deletions
|
@ -3,7 +3,11 @@
|
||||||
<nav class='buttons'>
|
<nav class='buttons'>
|
||||||
<article class='next-post'>
|
<article class='next-post'>
|
||||||
<% if (ctx.nextPostId) { %>
|
<% if (ctx.nextPostId) { %>
|
||||||
|
<% if (ctx.searchQuery && ctx.searchQuery.text) { %>
|
||||||
|
<a href='/post/<%= ctx.nextPostId %>/text=<%= ctx.searchQuery.text %>'>
|
||||||
|
<% } else { %>
|
||||||
<a href='/post/<%= ctx.nextPostId %>'>
|
<a href='/post/<%= ctx.nextPostId %>'>
|
||||||
|
<% } %>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<a class='inactive'>
|
<a class='inactive'>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
@ -13,7 +17,11 @@
|
||||||
</article>
|
</article>
|
||||||
<article class='previous-post'>
|
<article class='previous-post'>
|
||||||
<% if (ctx.prevPostId) { %>
|
<% if (ctx.prevPostId) { %>
|
||||||
|
<% if (ctx.searchQuery && ctx.searchQuery.text) { %>
|
||||||
|
<a href='/post/<%= ctx.prevPostId %>/text=<%= ctx.searchQuery.text %>'>
|
||||||
|
<% } else { %>
|
||||||
<a href='/post/<%= ctx.prevPostId %>'>
|
<a href='/post/<%= ctx.prevPostId %>'>
|
||||||
|
<% } %>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<a class='inactive'>
|
<a class='inactive'>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
@ -29,7 +37,11 @@
|
||||||
</a>
|
</a>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<% if (ctx.canEditPosts) { %>
|
<% if (ctx.canEditPosts) { %>
|
||||||
|
<% if (ctx.searchQuery && ctx.searchQuery.text) { %>
|
||||||
|
<a href='/post/<%= ctx.post.id %>/edit/text=<%= ctx.searchQuery.text %>'>
|
||||||
|
<% } else { %>
|
||||||
<a href='/post/<%= ctx.post.id %>/edit'>
|
<a href='/post/<%= ctx.post.id %>/edit'>
|
||||||
|
<% } %>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<a class='inactive'>
|
<a class='inactive'>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -4,7 +4,11 @@
|
||||||
<% for (let post of ctx.results) { %>
|
<% for (let post of ctx.results) { %>
|
||||||
<li>
|
<li>
|
||||||
<% if (ctx.canViewPosts) { %>
|
<% if (ctx.canViewPosts) { %>
|
||||||
|
<% if (ctx.searchQuery && ctx.searchQuery.text) { %>
|
||||||
|
<a href='/post/<%= post.id %>/text=<%= ctx.searchQuery.text %>' title='@<%= post.id %> (<%= post.type %>) Tags: <%= post.tags.map(tag => '#' + tag).join(' ') %>'>
|
||||||
|
<% } else { %>
|
||||||
<a href='/post/<%= post.id %>' title='@<%= post.id %> (<%= post.type %>) Tags: <%= post.tags.map(tag => '#' + tag).join(' ') %>'>
|
<a href='/post/<%= post.id %>' title='@<%= post.id %> (<%= post.type %>) Tags: <%= post.tags.map(tag => '#' + tag).join(' ') %>'>
|
||||||
|
<% } %>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<a>
|
<a>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -10,13 +10,14 @@ const PostView = require('../views/post_view.js');
|
||||||
const EmptyView = require('../views/empty_view.js');
|
const EmptyView = require('../views/empty_view.js');
|
||||||
|
|
||||||
class PostController {
|
class PostController {
|
||||||
constructor(id, editMode) {
|
constructor(id, editMode, searchQuery) {
|
||||||
topNavigation.activate('posts');
|
topNavigation.activate('posts');
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
Post.get(id),
|
Post.get(id),
|
||||||
api.get(`/post/${id}/around?fields=id&query=` +
|
api.get(`/post/${id}/around?fields=id&query=` +
|
||||||
this._decorateSearchQuery('')),
|
this._decorateSearchQuery(
|
||||||
|
searchQuery ? searchQuery.text : '')),
|
||||||
]).then(responses => {
|
]).then(responses => {
|
||||||
const [post, aroundResponse] = responses;
|
const [post, aroundResponse] = responses;
|
||||||
this._post = post;
|
this._post = post;
|
||||||
|
@ -28,6 +29,7 @@ class PostController {
|
||||||
canEditPosts: api.hasPrivilege('posts:edit'),
|
canEditPosts: api.hasPrivilege('posts:edit'),
|
||||||
canListComments: api.hasPrivilege('comments:list'),
|
canListComments: api.hasPrivilege('comments:list'),
|
||||||
canCreateComments: api.hasPrivilege('comments:create'),
|
canCreateComments: api.hasPrivilege('comments:create'),
|
||||||
|
searchQuery: searchQuery,
|
||||||
});
|
});
|
||||||
if (this._view.sidebarControl) {
|
if (this._view.sidebarControl) {
|
||||||
this._view.sidebarControl.addEventListener(
|
this._view.sidebarControl.addEventListener(
|
||||||
|
@ -138,10 +140,17 @@ class PostController {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = router => {
|
module.exports = router => {
|
||||||
router.enter('/post/:id', (ctx, next) => {
|
router.enter('/post/:id/edit/:query?',
|
||||||
ctx.controller = new PostController(ctx.params.id, false);
|
(ctx, next) => { misc.parseSearchQueryRoute(ctx, next); },
|
||||||
|
(ctx, next) => {
|
||||||
|
ctx.controller = new PostController(
|
||||||
|
ctx.params.id, true, ctx.searchQuery);
|
||||||
});
|
});
|
||||||
router.enter('/post/:id/edit', (ctx, next) => {
|
router.enter(
|
||||||
ctx.controller = new PostController(ctx.params.id, true);
|
'/post/:id/:query?',
|
||||||
|
(ctx, next) => { misc.parseSearchQueryRoute(ctx, next); },
|
||||||
|
(ctx, next) => {
|
||||||
|
ctx.controller = new PostController(
|
||||||
|
ctx.params.id, false, ctx.searchQuery);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue