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

Commit

Permalink
Refactoring: actions/posts
Browse files Browse the repository at this point in the history
  • Loading branch information
artkravchenko committed Jun 11, 2016
1 parent a859104 commit e7e7c3f
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 114 deletions.
73 changes: 4 additions & 69 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export const ui = require('./ui');
export const comments = require('./comments');
export const search = require('./search');
export const river = require('./river');
export const messages = require('./messages');

export const hashtags = require('./hashtags');
export const geotags = require('./geotags');
export const schools = require('./schools');

export const ADD_USER = 'ADD_USER';
export const posts = require('./posts');
export const river = require('./river');
export const comments = require('./comments');

export const ADD_POST = 'ADD_POST';
export const SET_RELATED_POSTS = 'SET_RELATED_POSTS';
export const SET_USER_POSTS = 'SET_USER_POSTS';
export const ADD_USER = 'ADD_USER';

export const SET_USER_TAGS = 'SET_USER_TAGS';

export const REMOVE_POST = 'REMOVE_POST';

export const SET_LIKES = 'SET_LIKES';
export const SET_FAVOURITES = 'SET_FAVOURITES';

Expand All @@ -57,41 +53,13 @@ export const SET_USER_RECENT_TAGS = 'SET_USER_RECENT_TAGS';

export const SET_QUOTES = 'SET_QUOTES';

export const RESET_CREATE_POST_FORM = 'RESET_CREATE_POST_FORM';
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 addUser(user) {
return {
type: ADD_USER,
user
};
}

export function addPost(post) {
return {
type: ADD_POST,
post
};
}

export function setRelatedPosts(post_id, posts) {
return {
type: SET_RELATED_POSTS,
post_id,
posts
};
}

export function setUserPosts(user_id, posts) {
return {
type: SET_USER_POSTS,
user_id,
posts
};
}

