Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Merge origin/feature/all-posts-page into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
indeyets committed Feb 13, 2017
2 parents c7ec6d1 + ec07417 commit c0d0378
Show file tree
Hide file tree
Showing 28 changed files with 690 additions and 27 deletions.
37 changes: 37 additions & 0 deletions src/actions/all-posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2016 Loki Education (Social Enterprise)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export const ADD_POSTS_TO_ALL_POSTS = 'ADD_POSTS_TO_ALL_POSTS';
export const SET_ALL_POSTS = 'SET_ALL_POSTS';

export function addPosts(posts) {
return {
type: ADD_POSTS_TO_ALL_POSTS,
payload: {
posts
}
};
}

export function setPosts(posts) {
return {
type: SET_ALL_POSTS,
payload: {
posts
}
};
}
1 change: 1 addition & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export const quotes = require('./quotes');
export const tools = require('./tools');

export const userMessages = require('./user-messages');
export const allPosts = require('./all-posts');
10 changes: 10 additions & 0 deletions src/actions/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export const CREATE_POST = 'CREATE_POST';
export const ADD_POST = 'ADD_POST';
export const REMOVE_POST = 'REMOVE_POST';

Expand All @@ -30,6 +31,15 @@ export const UPDATE_CREATE_POST_FORM = 'UPDATE_CREATE_POST_FORM';
export const RESET_EDIT_POST_FORM = 'RESET_EDIT_POST_FORM';
export const UPDATE_EDIT_POST_FORM = 'UPDATE_EDIT_POST_FORM';

export function createPost(post) {
return {
type: CREATE_POST,
payload: {
post
}
};
}

