client/comments: add global comment list
This commit is contained in:
parent
a67db59d99
commit
1e48140b00
9 changed files with 109 additions and 10 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
.comments>ul
|
.comments>ul
|
||||||
list-style-type: none
|
list-style-type: none
|
||||||
margin: 1em 0
|
margin: 0 0 2em 0
|
||||||
padding: 0
|
padding: 0
|
||||||
|
|
||||||
.comment
|
.comment
|
||||||
|
@ -16,6 +16,8 @@
|
||||||
display: none
|
display: none
|
||||||
.tabs .edit.tab
|
.tabs .edit.tab
|
||||||
display: none
|
display: none
|
||||||
|
.content
|
||||||
|
margin-left: 0.5em
|
||||||
&.editing
|
&.editing
|
||||||
.tab:not(.active)
|
.tab:not(.active)
|
||||||
display: none
|
display: none
|
||||||
|
@ -134,3 +136,27 @@
|
||||||
|
|
||||||
blockquote :last-child
|
blockquote :last-child
|
||||||
margin-bottom: 0
|
margin-bottom: 0
|
||||||
|
|
||||||
|
.global-comment-list
|
||||||
|
text-align: left
|
||||||
|
|
||||||
|
&>ul
|
||||||
|
list-style-type: none
|
||||||
|
margin: 1em 0
|
||||||
|
padding: 0
|
||||||
|
|
||||||
|
&>li
|
||||||
|
display: flex
|
||||||
|
margin-bottom: 2em
|
||||||
|
|
||||||
|
.post-thumbnail
|
||||||
|
float: left
|
||||||
|
vertical-align: top
|
||||||
|
margin-right: 1em
|
||||||
|
.thumbnail
|
||||||
|
width: 12em
|
||||||
|
height: 8em
|
||||||
|
margin: 0
|
||||||
|
|
||||||
|
.comments-container
|
||||||
|
width: 100%
|
||||||
|
|
|
@ -196,7 +196,7 @@ a .access-key
|
||||||
height: 0
|
height: 0
|
||||||
.page
|
.page
|
||||||
position: relative
|
position: relative
|
||||||
p
|
.page-header
|
||||||
margin: 0.5em 0.5em 0.5em 0
|
margin: 0.5em 0.5em 0.5em 0
|
||||||
position: relative
|
position: relative
|
||||||
&:before
|
&:before
|
||||||
|
|
|
@ -94,8 +94,11 @@ $safety-unsafe = #F3985F
|
||||||
>.content
|
>.content
|
||||||
width: 100%
|
width: 100%
|
||||||
|
|
||||||
.post-container .post-content
|
.post-container
|
||||||
margin: 0
|
margin-bottom: 2em
|
||||||
|
|
||||||
|
.post-content
|
||||||
|
margin: 0
|
||||||
|
|
||||||
.post-list
|
.post-list
|
||||||
ul
|
ul
|
||||||
|
|
18
client/html/comments_page.tpl
Normal file
18
client/html/comments_page.tpl
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<div class='global-comment-list'>
|
||||||
|
<ul><!--
|
||||||
|
--><% for (let post of ctx.results) { %><!--
|
||||||
|
--><li><!--
|
||||||
|
--><div class='post-thumbnail'><!--
|
||||||
|
--><% if (ctx.canViewPosts) { %><!--
|
||||||
|
--><a href='/post/<%= post.id %>'><!--
|
||||||
|
--><% } %><!--
|
||||||
|
--><%= ctx.makeThumbnail(post.thumbnailUrl) %><!--
|
||||||
|
--><% if (ctx.canViewPosts) { %><!--
|
||||||
|
--></a><!--
|
||||||
|
--><% } %><!--
|
||||||
|
--></div><!--
|
||||||
|
--><div class='comments-container' data-for='<%= post.id %>'></div><!--
|
||||||
|
--></li><!--
|
||||||
|
--><% } %><!--
|
||||||
|
--></ul>
|
||||||
|
</div>
|
|
@ -1,4 +1,4 @@
|
||||||
<div class='page'>
|
<div class='page'>
|
||||||
<p><span>Page <%= ctx.page %> of <%= ctx.totalPages %></span></p>
|
<p class='page-header'><span>Page <%= ctx.page %> of <%= ctx.totalPages %></span></p>
|
||||||
<div class='page-content-holder'></div>
|
<div class='page-content-holder'></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,18 +1,39 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const api = require('../api.js');
|
||||||
const page = require('page');
|
const page = require('page');
|
||||||
|
const misc = require('../util/misc.js');
|
||||||
const topNavController = require('../controllers/top_nav_controller.js');
|
const topNavController = require('../controllers/top_nav_controller.js');
|
||||||
|
const pageController = require('../controllers/page_controller.js');
|
||||||
|
const CommentsPageView = require('../views/comments_page_view.js');
|
||||||
const EmptyView = require('../views/empty_view.js');
|
const EmptyView = require('../views/empty_view.js');
|
||||||
|
|
||||||
class CommentsController {
|
class CommentsController {
|
||||||
registerRoutes() {
|
registerRoutes() {
|
||||||
page('/comments', (ctx, next) => { this._listCommentsRoute(); });
|
page('/comments/:query?',
|
||||||
|
(ctx, next) => { misc.parseSearchQueryRoute(ctx, next); },
|
||||||
|
(ctx, next) => { this._listCommentsRoute(ctx); });
|
||||||
|
this._commentsPageView = new CommentsPageView();
|
||||||
this._emptyView = new EmptyView();
|
this._emptyView = new EmptyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
_listCommentsRoute() {
|
_listCommentsRoute(ctx) {
|
||||||
topNavController.activate('comments');
|
topNavController.activate('comments');
|
||||||
this._emptyView.render();
|
|
||||||
|
pageController.run({
|
||||||
|
searchQuery: ctx.searchQuery,
|
||||||
|
clientUrl: '/comments/' + misc.formatSearchQuery({page: '{page}'}),
|
||||||
|
requestPage: page => {
|
||||||
|
return api.get(
|
||||||
|
'/posts/?query=sort:comment-date+comment-count-min:1' +
|
||||||
|
`&page=${page}&pageSize=10&fields=` +
|
||||||
|
'id,comments,commentCount,thumbnailUrl');
|
||||||
|
},
|
||||||
|
pageRenderer: this._commentsPageView,
|
||||||
|
pageContext: {
|
||||||
|
canViewPosts: api.hasPrivilege('posts:view'),
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
client/js/views/comments_page_view.js
Normal file
27
client/js/views/comments_page_view.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const views = require('../util/views.js');
|
||||||
|
const CommentListControl = require('../controls/comment_list_control.js');
|
||||||
|
|
||||||
|
class CommentsPageView {
|
||||||
|
constructor() {
|
||||||
|
this._template = views.getTemplate('comments-page');
|
||||||
|
}
|
||||||
|
|
||||||
|
render(ctx) {
|
||||||
|
const target = ctx.target;
|
||||||
|
const source = this._template(ctx);
|
||||||
|
|
||||||
|
for (let post of ctx.results) {
|
||||||
|
post.comments.reverse();
|
||||||
|
new CommentListControl(
|
||||||
|
source.querySelector(
|
||||||
|
`.comments-container[data-for="${post.id}"]`),
|
||||||
|
post.comments);
|
||||||
|
}
|
||||||
|
|
||||||
|
views.showView(target, source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CommentsPageView;
|
|
@ -25,7 +25,9 @@ class EndlessPageView {
|
||||||
this._working = 0;
|
this._working = 0;
|
||||||
|
|
||||||
ctx.headerContext.target = pageHeaderHolder;
|
ctx.headerContext.target = pageHeaderHolder;
|
||||||
ctx.headerRenderer.render(ctx.headerContext);
|
if (ctx.headerRenderer) {
|
||||||
|
ctx.headerRenderer.render(ctx.headerContext);
|
||||||
|
}
|
||||||
|
|
||||||
const threshold = window.innerHeight / 3;
|
const threshold = window.innerHeight / 3;
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,9 @@ class ManualPageView {
|
||||||
const currentPage = ctx.searchQuery.page;
|
const currentPage = ctx.searchQuery.page;
|
||||||
|
|
||||||
ctx.headerContext.target = pageHeaderHolder;
|
ctx.headerContext.target = pageHeaderHolder;
|
||||||
ctx.headerRenderer.render(ctx.headerContext);
|
if (ctx.headerRenderer) {
|
||||||
|
ctx.headerRenderer.render(ctx.headerContext);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.requestPage(currentPage).then(response => {
|
ctx.requestPage(currentPage).then(response => {
|
||||||
Object.assign(ctx.pageContext, response);
|
Object.assign(ctx.pageContext, response);
|
||||||
|
|
Loading…
Reference in a new issue