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

Commit

Permalink
Refactoring: actions/schools
Browse files Browse the repository at this point in the history
  • Loading branch information
artkravchenko committed Jun 11, 2016
1 parent e42f4e9 commit 21945e2
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 110 deletions.
66 changes: 1 addition & 65 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@ 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 ADD_SCHOOL = 'ADD_SCHOOL';

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

export const SET_USER_TAGS = 'SET_USER_TAGS';

export const ADD_USER_FOLLOWED_SCHOOL = 'ADD_USER_FOLLOWED_SCHOOL';
export const REMOVE_USER_FOLLOWED_SCHOOL = 'REMOVE_USER_FOLLOWED_SCHOOL';
export const SET_SCHOOL_POSTS = 'SET_SCHOOL_POSTS';
export const SET_SCHOOLS = 'SET_SCHOOLS';
export const REMOVE_POST = 'REMOVE_POST';

export const SET_LIKES = 'SET_LIKES';
Expand All @@ -46,8 +42,6 @@ export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const SET_CURRENT_USER = 'SET_CURRENT_USER';
export const SET_SUGGESTED_USERS = 'SET_SUGGESTED_USERS';
export const SET_PERSONALIZED_SUGGESTED_USERS = 'SET_PERSONALIZED_SUGGESTED_USERS';
export const ADD_LIKED_SCHOOL = 'ADD_LIKED_SCHOOL';
export const REMOVE_LIKED_SCHOOL = 'REMOVE_LIKED_SCHOOL';

export const SET_COUNTRIES = 'SET_COUNTRIES';
export const ADD_COUNTRY = 'ADD_COUNTRY';
Expand All @@ -60,7 +54,6 @@ export const REGISTRATION_SUCCESS = 'REGISTRATION_SUCCESS';
export const SHOW_REGISTER_FORM = 'SHOW_REGISTER_FORM';

export const SET_USER_RECENT_TAGS = 'SET_USER_RECENT_TAGS';
export const SET_SCHOOL_CLOUD = 'SET_SCHOOL_CLOUD';

export const SET_QUOTES = 'SET_QUOTES';

Expand All @@ -76,13 +69,6 @@ export function addUser(user) {
};
}

export function addSchool(school) {
return {
type: ADD_SCHOOL,
school
};
}