export function addPost(post) {
return {
type: ADD_POST,
Expand Down
11 changes: 0 additions & 11 deletions src/actions/river.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,12 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export const ADD_POST_TO_RIVER = 'ADD_POST_TO_RIVER';

export const CLEAR_RIVER = 'CLEAR_RIVER';

export const SET_POSTS_TO_RIVER = 'SET_POSTS_TO_RIVER';
export const SET_POSTS_TO_LIKES_RIVER = 'SET_POSTS_TO_LIKES_RIVER';
export const SET_POSTS_TO_FAVOURITES_RIVER = 'SET_POSTS_TO_FAVOURITES_RIVER';

export function addPostToRiver(post) {
return {
type: ADD_POST_TO_RIVER,
payload: {
post
}
};
}

export function clearRiver() {
return {
type: CLEAR_RIVER
Expand Down
5 changes: 5 additions & 0 deletions src/api/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ export default class ApiClient
return await response.json();
}

async allPosts(query: Object = {}): Promise<Array<Post>> {
const response = await this.get('/api/v1/posts/all', query);
return await response.json();
}

async checkUserExists(username: Username): Promise<boolean> {
const result = await this.head(`/api/v1/user/${username}`);

Expand Down
28 changes: 26 additions & 2 deletions src/api/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,20 @@ export default class ApiController {
};

allPosts = async (ctx) => {
const Posts = this.bookshelf.collection('Posts');
const posts = new Posts();
const Post = this.bookshelf.model('Post');
const posts = Post.collection().query(qb => {
this.applySortQuery(qb, ctx.query, '-created_at');
this.applyLimitQuery(qb, ctx.query, 10);
this.applyOffsetQuery(qb, ctx.query);

if ('continent' in ctx.query) {
qb
.distinct('posts.*')
.join('geotags_posts', 'posts.id', 'geotags_posts.post_id')
.join('geotags', 'geotags_posts.geotag_id', 'geotags.id')
.where('geotags.continent_code', ctx.query.continent);
}
});
let response = await posts.fetch({ require: false, withRelated: POST_RELATIONS });
response = response.map(post => {
post.relations.schools = post.relations.schools.map(row => ({ id: row.id, name: row.attributes.name, url_name: row.attributes.url_name }));
Expand Down Expand Up @@ -3401,4 +3413,16 @@ export default class ApiController {
qb.where('name', 'ILIKE', `${query.startsWith}%`);
}
}

applyLimitQuery(qb, query, defaultValue = null) {
if ('limit' in query || defaultValue) {
qb.limit(query.limit || defaultValue);
}
}

applyOffsetQuery(qb, query, defaultValue = null) {
if ('offset' in query || defaultValue) {
qb.offset(query.offset || defaultValue);
}
}
}
38 changes: 38 additions & 0 deletions src/components/filters/continent-filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2016 Loki Education (Social Enterprise)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react';
import CONTINENTS from '../../consts/continents';
import FilterLink from './filter-link';


export default function ContinentFilter({ location }) {
const continents = Object.keys(CONTINENTS).map(code => (
<FilterLink
key={code}
location={location}
query={{ continent: code }}
title={CONTINENTS[code].name}
/>
));

return (
<div className="aux-nav">
{continents}
</div>
);
}
59 changes: 59 additions & 0 deletions src/components/filters/filter-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2016 Loki Education (Social Enterprise)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react';
import { Link } from 'react-router';
import { intersection } from 'lodash';


function getNewUrl(query, location) {
return {
...location,
query: {
...location.query,
...query
}
};
}

export default function FilterLink({ isDefault, title, query, location }) {
const urlFunction = getNewUrl.bind(null, query);
let activeClassName = 'aux-nav__link--active';
let className = 'aux-nav__link';
const isFilterSet = intersection(
Object.keys(query),
Object.keys(location.query)
).length > 0;

// force active state
if (isDefault && !isFilterSet) {
className = `${className} ${activeClassName}`;
activeClassName = null;
}

return (
<div className="aux-nav__item">
<Link
activeClassName={activeClassName}
className={className}
to={urlFunction}
>
{title}
</Link>
</div>
);
}
38 changes: 38 additions & 0 deletions src/components/filters/sorting-filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2016 Loki Education (Social Enterprise)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react';
import FilterLink from './filter-link';


export default function SortingFilter({ location, sortingTypes }) {
const continents = sortingTypes.map((item, i) => (
<FilterLink
isDefault={item.isDefault}
key={i}
location={location}
query={{ sort: item.value }}
title={item.name}
/>
));

return (
<div className="aux-nav">
{continents}
</div>
);
}
10 changes: 9 additions & 1 deletion src/consts/sidebar-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export const MENU_ITEMS = {
all: {
className: 'navigation-item--color_blue menu__all',
icon: {
icon: 'public'
},
title: 'all',
url: () => '/all'
},
news: {
className: 'navigation-item--color_blue menu__news',
icon: {
icon: 'public'
},
title: 'news',
url: () => '/'
url: () => '/feed'
},
likes: {
className: 'navigation-item--color_red menu__likes',
Expand Down
22 changes: 22 additions & 0 deletions src/consts/sorting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2016 Loki Education (Social Enterprise)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export const POST_SORTING_TYPES = [
{ name: 'Newest', value: '-created_at', isDefault: true },
{ name: 'Last modified', value: '-updated_at' }
];
56 changes: 56 additions & 0 deletions src/less/blocks/aux-nav.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2015 Loki Education (Social Enterprise)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
.aux-nav {
@active-icon: #6AB7EA;
@active-text: #1078B4;

margin-bottom: @doubleSpace;

&__item {
position: relative;
}

&__link {
display: block;
min-height: 42px;
margin-bottom: 2px;
padding: 10px 24px 10px 20px;
background-color: #FAFAFA;
}

&__link--active {
background-color: white;
color: @active-text;

&:after {
@height: 14px;

content: '';

display: block;
position: absolute;
top: calc(50% - @height);
right: 10px;
width: 4px;
height: @height;

background-color: @active-icon;
border-radius: 2px;
}
}
}

0 comments on commit c0d0378

Please sign in to comment.