client/posts: add proof of concept for post list

This commit is contained in:
rr-
2016-06-02 00:07:51 +02:00
parent 28009bf46d
commit f8e6d07fea
7 changed files with 222 additions and 5 deletions

View File

@ -2,15 +2,24 @@
const misc = require('../util/misc.js');
const page = require('page');
const api = require('../api.js');
const topNavController = require('../controllers/top_nav_controller.js');
const pageController = require('../controllers/page_controller.js');
const PostsHeaderView = require('../views/posts_header_view.js');
const PostsPageView = require('../views/posts_page_view.js');
const EmptyView = require('../views/empty_view.js');
class PostsController {
constructor() {
this._postsHeaderView = new PostsHeaderView();
this._postsPageView = new PostsPageView();
}
registerRoutes() {
page('/upload', (ctx, next) => { this._uploadPostsRoute(); });
page('/posts/:query?',
(ctx, next) => { misc.parseSearchQueryRoute(ctx, next); },
(ctx, next) => { this._listPostsRoute(); });
(ctx, next) => { this._listPostsRoute(ctx); });
page(
'/post/:id',
(ctx, next) => { this._showPostRoute(ctx.params.id); });
@ -25,9 +34,23 @@ class PostsController {
this._emptyView.render();
}
_listPostsRoute() {
_listPostsRoute(ctx) {
topNavController.activate('posts');
this._emptyView.render();
pageController.run({
state: ctx.state,
requestPage: page => {
const text = ctx.searchQuery.text;
return api.get(
`/posts/?query=${text}&page=${page}&pageSize=40&_fields=` +
`id,type,tags,score,favoriteCount,commentCount,thumbnailUrl`);
},
clientUrl: '/posts/' + misc.formatSearchQuery({
text: ctx.searchQuery.text, page: '{page}'}),
searchQuery: ctx.searchQuery,
headerRenderer: this._postsHeaderView,
pageRenderer: this._postsPageView,
});
}
_showPostRoute(id) {