client/posts: remember search for prev/next post

This commit is contained in:
rr- 2016-06-18 11:39:54 +02:00
parent 4ec826d0a5
commit 39c0c4f338
3 changed files with 37 additions and 12 deletions

View file

@ -3,7 +3,11 @@
<nav class='buttons'>
<article class='next-post'>
<% if (ctx.nextPostId) { %>
<% if (ctx.searchQuery && ctx.searchQuery.text) { %>
<a href='/post/<%= ctx.nextPostId %>/text=<%= ctx.searchQuery.text %>'>
<% } else { %>
<a href='/post/<%= ctx.nextPostId %>'>
<% } %>
<% } else { %>
<a class='inactive'>
<% } %>
@ -13,7 +17,11 @@
</article>
<article class='previous-post'>
<% if (ctx.prevPostId) { %>
<% if (ctx.searchQuery && ctx.searchQuery.text) { %>
<a href='/post/<%= ctx.prevPostId %>/text=<%= ctx.searchQuery.text %>'>
<% } else { %>
<a href='/post/<%= ctx.prevPostId %>'>
<% } %>
<% } else { %>
<a class='inactive'>
<% } %>
@ -29,7 +37,11 @@
</a>
<% } else { %>
<% 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'>
<% } %>
<% } else { %>
<a class='inactive'>
<% } %>

View file

@ -4,7 +4,11 @@
<% for (let post of ctx.results) { %>
<li>
<% if (ctx.canViewPosts) { %>
<% if (ctx.searchQuery && ctx.searchQuery.text) { %>
<a href='/post/<%= post.id %>/text=<%= ctx.searchQuery.text %>' title='@<%= post.id %> (<%= post.type %>)&#10;&#10;Tags: <%= post.tags.map(tag => '#' + tag).join(' ') %>'>
<% } else { %>
<a href='/post/<%= post.id %>' title='@<%= post.id %> (<%= post.type %>)&#10;&#10;Tags: <%= post.tags.map(tag => '#' + tag).join(' ') %>'>
<% } %>
<% } else { %>
<a>
<% } %>

View file

@ -10,13 +10,14 @@ const PostView = require('../views/post_view.js');
const EmptyView = require('../views/empty_view.js');
class PostController {
constructor(id, editMode) {
constructor(id, editMode, searchQuery) {
topNavigation.activate('posts');
Promise.all([
Post.get(id),
api.get(`/post/${id}/around?fields=id&query=` +
this._decorateSearchQuery('')),
this._decorateSearchQuery(
searchQuery ? searchQuery.text : '')),
]).then(responses => {
const [post, aroundResponse] = responses;
this._post = post;
@ -28,6 +29,7 @@ class PostController {
canEditPosts: api.hasPrivilege('posts:edit'),
canListComments: api.hasPrivilege('comments:list'),
canCreateComments: api.hasPrivilege('comments:create'),
searchQuery: searchQuery,
});
if (this._view.sidebarControl) {
this._view.sidebarControl.addEventListener(
@ -138,10 +140,17 @@ class PostController {
}
module.exports = router => {
router.enter('/post/:id', (ctx, next) => {
ctx.controller = new PostController(ctx.params.id, false);
router.enter('/post/:id/edit/:query?',
(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) => {
ctx.controller = new PostController(ctx.params.id, true);
router.enter(
'/post/:id/:query?',
(ctx, next) => { misc.parseSearchQueryRoute(ctx, next); },
(ctx, next) => {
ctx.controller = new PostController(
ctx.params.id, false, ctx.searchQuery);
});
};