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

Commit

Permalink
Refactoring: actions/users
Browse files Browse the repository at this point in the history
  • Loading branch information
artkravchenko committed Jun 12, 2016
1 parent b3c5c17 commit 87105fd
Show file tree
Hide file tree
Showing 22 changed files with 164 additions and 148 deletions.
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import ApiClient from './src/api/client';
import { initState } from './src/store';
import {
setCurrentUser, setLikes, setFavourites
} from './src/actions';
} from './src/actions/users';

import db_config from './knexfile';

Expand Down
85 changes: 1 addition & 84 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,95 +30,12 @@ export const posts = require('./posts');
export const river = require('./river');
export const comments = require('./comments');

export const ADD_USER = 'ADD_USER';
export const users = require('./users');

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

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 SUBMIT_RESET_PASSWORD = 'SUBMIT_RESET_PASSWORD';
export const SUBMIT_NEW_PASSWORD = 'SUBMIT_NEW_PASSWORD';
export const REGISTRATION_SUCCESS = 'REGISTRATION_SUCCESS';
export const SHOW_REGISTER_FORM = 'SHOW_REGISTER_FORM';

export const SET_QUOTES = 'SET_QUOTES';

export function addUser(user) {
return {
type: ADD_USER,
user
};
}

export function setLikes(user_id, likes, post_id, likers) {
return {
type: SET_LIKES,
user_id,
likes,
post_id,
likers
};
}

export function setFavourites(user_id, favourites, post_id, favourers) {
return {
type: SET_FAVOURITES,
user_id,
favourites,
post_id,
favourers
};
}

export function loginSuccess() {
return {
type: LOGIN_SUCCESS
};
}

export function setCurrentUser(user) {
return {
type: SET_CURRENT_USER,
user
};
}

export function setSuggestedUsers(suggested_users) {
return {
type: SET_SUGGESTED_USERS,
suggested_users
};
}

export function setPersonalizedSuggestedUsers(suggested_users) {
return {
type: SET_PERSONALIZED_SUGGESTED_USERS,
suggested_users
};
}

export function submitResetPassword() {
return {
type: SUBMIT_RESET_PASSWORD
};
}

export function submitNewPassword() {
return {
type: SUBMIT_NEW_PASSWORD
};
}

export function registrationSuccess() {
return {
type: REGISTRATION_SUCCESS
};
}