export function addPost(post) {
return {
type: ADD_POST,
Expand Down Expand Up @@ -115,35 +101,13 @@ export function setUserTags(tags) {
};
}

export function addUserFollowedSchool(school) {
return {
type: ADD_USER_FOLLOWED_SCHOOL,
school
};
}

export function removeUserFollowedSchool(school) {
return {
type: REMOVE_USER_FOLLOWED_SCHOOL,
school
};
}

export function setUserRecentTags(recent_tags) {
return {
type: SET_USER_RECENT_TAGS,
recent_tags
};
}

export function setSchoolPosts(school, posts) {
return {
type: SET_SCHOOL_POSTS,
school,
posts
};
}

export function removePost(id) {
return {
type: REMOVE_POST,
Expand Down Expand Up @@ -171,13 +135,6 @@ export function setFavourites(user_id, favourites, post_id, favourers) {
};
}

export function setSchools(schools) {
return {
type: SET_SCHOOLS,
schools
};
}

export function loginSuccess() {
return {
type: LOGIN_SUCCESS
Expand Down Expand Up @@ -254,13 +211,6 @@ export function setCityPosts(cityId, posts) {
};
}

export function setSchoolCloud(schools) {
return {
type: SET_SCHOOL_CLOUD,
schools
};
}

export function registrationSuccess() {
return {
type: REGISTRATION_SUCCESS
Expand Down Expand Up @@ -299,20 +249,6 @@ export function updateEditPostForm(edit_post_form) {
};
}

export function addLikedSchool(school) {
return {
type: ADD_LIKED_SCHOOL,
school
};
}

export function removeLikedSchool(school) {
return {
type: REMOVE_LIKED_SCHOOL,
school
};
}

export function setQuotes(quotes) {
return {
type: SET_QUOTES,
Expand Down
84 changes: 84 additions & 0 deletions src/actions/schools.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_SCHOOL = 'ADD_SCHOOL';
export const SET_SCHOOLS = 'SET_SCHOOLS';
export const SET_SCHOOL_POSTS = 'SET_SCHOOL_POSTS';
export const SET_SCHOOL_CLOUD = 'SET_SCHOOL_CLOUD';

export const ADD_LIKED_SCHOOL = 'ADD_LIKED_SCHOOL';
export const REMOVE_LIKED_SCHOOL = 'REMOVE_LIKED_SCHOOL';

export const ADD_USER_FOLLOWED_SCHOOL = 'ADD_USER_FOLLOWED_SCHOOL';
export const REMOVE_USER_FOLLOWED_SCHOOL = 'REMOVE_USER_FOLLOWED_SCHOOL';

export function addSchool(school) {
return {
type: ADD_SCHOOL,
school
};
}

export function setSchools(schools) {
return {
type: SET_SCHOOLS,
schools
};
}

export function setSchoolPosts(school, posts) {
return {
type: SET_SCHOOL_POSTS,
school,
posts
};
}

export function setSchoolCloud(schools) {
return {
type: SET_SCHOOL_CLOUD,
schools
};
}

export function addLikedSchool(school) {
return {
type: ADD_LIKED_SCHOOL,
school
};
}

export function removeLikedSchool(school) {
return {
type: REMOVE_LIKED_SCHOOL,
school
};
}

export function addUserFollowedSchool(school) {
return {
type: ADD_USER_FOLLOWED_SCHOOL,
school
};
}

export function removeUserFollowedSchool(school) {
return {
type: REMOVE_USER_FOLLOWED_SCHOOL,
school
};
}
9 changes: 3 additions & 6 deletions src/pages/school-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 All @@ -25,11 +25,8 @@ import Helmet from 'react-helmet';
import { API_HOST } from '../config';
import ApiClient from '../api/client';
import BaseTagPage from './base/tag';
import {
addSchool,
resetCreatePostForm,
updateCreatePostForm
} from '../actions';
import { resetCreatePostForm, updateCreatePostForm } from '../actions';
import { addSchool } from '../actions/schools';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';
import { URL_NAMES, getUrl } from '../utils/urlGenerator';
Expand Down
10 changes: 3 additions & 7 deletions src/pages/school.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 All @@ -21,12 +21,8 @@ import { connect } from 'react-redux';
import { find, values } from 'lodash';
import Helmet from 'react-helmet';

import {
setSchoolPosts,
addSchool,
resetCreatePostForm,
updateCreatePostForm
} from '../actions';
import { resetCreatePostForm, updateCreatePostForm } from '../actions';
import { setSchoolPosts, addSchool } from '../actions/schools';
import { API_HOST } from '../config';
import ApiClient from '../api/client';
import NotFound from './not-found';
Expand Down
4 changes: 2 additions & 2 deletions src/store/comments.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 @@ -49,7 +49,7 @@ export default function reducer(state = initialState, action) {
case a.river.SET_POSTS_TO_FAVOURITES_RIVER:
case a.SET_USER_POSTS:
case a.hashtags.SET_HASHTAG_POSTS:
case a.SET_SCHOOL_POSTS:
case a.schools.SET_SCHOOL_POSTS:
case a.geotags.SET_GEOTAG_POSTS:
case a.SET_RELATED_POSTS: {
action.posts.forEach(post => {
Expand Down
10 changes: 5 additions & 5 deletions src/store/current-user.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 @@ -130,13 +130,13 @@ export default function reducer(state = initialState, action) {
break;
}

case a.ADD_USER_FOLLOWED_SCHOOL: {
case a.schools.ADD_USER_FOLLOWED_SCHOOL: {
state = state.setIn(['followed_schools', action.school.url_name], i.fromJS(action.school));

break;
}

case a.REMOVE_USER_FOLLOWED_SCHOOL: {
case a.schools.REMOVE_USER_FOLLOWED_SCHOOL: {
state = state.deleteIn(['followed_schools', action.school.url_name]);

break;
Expand Down Expand Up @@ -172,13 +172,13 @@ export default function reducer(state = initialState, action) {
break;
}

case a.ADD_LIKED_SCHOOL: {
case a.schools.ADD_LIKED_SCHOOL: {
state = state.setIn(['liked_schools', action.school.url_name], i.fromJS(action.school));

break;
}

case a.REMOVE_LIKED_SCHOOL: {
case a.schools.REMOVE_LIKED_SCHOOL: {
state = state.deleteIn(['liked_schools', action.school.url_name]);

break;
Expand Down
2 changes: 1 addition & 1 deletion src/store/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function reducer(state = initialState, action) {
case a.river.SET_POSTS_TO_FAVOURITES_RIVER:
case a.SET_USER_POSTS:
case a.hashtags.SET_HASHTAG_POSTS:
case a.SET_SCHOOL_POSTS:
case a.schools.SET_SCHOOL_POSTS:
case a.geotags.SET_GEOTAG_POSTS:
case a.SET_RELATED_POSTS: {
const postsWithoutUsers = _.keyBy(action.posts.map(post => {
Expand Down
6 changes: 3 additions & 3 deletions src/store/school_cloud.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 All @@ -18,13 +18,13 @@
import i from 'immutable';
import _ from 'lodash';

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

const initialState = i.List([]);

export default function reducer(state = initialState, action) {
switch (action.type) {
case a.SET_SCHOOL_CLOUD: {
case schools.SET_SCHOOL_CLOUD: {
state = i.fromJS(_.map(action.schools, 'id'));
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/store/school_posts.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 @@ -38,7 +38,7 @@ export default function reducer(state = initialState, action) {
break;
}

case a.SET_SCHOOL_POSTS: {
case a.schools.SET_SCHOOL_POSTS: {
state = state.set(action.school.id, i.List(action.posts.map(post => post.id)));
break;
}
Expand Down

0 comments on commit 21945e2

Please sign in to comment.