export function setUserTags(tags) {
return {
type: SET_USER_TAGS,
Expand All @@ -108,13 +76,6 @@ export function setUserRecentTags(recent_tags) {
};
}

export function removePost(id) {
return {
type: REMOVE_POST,
id
};
}

export function setLikes(user_id, likes, post_id, likers) {
return {
type: SET_LIKES,
Expand Down Expand Up @@ -223,32 +184,6 @@ export function showRegisterForm() {
};
}

export function resetCreatePostForm() {
return {
type: RESET_CREATE_POST_FORM
};
}

export function updateCreatePostForm(create_post_form) {
return {
type: UPDATE_CREATE_POST_FORM,
create_post_form
};
}

export function resetEditPostForm() {
return {
type: RESET_EDIT_POST_FORM
};
}

export function updateEditPostForm(edit_post_form) {
return {
type: UPDATE_EDIT_POST_FORM,
edit_post_form
};
}

export function setQuotes(quotes) {
return {
type: SET_QUOTES,
Expand Down
84 changes: 84 additions & 0 deletions src/actions/posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
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_POST = 'ADD_POST';
export const REMOVE_POST = 'REMOVE_POST';

export const SET_RELATED_POSTS = 'SET_RELATED_POSTS';
export const SET_USER_POSTS = 'SET_USER_POSTS';

export const RESET_CREATE_POST_FORM = 'RESET_CREATE_POST_FORM';
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 addPost(post) {
return {
type: ADD_POST,
post
};
}

export function removePost(id) {
return {
type: REMOVE_POST,
id
};
}

export function setRelatedPosts(post_id, posts) {
return {
type: SET_RELATED_POSTS,
post_id,
posts
};
}

export function setUserPosts(user_id, posts) {
return {
type: SET_USER_POSTS,
user_id,
posts
};
}

export function resetCreatePostForm() {
return {
type: RESET_CREATE_POST_FORM
};
}

export function updateCreatePostForm(create_post_form) {
return {
type: UPDATE_CREATE_POST_FORM,
create_post_form
};
}

export function resetEditPostForm() {
return {
type: RESET_EDIT_POST_FORM
};
}

export function updateEditPostForm(edit_post_form) {
return {
type: UPDATE_EDIT_POST_FORM,
edit_post_form
};
}
2 changes: 1 addition & 1 deletion src/pages/geotag-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { defaultSelector } from '../selectors';
import { API_HOST } from '../config';
import ApiClient from '../api/client';
import BaseTagPage from './base/tag';
import { resetCreatePostForm, updateCreatePostForm } from '../actions';
import { resetCreatePostForm, updateCreatePostForm } from '../actions/posts';
import { addGeotag } from '../actions/geotags';
import { ActionsTrigger } from '../triggers';
import { URL_NAMES, getUrl } from '../utils/urlGenerator';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/geotag.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { values } from 'lodash';

import ApiClient from '../api/client';
import { API_HOST } from '../config';
import { resetCreatePostForm, updateCreatePostForm } from '../actions';
import { resetCreatePostForm, updateCreatePostForm } from '../actions/posts';
import { addGeotag, setGeotagPosts } from '../actions/geotags';

import NotFound from './not-found';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/hashtag-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { defaultSelector } from '../selectors';
import { API_HOST } from '../config';
import ApiClient from '../api/client';
import BaseTagPage from './base/tag';
import { resetCreatePostForm, updateCreatePostForm } from '../actions';
import { resetCreatePostForm, updateCreatePostForm } from '../actions/posts';
import { addHashtag } from '../actions/hashtags';
import { ActionsTrigger } from '../triggers';
import { URL_NAMES, getUrl } from '../utils/urlGenerator';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { defaultSelector } from '../selectors';
import {
resetCreatePostForm,
updateCreatePostForm
} from '../actions';
} from '../actions/posts';
import { clearRiver } from '../actions/river';

const client = new ApiClient(API_HOST);
Expand Down
6 changes: 3 additions & 3 deletions src/pages/post-edit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2015 Loki Education (Social Enterprise)
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
Expand Down Expand Up @@ -35,7 +35,6 @@ import Header from '../components/header';
import Footer from '../components/footer';
import { API_HOST } from '../config';
import ApiClient from '../api/client';
import { addPost } from '../actions';
import { URL_NAMES, getUrl } from '../utils/urlGenerator';
import Sidebar from '../components/sidebar';
import SidebarAlt from '../components/sidebarAlt';
Expand All @@ -45,9 +44,10 @@ import AddedTags from '../components/post/added-tags';
import { defaultSelector } from '../selectors';
import { ActionsTrigger } from '../triggers';
import {
addPost,
resetEditPostForm,
updateEditPostForm
} from '../actions';
} from '../actions/posts';


class PostEditPage extends React.Component {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2015 Loki Education (Social Enterprise)
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
Expand Down Expand Up @@ -39,7 +39,7 @@ import RelatedPosts from '../components/related-posts';
import SidebarAlt from '../components/sidebarAlt';
import { API_HOST } from '../config';
import ApiClient from '../api/client';
import { addPost, setRelatedPosts } from '../actions';
import { addPost, setRelatedPosts } from '../actions/posts';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';
import { URL_NAMES, getUrl } from '../utils/urlGenerator';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/school-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Helmet from 'react-helmet';
import { API_HOST } from '../config';
import ApiClient from '../api/client';
import BaseTagPage from './base/tag';
import { resetCreatePostForm, updateCreatePostForm } from '../actions';
import { resetCreatePostForm, updateCreatePostForm } from '../actions/posts';
import { addSchool } from '../actions/schools';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/school.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { connect } from 'react-redux';
import { find, values } from 'lodash';
import Helmet from 'react-helmet';

import { resetCreatePostForm, updateCreatePostForm } from '../actions';
import { resetCreatePostForm, updateCreatePostForm } from '../actions/posts';
import { setSchoolPosts, addSchool } from '../actions/schools';
import { API_HOST } from '../config';
import ApiClient from '../api/client';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { values } from 'lodash';

import ApiClient from '../api/client';
import { API_HOST } from '../config';
import { resetCreatePostForm, updateCreatePostForm } from '../actions';
import { resetCreatePostForm, updateCreatePostForm } from '../actions/posts';
import { addHashtag, setHashtagPosts } from '../actions/hashtags';

import NotFound from './not-found';
Expand Down
3 changes: 2 additions & 1 deletion src/pages/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import River from '../components/river_of_posts';

import { API_HOST } from '../config';
import ApiClient from '../api/client';
import { addUser, setUserPosts } from '../actions';
import { addUser } from '../actions';
import { setUserPosts } from '../actions/posts';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';

Expand Down
8 changes: 4 additions & 4 deletions src/store/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const clearComments = (comments) => (
export default function reducer(state = initialState, action) {
switch (action.type) {
case a.river.ADD_POST_TO_RIVER:
case a.ADD_POST: {
case a.posts.ADD_POST: {
const comments = action.post.post_comments || [];

state = state.set(action.post.id, List(clearComments(comments)));
Expand All @@ -47,11 +47,11 @@ export default function reducer(state = initialState, action) {
case a.river.SET_POSTS_TO_RIVER:
case a.river.SET_POSTS_TO_LIKES_RIVER:
case a.river.SET_POSTS_TO_FAVOURITES_RIVER:
case a.SET_USER_POSTS:
case a.posts.SET_USER_POSTS:
case a.hashtags.SET_HASHTAG_POSTS:
case a.schools.SET_SCHOOL_POSTS:
case a.geotags.SET_GEOTAG_POSTS:
case a.SET_RELATED_POSTS: {
case a.posts.SET_RELATED_POSTS: {
action.posts.forEach(post => {
const postCopy = cloneDeep(post);

Expand All @@ -67,7 +67,7 @@ export default function reducer(state = initialState, action) {
break;
}

case a.REMOVE_POST: {
case a.posts.REMOVE_POST: {
state = state.delete(action.id);

break;
Expand Down
6 changes: 3 additions & 3 deletions src/store/create_post_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
import i from 'immutable';

import * as a from '../actions';
import { posts } from '../actions';

const initialState = i.fromJS({
text: '',
Expand All @@ -28,12 +28,12 @@ const initialState = i.fromJS({

export default function reducer(state = initialState, action) {
switch (action.type) {
case a.RESET_CREATE_POST_FORM: {
case posts.RESET_CREATE_POST_FORM: {
state = initialState;
break;
}

case a.UPDATE_CREATE_POST_FORM: {
case posts.UPDATE_CREATE_POST_FORM: {
state = state.merge(action.create_post_form);
break;
}
Expand Down

0 comments on commit e7e7c3f

Please sign in to comment.