export function showRegisterForm() {
return {
type: SHOW_REGISTER_FORM
Expand Down
103 changes: 103 additions & 0 deletions src/actions/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
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_USER = 'ADD_USER';
export const SET_CURRENT_USER = 'SET_CURRENT_USER';

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

export const SET_SUGGESTED_USERS = 'SET_SUGGESTED_USERS';
export const SET_PERSONALIZED_SUGGESTED_USERS = 'SET_PERSONALIZED_SUGGESTED_USERS';

export const REGISTRATION_SUCCESS = 'REGISTRATION_SUCCESS';
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';

export const SUBMIT_RESET_PASSWORD = 'SUBMIT_RESET_PASSWORD';
export const SUBMIT_NEW_PASSWORD = 'SUBMIT_NEW_PASSWORD';

export function addUser(user) {
return {
type: ADD_USER,
user
};
}

export function setCurrentUser(user) {
return {
type: SET_CURRENT_USER,
user
};
}

export function setLikes(user_id, likes, post_id, likers) {
return {
type: SET_LIKES,
user_id,
likes,
post_id,
likers
};
}

export function setFavourites(user_id, favourites, post_id, favourers) {
return {
type: SET_FAVOURITES,
user_id,
favourites,
post_id,
favourers
};
}

export function setSuggestedUsers(suggested_users) {
return {
type: SET_SUGGESTED_USERS,
suggested_users
};
}

export function setPersonalizedSuggestedUsers(suggested_users) {
return {
type: SET_PERSONALIZED_SUGGESTED_USERS,
suggested_users
};
}

export function registrationSuccess() {
return {
type: REGISTRATION_SUCCESS
};
}

export function loginSuccess() {
return {
type: LOGIN_SUCCESS
};
}

export function submitResetPassword() {
return {
type: SUBMIT_RESET_PASSWORD
};
}

export function submitNewPassword() {
return {
type: SUBMIT_NEW_PASSWORD
};
}
2 changes: 1 addition & 1 deletion src/pages/induction.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Header from '../components/header';
import UserGrid from '../components/user-grid';
import ApiClient from '../api/client';
import { API_HOST } from '../config';
import { addUser } from '../actions';
import { addUser } from '../actions/users';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import BaseSettingsPage from './base/settings';
import SettingsPasswordForm from '../components/settings/password-form';
import ApiClient from '../api/client';
import { API_HOST } from '../config';
import { addUser } from '../actions';
import { addUser } from '../actions/users';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import BaseSettingsPage from './base/settings';

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

Expand Down
4 changes: 2 additions & 2 deletions src/pages/user-bio.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 @@ -24,7 +24,7 @@ import NotFound from './not-found';
import BaseUserPage from './base/user';
import ApiClient from '../api/client';
import { API_HOST } from '../config';
import { addUser } from '../actions';
import { addUser } from '../actions/users';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';

Expand Down
4 changes: 2 additions & 2 deletions src/pages/user-favorites.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,7 +25,7 @@ import BaseUserFavoritesPage from './base/user';
import River from '../components/river_of_posts';
import ApiClient from '../api/client';
import { API_HOST } from '../config';
import { addUser } from '../actions';
import { addUser } from '../actions/users';
import { setPostsToFavouritesRiver } from '../actions/river';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';
Expand Down
4 changes: 2 additions & 2 deletions src/pages/user-likes.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 @@ -28,7 +28,7 @@ import River from '../components/river_of_posts';

import ApiClient from '../api/client';
import { API_HOST } from '../config';
import { addUser } from '../actions';
import { addUser } from '../actions/users';
import { setPostsToLikesRiver } from '../actions/river';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import River from '../components/river_of_posts';

import { API_HOST } from '../config';
import ApiClient from '../api/client';
import { addUser } from '../actions';
import { addUser } from '../actions/users';
import { setUserPosts } from '../actions/posts';
import { ActionsTrigger } from '../triggers';
import { defaultSelector } from '../selectors';
Expand Down
4 changes: 2 additions & 2 deletions src/store/current-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const initialState = i.Map({

export default function reducer(state = initialState, action) {
switch (action.type) {
case a.SET_CURRENT_USER: {
case a.users.SET_CURRENT_USER: {
const oldUid = state.get('id');
const newUid = action.user ? action.user.id : null;

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

case a.SET_PERSONALIZED_SUGGESTED_USERS: {
case a.users.SET_PERSONALIZED_SUGGESTED_USERS: {
state = state.set('suggested_users', i.fromJS(action.suggested_users));

break;
Expand Down
6 changes: 3 additions & 3 deletions src/store/favourites.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 @@ -17,13 +17,13 @@
*/
import i from 'immutable';

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

const initialState = i.Map({});

export default function reducer(state = initialState, action) {
switch (action.type) {
case a.SET_FAVOURITES: {
case users.SET_FAVOURITES: {
state = state.set(action.user_id, i.List(action.favourites));
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/store/followers.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 @@ -17,14 +17,14 @@
*/
import i from 'immutable';

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

const initialState = i.Map({});

export default function reducer(state = initialState, action) {
switch (action.type) {
case a.ADD_USER:
case a.SET_CURRENT_USER: {
case users.ADD_USER:
case users.SET_CURRENT_USER: {
if (action.user && action.user.followers) {
state = state.set(action.user.id, i.List(action.user.followers.map(user => user.id)));
}
Expand Down
6 changes: 3 additions & 3 deletions src/store/following.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
*/
import i from 'immutable';

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

const initialState = i.Map({});

export default function reducer(state = initialState, action) {
switch (action.type) {
case a.ADD_USER:
case a.SET_CURRENT_USER: {
case users.ADD_USER:
case users.SET_CURRENT_USER: {
if (action.user && action.user.following) {
state = state.set(action.user.id, i.List(action.user.following.map(user => user.id)));
}
Expand Down

0 comments on commit 87105fd

Please sign in to comment.