Migrate actions,reducers and action types to TS #15

This commit is contained in:
Qolzam
2017-10-10 08:01:25 +07:00
parent 3b3899e7af
commit f9d213f741
113 changed files with 2692 additions and 1275 deletions

View File

@@ -58,8 +58,8 @@ import * as globalActions from 'actions/globalActions';
}
/**
* Register user in database
* @param {object} user
*
* @param user for registering
*/
export const dbSignup = (user: User) => {
return (dispatch: any, getState: any) => {
@@ -128,8 +128,8 @@ import * as globalActions from 'actions/globalActions';
}
/**
* Register user
* @param {object} user
* User registeration call
* @param user for registering
*/
export const signup = (user: User) => {
return {

View File

@@ -1,18 +1,22 @@
// - Import firebase component
import firebase, { firebaseRef } from 'app/firebase/'
// - Import domain
import { User } from "domain/users";
import { Circle, UserFollower } from "domain/circles";
// - Import utility components
import moment from 'moment'
// - Import action types
import * as types from 'actionTypes'
import { CircleActionType } from 'constants/circleActionType'
// - Import actions
import * as globalActions from 'globalActions'
import * as postActions from 'postActions'
import * as userActions from 'userActions'
import * as notifyActions from 'notifyActions'
import * as globalActions from 'actions/globalActions'
import * as postActions from 'actions/postActions'
import * as userActions from 'actions/userActions'
import * as notifyActions from 'actions/notifyActions'
@@ -25,11 +29,11 @@ import * as notifyActions from 'notifyActions'
* Add a circle
* @param {string} circleName
*/
export var dbAddCircle = (circleName) => {
return (dispatch, getState) => {
export var dbAddCircle = (circleName: string) => {
return (dispatch: any, getState: Function) => {
let uid = getState().authorize.uid
let circle = {
let uid: string = getState().authorize.uid
let circle: Circle = {
creationDate: moment().unix(),
name: circleName,
users: {}
@@ -37,10 +41,9 @@ export var dbAddCircle = (circleName) => {
let circleRef = firebaseRef.child(`userCircles/${uid}/circles`).push(circle)
return circleRef.then(() => {
dispatch(addCircle(uid, {
...circle,
id: circleRef.key
}))
circle.id = circleRef.key;
circle.ownerId = uid
dispatch(addCircle(circle))
}, (error) => dispatch(globalActions.showErrorMessage(error.message)))
@@ -50,37 +53,39 @@ export var dbAddCircle = (circleName) => {
/**
* Add a user in a circle
* @param {string} cid is circle identifier
* @param {object} userFollowing is the user for following
* @param {User} userFollowing is the user for following
*/
export var dbAddFollowingUser = (cid, userFollowing) => {
return (dispatch, getState) => {
export var dbAddFollowingUser = (cid: string, userFollowing: User) => {
return (dispatch: any, getState: Function) => {
let uid = getState().authorize.uid
let user = getState().user.info[uid]
let uid: string = getState().authorize.uid;
let user: User = getState().user.info[uid];
let userCircle = {
let userCircle: User = {
creationDate: moment().unix(),
fullName: userFollowing.fullName,
avatar: userFollowing.avatar || ''
}
let userFollower = {
let userFollower: UserFollower = {
creationDate: moment().unix(),
fullName: user.fullName,
avatar: user.avatar || '',
approved: false
}
let updates = {}
let updates: any = {}
updates[`userCircles/${uid}/circles/${cid}/users/${userFollowing.userId}`] = userCircle
updates[`userCircles/${userFollowing.userId}/circles/-Followers/users/${uid}`] = userFollower
return firebaseRef.update(updates).then((result) => {
dispatch(addFollowingUser(uid, cid, userFollowing.userId, { ...userCircle }))
dispatch(notifyActions.dbAddNotify(
{
description: `${user.fullName} follow you.`,
url: `/${uid}`,
notifyRecieverUserId: userFollowing.userId, notifierUserId: uid
}))
dispatch(addFollowingUser(uid, cid, userFollowing.userId as string, { ...userCircle } as User))
dispatch(notifyActions.dbAddNotify(
{
description: `${user.fullName} follow you.`,
url: `/${uid}`,
notifyRecieverUserId: userFollowing.userId as string,
notifierUserId: uid,
isSeen:false
}))
}, (error) => {
dispatch(globalActions.showErrorMessage(error.message))
@@ -94,12 +99,12 @@ export var dbAddFollowingUser = (cid, userFollowing) => {
* @param {string} cid is circle identifier
* @param {string} followingId following user identifier
*/
export var dbDeleteFollowingUser = (cid, followingId) => {
return (dispatch, getState) => {
export var dbDeleteFollowingUser = (cid: string, followingId: string) => {
return (dispatch: any, getState:Function) => {
let uid = getState().authorize.uid
let uid: string = getState().authorize.uid
let updates = {}
let updates: any = {}
updates[`userCircles/${uid}/circles/${cid}/users/${followingId}`] = null
updates[`userCircles/${followingId}/circles/-Followers/users/${uid}`] = null
return firebaseRef.update(updates).then((result) => {
@@ -112,24 +117,24 @@ export var dbDeleteFollowingUser = (cid, followingId) => {
/**
* Update a circle from database
* @param {object} newCircle
* @param {Circle} newCircle
*/
export const dbUpdateCircle = (newCircle) => {
return (dispatch, getState) => {
export const dbUpdateCircle = (newCircle: Circle) => {
return (dispatch: any, getState: Function) => {
// Get current user id
var uid = getState().authorize.uid
let uid: string = getState().authorize.uid
// Write the new data simultaneously in the list
let updates = {}
let circle = getState().circle.userCircles[uid][newCircle.id]
let updatedCircle = {
let updates: any = {}
let circle: Circle = getState().circle.userCircles[uid][newCircle.id!]
let updatedCircle : Circle = {
name: newCircle.name || circle.name,
users: newCircle.users ? newCircle.users : (circle.users || [])
}
updates[`userCircles/${uid}/circles/${newCircle.id}`] = updatedCircle
return firebaseRef.update(updates).then((result) => {
dispatch(updateCircle(uid, { id: newCircle.id, ...updatedCircle }))
return firebaseRef.update(updates).then(() => {
dispatch(updateCircle(uid,{ id: newCircle.id, ...updatedCircle }))
}, (error) => {
dispatch(globalActions.showErrorMessage(error.message))
})
@@ -142,14 +147,14 @@ export const dbUpdateCircle = (newCircle) => {
* Delete a circle from database
* @param {string} id is circle identifier
*/
export const dbDeleteCircle = (id) => {
return (dispatch, getState) => {
export const dbDeleteCircle = (id: string) => {
return (dispatch: any, getState: Function) => {
// Get current user id
var uid = getState().authorize.uid
let uid: string = getState().authorize.uid
// Write the new data simultaneously in the list
var updates = {};
let updates: any = {};
updates[`userCircles/${uid}/circles/${id}`] = null;
return firebaseRef.update(updates).then((result) => {
@@ -165,19 +170,19 @@ export const dbDeleteCircle = (id) => {
* Get all user circles from data base
*/
export const dbGetCircles = () => {
return (dispatch, getState) => {
var uid = getState().authorize.uid
return (dispatch: any, getState: Function) => {
let uid: string = getState().authorize.uid
if (uid) {
var circlesRef = firebaseRef.child(`userCircles/${uid}/circles`);
let circlesRef: any = firebaseRef.child(`userCircles/${uid}/circles`);
return circlesRef.once('value').then((snapshot) => {
var circles = snapshot.val() || {};
var parsedCircles = {};
return circlesRef.once('value').then((snapshot: any) => {
var circles: any = snapshot.val() || {};
var parsedCircles: { [circleId: string]: Circle } = {};
Object.keys(circles).forEach((circleId) => {
if (circleId !== '-Followers' && circles[circleId].users) {
Object.keys(circles[circleId].users).filter((v, i, a) => a.indexOf(v) === i).forEach((userId) => {
dispatch(postActions.dbGetPostsByUserId(userId))
dispatch(userActions.dbGetUserInfoByUserId(userId))
dispatch(userActions.dbGetUserInfoByUserId(userId, ""))
})
}
parsedCircles[circleId] = {
@@ -195,17 +200,18 @@ export const dbGetCircles = () => {
/**
* Get all user circles from data base by user id
* Get all user circles from data base by user id
* @param uid user identifier
*/
export const dbGetCirclesByUserId = (uid) => {
return (dispatch, getState) => {
export const dbGetCirclesByUserId = (uid: string) => {
return (dispatch: any, getState: Function) => {
if (uid) {
var circlesRef = firebaseRef.child(`userCircles/${uid}/circles`);
let circlesRef = firebaseRef.child(`userCircles/${uid}/circles`);
return circlesRef.once('value').then((snapshot) => {
var circles = snapshot.val() || {};
var parsedCircles = {};
var parsedCircles: { [circleId: string]: Circle } = {};
Object.keys(circles).forEach((circleId) => {
parsedCircles[circleId] = {
id: circleId,
@@ -229,23 +235,23 @@ export const dbGetCirclesByUserId = (uid) => {
/**
* Add a normal circle
* @param {string} uid is user identifier
* @param {object} circle
* @param {Circle} circle
*/
export const addCircle = (uid, circle) => {
export const addCircle = (circle: Circle) => {
return {
type: types.ADD_CIRCLE,
payload: { uid, circle }
type: CircleActionType.ADD_CIRCLE,
payload: { circle }
}
}
/**
* Update a circle
* @param {string} uid is user identifier
* @param {object} circle
* @param {Circle} circle
*/
export const updateCircle = (uid, circle) => {
export const updateCircle = (uid: string, circle: Circle) => {
return {
type: types.UPDATE_CIRCLE,
type: CircleActionType.UPDATE_CIRCLE,
payload: { uid, circle }
}
}
@@ -255,9 +261,9 @@ export const updateCircle = (uid, circle) => {
* @param {string} uid is user identifier
* @param {string} id is circle identifier
*/
export const deleteCircle = (uid, id) => {
export const deleteCircle = (uid: string, id: string) => {
return {
type: types.DELETE_CIRCLE,
type: CircleActionType.DELETE_CIRCLE,
payload: { uid, id }
}
}
@@ -266,11 +272,11 @@ export const deleteCircle = (uid, id) => {
/**
* Add a list of circle
* @param {string} uid
* @param {[object]} circles
* @param {circleId: string]: Circle} circles
*/
export const addCircles = (uid, circles) => {
export const addCircles = (uid: string, circles: { [circleId: string]: Circle }) => {
return {
type: types.ADD_LIST_CIRCLE,
type: CircleActionType.ADD_LIST_CIRCLE,
payload: { uid, circles }
}
}
@@ -280,17 +286,19 @@ export const addCircles = (uid, circles) => {
*/
export const clearAllCircles = () => {
return {
type: types.CLEAR_ALL_CIRCLES
type: CircleActionType.CLEAR_ALL_CIRCLES
}
}
/**
* Open circle settings
* @param uid user idenifier
* @param id circle identifier
*/
export const openCircleSettings = (uid, id) => {
export const openCircleSettings = (uid: string, id: string) => {
return {
type: types.OPEN_CIRCLE_SETTINGS,
type: CircleActionType.OPEN_CIRCLE_SETTINGS,
payload: { uid, id }
}
@@ -298,10 +306,12 @@ export const openCircleSettings = (uid, id) => {
/**
* Close open circle settings
* @param uid user identifier
* @param id circle identifier
*/
export const closeCircleSettings = (uid, id) => {
export const closeCircleSettings = (uid: string, id: string) => {
return {
type: types.CLOSE_CIRCLE_SETTINGS,
type: CircleActionType.CLOSE_CIRCLE_SETTINGS,
payload: { uid, id }
}
@@ -312,11 +322,11 @@ export const closeCircleSettings = (uid, id) => {
* @param {string} uid user identifire who want to follow the following user
* @param {string} cid circle identifier that following user should be added in
* @param {string} followingId following user identifier
* @param {object} userCircle information about following user
* @param {User} userCircle information about following user
*/
export const addFollowingUser = (uid, cid, followingId, userCircle) => {
export const addFollowingUser = (uid: string, cid: string, followingId: string, userCircle: User) => {
return {
type: types.ADD_FOLLOWING_USER,
type: CircleActionType.ADD_FOLLOWING_USER,
payload: { uid, cid, followingId, userCircle }
}
@@ -328,9 +338,9 @@ export const addFollowingUser = (uid, cid, followingId, userCircle) => {
* @param {string} cid circle identifier that following user should be added in
* @param {string} followingId following user identifier
*/
export const deleteFollowingUser = (uid, cid, followingId) => {
export const deleteFollowingUser = (uid: string, cid: string, followingId: string) => {
return {
type: types.DELETE_FOLLOWING_USER,
type: CircleActionType.DELETE_FOLLOWING_USER,
payload: { uid, cid, followingId }
}

View File

@@ -1,231 +0,0 @@
// - Import react components
import moment from 'moment'
import { firebaseRef } from 'app/firebase/'
// - Import action types
import * as types from 'actionTypes'
// - Import actions
import * as globalActions from 'globalActions'
import * as notifyActions from 'notifyActions'
/* _____________ CRUD DB _____________ */
/**
* Add comment to database
* @param {object} newComment user comment
* @param {function} callBack will be fired when server responsed
*/
export const dbAddComment = (newComment, callBack) => {
return (dispatch, getState) => {
dispatch(globalActions.showTopLoading())
var uid = getState().authorize.uid
var comment = {
postId: newComment.postId,
score: 0,
text: newComment.text,
creationDate: moment().unix(),
userDisplayName: getState().user.info[uid].fullName,
userAvatar: getState().user.info[uid].avatar,
userId: uid
}
var commentRef = firebaseRef.child(`postComments/${newComment.postId}`).push(comment)
return commentRef.then(() => {
dispatch(addComment(
{
comment,
postId: newComment.postId,
id: commentRef.key,
editorStatus: false
}))
callBack()
dispatch(globalActions.hideTopLoading())
if (newComment.ownerPostUserId !== uid)
dispatch(notifyActions.dbAddNotify(
{
description: 'Add comment on your post.',
url: `/${newComment.ownerPostUserId}/posts/${newComment.postId}`,
notifyRecieverUserId: newComment.ownerPostUserId, notifierUserId: uid
}))
}, (error) => {
dispatch(globalActions.showErrorMessage(error.message))
dispatch(globalActions.hideTopLoading())
})
}
}
/**
* Get all comments from database
*/
export const dbGetComments = () => {
return (dispatch, getState) => {
var uid = getState().authorize.uid
if (uid) {
var commentsRef = firebaseRef.child(`postComments`);
return commentsRef.on('value', (snapshot) => {
var comments = snapshot.val() || {};
dispatch(addCommentList(comments))
})
}
}
}
/**
* Update a comment from database
* @param {string} id of comment
* @param {string} postId is the identifier of the post which comment belong to
*/
export const dbUpdateComment = (id, postId, text) => {
return (dispatch, getState) => {
dispatch(globalActions.showTopLoading())
// Get current user id
var uid = getState().authorize.uid
// Write the new data simultaneously in the list
var updates = {};
let comment = getState().comment.postComments[postId][id]
updates[`postComments/${postId}/${id}`] = {
postId: postId,
score: comment.score,
text: text,
creationDate: comment.creationDate,
userDisplayName: comment.userDisplayName,
userAvatar: comment.userAvatar,
userId: uid
}
return firebaseRef.update(updates).then((result) => {
dispatch(updateComment({ id, postId, text, editorStatus: false }))
dispatch(globalActions.hideTopLoading())
}, (error) => {
dispatch(globalActions.showErrorMessage(error.message))
dispatch(globalActions.hideTopLoading())
})
}
}
/**
* Delete a comment from database
* @param {string} id of comment
* @param {string} postId is the identifier of the post which comment belong to
*/
export const dbDeleteComment = (id, postId) => {
return (dispatch, getState) => {
dispatch(globalActions.showTopLoading())
// Get current user id
var uid = getState().authorize.uid
// Write the new data simultaneously in the list
var updates = {};
updates[`postComments/${postId}/${id}`] = null;
return firebaseRef.update(updates).then((result) => {
dispatch(deleteComment(id, postId))
dispatch(globalActions.hideTopLoading())
}, (error) => {
dispatch(globalActions.showErrorMessage(error.message))
dispatch(globalActions.hideTopLoading())
})
}
}
/* _____________ CRUD State _____________ */
/**
* Add comment
* @param {object} data
*/
export const addComment = (data) => {
return {
type: types.ADD_COMMENT,
payload: data
}
}
/**
* Update comment
* @param {object} data
*/
export const updateComment = (data) => {
return {
type: types.UPDATE_COMMENT,
payload: data
}
}
/**
* Add comment list
* @param {[object]} postComments an array of comments
*/
export const addCommentList = (postComments) => {
return {
type: types.ADD_COMMENT_LIST,
payload: postComments
}
}
/**
* Delete a comment
* @param {string} id of comment
* @param {string} postId is the identifier of the post which comment belong to
*/
export const deleteComment = (id, postId) => {
return { type: types.DELETE_COMMENT, payload: { id, postId } }
}
/**
* Clear all data
*/
export const clearAllData = () => {
return {
type: types.CLEAR_ALL_DATA_COMMENT
}
}
export const openCommentEditor = (comment) => {
return {
type: types.OPEN_COMMENT_EDITOR,
payload: comment
}
}
export const closeCommentEditor = (comment) => {
return {
type: types.CLOSE_COMMENT_EDITOR,
payload: comment
}
}

View File

@@ -0,0 +1,232 @@
// - Import react components
import moment from 'moment'
import { firebaseRef } from 'app/firebase/'
// - Import domain
import { Comment } from "domain/comments";
// - Import action types
import {CommentActionType} from 'constants/commentActionType'
// - Import actions
import * as globalActions from 'actions/globalActions'
import * as notifyActions from 'actions/notifyActions'
/* _____________ CRUD DB _____________ */
/**
* Add comment to database
* @param {object} ownerPostUserId the identifier of the user who is the owner of the post which comment belong to
* @param {object} newComment user comment
* @param {function} callBack will be fired when server responsed
*/
export const dbAddComment = (ownerPostUserId: string,newComment: Comment, callBack: Function) => {
return (dispatch: any, getState: Function) => {
dispatch(globalActions.showTopLoading())
let uid: string = getState().authorize.uid
let comment: Comment = {
score : 0,
creationDate : moment().unix(),
userDisplayName : getState().user.info[uid].fullName,
userAvatar : getState().user.info[uid].avatar,
userId : uid,
postId: newComment.postId,
text: newComment.text
}
let commentRef: any = firebaseRef.child(`postComments/${newComment.postId}`).push(comment)
return commentRef.then(() => {
dispatch(addComment(newComment))
callBack()
dispatch(globalActions.hideTopLoading())
if (ownerPostUserId && ownerPostUserId !== uid)
dispatch(notifyActions.dbAddNotify(
{
description: 'Add comment on your post.',
url: `/${ownerPostUserId}/posts/${newComment.postId}`,
notifyRecieverUserId: ownerPostUserId, notifierUserId: uid
}))
}, (error: any) => {
dispatch(globalActions.showErrorMessage(error.message))
dispatch(globalActions.hideTopLoading())
})
}
}
/**
* Get all comments from database
*/
export const dbGetComments = () => {
return (dispatch: any, getState: Function) => {
let uid: string = getState().authorize.uid
if (uid) {
let commentsRef: any = firebaseRef.child(`postComments`);
return commentsRef.on('value', (snapshot: any) => {
let comments: {[postId: string]: {[commentId: string] : Comment}} = snapshot!.val() || {};
dispatch(addCommentList(comments))
})
}
}
}
/**
* Update a comment from database
* @param {string} id of comment
* @param {string} postId is the identifier of the post which comment belong to
* @param {string} text is the text of comment
*/
export const dbUpdateComment = (id: string, postId: string, text: string) => {
return (dispatch: any, getState: Function) => {
dispatch(globalActions.showTopLoading())
// Get current user id
let uid: string = getState().authorize.uid
// Write the new data simultaneously in the list
let updates: any = {};
let comment: Comment = getState().comment.postComments[postId][id]
updates[`postComments/${postId}/${id}`] = {
postId: postId,
score: comment.score,
text: text,
creationDate: comment.creationDate,
userDisplayName: comment.userDisplayName,
userAvatar: comment.userAvatar,
userId: uid
}
return firebaseRef.update(updates).then((result) => {
dispatch(updateComment( id, postId, text))
dispatch(globalActions.hideTopLoading())
}, (error) => {
dispatch(globalActions.showErrorMessage(error.message))
dispatch(globalActions.hideTopLoading())
})
}
}
/**
* Delete a comment from database
* @param {string} id of comment
* @param {string} postId is the identifier of the post which comment belong to
*/
export const dbDeleteComment = (id: string, postId: string) => {
return (dispatch: any, getState: Function) => {
dispatch(globalActions.showTopLoading())
// Get current user id
let uid: string = getState().authorize.uid
// Write the new data simultaneously in the list
let updates: any = {};
updates[`postComments/${postId}/${id}`] = null;
return firebaseRef.update(updates).then((result) => {
dispatch(deleteComment(id, postId))
dispatch(globalActions.hideTopLoading())
}, (error) => {
dispatch(globalActions.showErrorMessage(error.message))
dispatch(globalActions.hideTopLoading())
})
}
}
/* _____________ CRUD State _____________ */
/**
* Add comment
* @param {Comment} data
*/
export const addComment = (comment:Comment) => {
return {
type: CommentActionType.ADD_COMMENT,
payload: comment
}
}
/**
*
* @param id comment identifier
* @param postId post identefier which comment belong to
* @param text the new text for comment
*/
export const updateComment = ( id: string, postId: string, text: string) => {
return {
type: CommentActionType.UPDATE_COMMENT,
payload: {id, postId, text}
}
}
/**
* Add comment list
* @param {[postId: string]: {[commentId: string] : Comment}} postComments an array of comments
*/
export const addCommentList = (postComments: {[postId: string]: {[commentId: string] : Comment}}) => {
return {
type: CommentActionType.ADD_COMMENT_LIST,
payload: postComments
}
}
/**
* Delete a comment
* @param {string} id of comment
* @param {string} postId is the identifier of the post which comment belong to
*/
export const deleteComment = (id: string, postId: string) => {
return { type: CommentActionType.DELETE_COMMENT, payload: { id, postId } }
}
/**
* Clear all data
*/
export const clearAllData = () => {
return {
type: CommentActionType.CLEAR_ALL_DATA_COMMENT
}
}
export const openCommentEditor = (comment: Comment) => {
return {
type: CommentActionType.OPEN_COMMENT_EDITOR,
payload: comment
}
}
export const closeCommentEditor = (comment: Comment) => {
return {
type: CommentActionType.CLOSE_COMMENT_EDITOR,
payload: comment
}
}

View File

@@ -1,19 +1,19 @@
// - Import image gallery action types
import * as types from 'actionTypes'
import {GlobalActionType} from 'constants/globalActionType'
// - Import actions
import * as postActions from 'postActions'
import * as commentActions from 'commentActions'
import * as userActions from 'userActions'
import * as postActions from 'actions/postActions'
import * as commentActions from 'actions/commentActions'
import * as userActions from 'actions/userActions'
/**
* Progress change
* @param {string} percent
* @param {boolean} visible
*/
export const progressChange = (percent, visible) => {
export const progressChange = (percent: number, visible: Boolean) => {
return {
type: types.PROGRESS_CHANGE,
type: GlobalActionType.PROGRESS_CHANGE,
payload: {percent, visible}
}
@@ -24,7 +24,7 @@ export const progressChange = (percent, visible) => {
*/
export const defaultDataEnable = () => {
return{
type: types.DEFAULT_DATA_ENABLE
type: GlobalActionType.DEFAULT_DATA_ENABLE
}
}
@@ -34,7 +34,7 @@ export const defaultDataEnable = () => {
*/
export const defaultDataDisable = () => {
return{
type: types.DEFAULT_DATA_DISABLE
type: GlobalActionType.DEFAULT_DATA_DISABLE
}
}
@@ -42,14 +42,14 @@ export const defaultDataDisable = () => {
// - Show notification of request
export const showNotificationRequest = () => {
return{
type: types.SHOW_SEND_REQUEST_MESSAGE_GLOBAL
type: GlobalActionType.SHOW_SEND_REQUEST_MESSAGE_GLOBAL
}
}
// - Show notification of success
export const showNotificationSuccess = () => {
return{
type: types.SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL
type: GlobalActionType.SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL
}
}
@@ -58,7 +58,7 @@ export const showNotificationSuccess = () => {
*/
export const hideMessage = () => {
return{
type: types.HIDE_MESSAGE_GLOBAL
type: GlobalActionType.HIDE_MESSAGE_GLOBAL
}
}
@@ -67,9 +67,9 @@ export const hideMessage = () => {
* Show error message
* @param {string} message
*/
export const showErrorMessage = (message) => {
export const showErrorMessage = (message: string) => {
return {
type: types.SHOW_ERROR_MESSAGE_GLOBAL,
type: GlobalActionType.SHOW_ERROR_MESSAGE_GLOBAL,
payload: message
}
@@ -78,9 +78,9 @@ export const showErrorMessage = (message) => {
/**
* Set header title
*/
export const setHeaderTitleOpt = (opt,payload) => {
return (dispatch,getState) => {
switch (opt) {
export const setHeaderTitleOpt = (callerKey: string,payload: any) => {
return (dispatch: any,getState: Function) => {
switch (callerKey) {
case 'profile':
const userName = getState().user.info && getState().user.info[payload] ? getState().user.info[payload].fullName : ''
dispatch(setHeaderTitle(userName))
@@ -97,9 +97,9 @@ export const setHeaderTitleOpt = (opt,payload) => {
/**
* Set header title
*/
export const setHeaderTitle = (text) => {
export const setHeaderTitle = (text: string) => {
return{
type: types.SET_HEADER_TITLE,
type: GlobalActionType.SET_HEADER_TITLE,
payload: text
}
@@ -110,7 +110,7 @@ export const setHeaderTitle = (text) => {
*/
export const openPostWrite = () => {
return{
type: types.OPEN_POST_WRITE
type: GlobalActionType.OPEN_POST_WRITE
}
}
@@ -120,7 +120,7 @@ export const openPostWrite = () => {
*/
export const closePostWrite = () => {
return{
type: types.CLOSE_POST_WRITE
type: GlobalActionType.CLOSE_POST_WRITE
}
}
@@ -130,7 +130,7 @@ export const closePostWrite = () => {
*/
export const showTopLoading = () => {
return{
type: types.SHOW_TOP_LOADING
type: GlobalActionType.SHOW_TOP_LOADING
}
}
@@ -140,7 +140,7 @@ export const showTopLoading = () => {
*/
export const hideTopLoading = () => {
return{
type: types.HIDE_TOP_LOADING
type: GlobalActionType.HIDE_TOP_LOADING
}
}
@@ -151,9 +151,9 @@ export const hideTopLoading = () => {
/**
* Store temp data
*/
export const temp = (data) => {
export const temp = (data: string) => {
return{
type: types.TEMP,
type: GlobalActionType.TEMP,
payload: data
}
@@ -163,7 +163,7 @@ export const temp = (data) => {
// - Load data for guest
export const loadDataGuest = () => {
return (dispatch,getState) => {
return (dispatch: any,getState: Function) => {
}
}

View File

@@ -2,49 +2,34 @@
import moment from 'moment'
import { firebaseRef, firebaseAuth, storageRef } from 'app/firebase/'
// - Import domain
import { Image } from "domain/imageGallery";
// - Import action types
import * as types from 'actionTypes'
import {ImageGalleryActionType} from 'constants/imageGalleryActionType'
// - Import actions
import * as globalActions from 'globalActions'
import * as globalActions from 'actions/globalActions'
// - Import app API
import FileAPI from 'FileAPI'
import FileAPI from 'api/FileAPI'
/* _____________ UI Actions _____________ */
/**
* Clear selected data
*/
export const clearSelectData = () => {
return { type: types.CLEARS_SELECT_IMAGE_GALLERY }
}
/**
* Clear all data in image gallery store
*/
export const clearAllData = () => {
return {
type: types.CLEAT_ALL_DATA_IMAGE_GALLERY
}
}
declare const console: any;
/**
* Download images for image gallery
*/
export const downloadForImageGallery = () => {
return (dispatch, getState) => {
var uid = getState().authorize.uid
return (dispatch: any, getState: Function) => {
let uid: string = getState().authorize.uid
if (uid) {
var imagesRef = firebaseRef.child(`userFiles/${uid}/files/images`);
let imagesRef: any = firebaseRef.child(`userFiles/${uid}/files/images`);
return imagesRef.once('value').then((snapshot) => {
return imagesRef.once('value').then((snapshot: any) => {
var images = snapshot.val() || {};
var parsedImages = []
var parsedImages: Image[] = []
Object.keys(images).forEach((imageId) => {
parsedImages.push({
id: imageId,
@@ -64,18 +49,19 @@ export const downloadForImageGallery = () => {
/**
* Save image URL in the server
* @param {string} imageURL is the URL of image
* @param {string} imageFullPath is the folder name + / + file name
*/
export const dbSaveImage = (imageURL,imageFullPath) => {
return (dispatch, getState) => {
export const dbSaveImage = (imageURL: string,imageFullPath: string) => {
return (dispatch: any, getState: Function) => {
var uid = getState().authorize.uid
var image = {
let uid: string = getState().authorize.uid
var image: Image = {
creationDate: moment().unix(),
deletationDate: '',
deleteDate: '',
URL: imageURL,
fullPath:imageFullPath,
ownerUserId: uid,
lastEditDate: '',
lastEditDate: 0,
deleted: false
}
@@ -94,14 +80,14 @@ export const dbSaveImage = (imageURL,imageFullPath) => {
* Delete an image from database
* @param {string} id of image
*/
export const dbDeleteImage = (id) => {
return (dispatch, getState) => {
export const dbDeleteImage = (id: string) => {
return (dispatch: any, getState: Function) => {
// Get current user id
var uid = getState().authorize.uid
let uid: string = getState().authorize.uid;
// Write the new data simultaneously in the list
var updates = {};
var updates: any = {};
updates[`userFiles/${uid}/files/images/${id}`] = null;
return firebaseRef.update(updates).then((result) => {
@@ -119,30 +105,30 @@ export const dbDeleteImage = (id) => {
* @param {file} file
* @param {string} fileName
*/
export const dbUploadImage = (file, fileName) => {
return (dispatch, getState) => {
export const dbUploadImage = (file: any, fileName: string) => {
return (dispatch: any, getState: Function) => {
// Create a storage refrence
var storegeFile = storageRef.child(`images/${fileName}`)
let storegeFile: any = storageRef.child(`images/${fileName}`)
// Upload file
var task = storegeFile.put(file)
let task: any = storegeFile.put(file)
dispatch(globalActions.showTopLoading())
// Upload storage bar
task.on('state_changed', (snapshot) => {
task.on('state_changed', (snapshot: any) => {
var percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100
dispatch(globalActions.progressChange(percentage, true))
}, (error) => {
}, (error: any) => {
dispatch(globalActions.showErrorMessage(error.code))
dispatch(globalActions.hideTopLoading())
}, (complete) => {
}, (complete?: any ) => {
dispatch(globalActions.progressChange(100, false))
dispatch(dbSaveImage(fileName))
dispatch(dbSaveImage(fileName,''))
dispatch(globalActions.hideTopLoading())
})
}
}
@@ -151,9 +137,9 @@ export const dbUploadImage = (file, fileName) => {
* Download image from server
* @param {string} fileName
*/
export const dbDownloadImage = (fileName) => {
export const dbDownloadImage = (fileName: string) => {
return (dispatch, getState) => {
return (dispatch: any, getState: Function) => {
if (fileName == 'noImage')
return {}
if (getState().imageGallery.imageURLList[fileName] && fileName !== '')
@@ -164,14 +150,14 @@ export const dbDownloadImage = (fileName) => {
dispatch(sendImageRequest(fileName))
// Create a reference to the file we want to download
var starsRef = storageRef.child(`images/${fileName}`);
let starsRef: any = storageRef.child(`images/${fileName}`);
// Get the download URL
starsRef.getDownloadURL().then((url) => {
starsRef.getDownloadURL().then((url: string) => {
// Insert url into an <img> tag to "download"
if (!getState().imageGallery.imageURLList[fileName] || fileName === '')
dispatch(setImageURL(fileName, url))
}).catch((error) => {
}).catch((error:any) => {
// A full list of error codes is available at
// https://firebase.google.com/docs/storage/web/handle-errors
@@ -204,46 +190,55 @@ export const dbDownloadImage = (fileName) => {
/**
* Add image list to image gallery
* @param {[object]} images is an array of images
* @param {Image[]} images is an array of images
*/
export const addImageList = (images) => {
return { type: types.ADD_IMAGE_LIST_GALLERY, images }
export const addImageList = (images: Image[]) => {
return { type: ImageGalleryActionType.ADD_IMAGE_LIST_GALLERY,payload: images }
}
/**
* Add image to image gallery
* @param {object} image
* @param {Image} image
*/
export const addImage = (image) => {
return { type: types.ADD_IMAGE_GALLERY, image }
export const addImage = (image: Image) => {
return { type: ImageGalleryActionType.ADD_IMAGE_GALLERY, payload: image }
}
/**
* Delete an image
* @param {string} id is an image identifier
*/
export const deleteImage = (id) => {
return { type: types.DELETE_IMAGE, id }
export const deleteImage = (id: string) => {
return { type: ImageGalleryActionType.DELETE_IMAGE, payload: id }
}
/**
* Delete an image
*/
export const setImageURL = (name, url) => {
export const setImageURL = (name: string, url: string) => {
return {
type: types.SET_IMAGE_URL,
type: ImageGalleryActionType.SET_IMAGE_URL,
payload: { name, url }
}
}
/**
* Clear all data in image gallery store
*/
export const clearAllData = () => {
return {
type: ImageGalleryActionType.CLEAT_ALL_DATA_IMAGE_GALLERY
}
}
/**
* Send image request
*/
export const sendImageRequest = (name) => {
export const sendImageRequest = (name: string) => {
return {
type: types.SEND_IMAGE_REQUEST,
type: ImageGalleryActionType.SEND_IMAGE_REQUEST,
payload: name
}

View File

@@ -2,12 +2,15 @@
import moment from 'moment'
import { firebaseRef } from 'app/firebase/'
// - Import domain
import { Notification } from "domain/notifications";
// - Import action types
import * as types from 'actionTypes'
import {NotificationActionType} from 'constants/notificationActionType'
// - Import actions
import * as globalActions from 'globalActions'
import * as userActions from 'userActions'
import * as globalActions from 'actions/globalActions'
import * as userActions from 'actions/userActions'
/* _____________ CRUD DB _____________ */
@@ -16,21 +19,23 @@ import * as userActions from 'userActions'
* Add notificaition to database
* @param {object} newNotify user notificaition
*/
export const dbAddNotify = (newNotify) => {
return (dispatch, getState) => {
export const dbAddNotify = (newNotify: Notification) => {
return (dispatch: any, getState: Function) => {
var uid = getState().authorize.uid
var notify = {
let uid: string = getState().authorize.uid
let notify: Notification = {
isSeen: false,
description: newNotify.description,
url: newNotify.url,
notifierUserId: newNotify.notifierUserId,
isSeen: false
notifyRecieverUserId: newNotify.notifyRecieverUserId
}
var notifyRef = firebaseRef.child(`userNotifies/${newNotify.notifyRecieverUserId}`).push(notify)
let notifyRef: any = firebaseRef.child(`userNotifies/${newNotify.notifyRecieverUserId}`).push(notify)
return notifyRef.then(() => {
dispatch(addNotify())
}, (error) => dispatch(globalActions.showErrorMessage(error.message)))
}, (error: any) => dispatch(globalActions.showErrorMessage(error.message)))
}
}
@@ -39,17 +44,17 @@ export const dbAddNotify = (newNotify) => {
* Get all notificaitions from database
*/
export const dbGetNotifies = () => {
return (dispatch, getState) => {
var uid = getState().authorize.uid
return (dispatch: any, getState: Function) => {
let uid: string = getState().authorize.uid
if (uid) {
var notifiesRef = firebaseRef.child(`userNotifies/${uid}`);
let notifiesRef: any = firebaseRef.child(`userNotifies/${uid}`);
return notifiesRef.on('value', (snapshot) => {
var notifies = snapshot.val() || {};
return notifiesRef.on('value', (snapshot: any) => {
let notifies: {[notifyId: string]: Notification} = snapshot.val() || {};
Object.keys(notifies).forEach((key => {
if (!getState().user.info[notifies[key].notifierUserId]) {
dispatch(userActions.dbGetUserInfoByUserId(notifies[key].notifierUserId))
dispatch(userActions.dbGetUserInfoByUserId(notifies[key].notifierUserId,''))
}
}))
@@ -65,14 +70,14 @@ export const dbGetNotifies = () => {
* Delete a notificaition from database
* @param {string} id of notificaition
*/
export const dbDeleteNotify = (id) => {
return (dispatch, getState) => {
export const dbDeleteNotify = (id: string) => {
return (dispatch: any, getState: Function) => {
// Get current user id
var uid = getState().authorize.uid
var uid: string = getState().authorize.uid
// Write the new data simultaneously in the list
var updates = {};
var updates: any = {};
updates[`userNotifies/${uid}/${id}`] = null;
return firebaseRef.update(updates).then((result) => {
@@ -88,21 +93,21 @@ export const dbDeleteNotify = (id) => {
* Make seen a notificaition from database
* @param {string} id of notificaition
*/
export const dbSeenNotify = (id) => {
return (dispatch, getState) => {
export const dbSeenNotify = (id: string) => {
return (dispatch: any, getState: Function) => {
// Get current user id
var uid = getState().authorize.uid
let notify = getState().notify.userNotifies[id]
let updatedNotify = {
let uid: string = getState().authorize.uid
let notify: Notification = getState().notify.userNotifies[id]
let updates: any = {};
updates[`userNotifies/${uid}/${id}`] = {
description: notify.description,
url: notify.url,
notifierUserId: notify.notifierUserId,
isSeen: true
}
// Write the new data simultaneously in the list
var updates = {};
updates[`userNotifies/${uid}/${id}`] = updatedNotify;
return firebaseRef.update(updates).then((result) => {
dispatch(seenNotify(id))
@@ -116,23 +121,22 @@ export const dbSeenNotify = (id) => {
/**
* Add notificaition
* @param {object} data
*/
export const addNotify = () => {
return {
type: types.ADD_NOTIFY
type: NotificationActionType.ADD_NOTIFY
}
}
/**
* Add notificaition list
* @param {[object]} userNotifies an array of notificaitions
* @param {[notifyId: string]: Notification} userNotifies an array of notificaitions
*/
export const addNotifyList = (userNotifies) => {
export const addNotifyList = (userNotifies: {[notifyId: string]: Notification}) => {
return {
type: types.ADD_NOTIFY_LIST,
type: NotificationActionType.ADD_NOTIFY_LIST,
payload: userNotifies
}
}
@@ -142,8 +146,8 @@ export const addNotifyList = (userNotifies) => {
* Delete a notificaition
* @param {string} id of notificaition
*/
export const deleteNotify = (id) => {
return { type: types.DELETE_NOTIFY, payload: id }
export const deleteNotify = (id: string) => {
return { type: NotificationActionType.DELETE_NOTIFY, payload: id }
}
@@ -151,8 +155,8 @@ export const deleteNotify = (id) => {
* Change notificaition to has seen status
* @param {string} id of notificaition
*/
export const seenNotify = (id) => {
return { type: types.SEEN_NOTIFY, payload: id }
export const seenNotify = (id: string) => {
return { type: NotificationActionType.SEEN_NOTIFY, payload: id }
}
@@ -161,7 +165,7 @@ export const seenNotify = (id) => {
*/
export const clearAllNotifications = () => {
return {
type: types.CLEAR_ALL_DATA_NOTIFY
type: NotificationActionType.CLEAR_ALL_DATA_NOTIFY
}
}

View File

@@ -4,6 +4,9 @@ import { Action } from "redux";
// - Import firebase component
import firebase, { firebaseRef } from '../firebase';
// - Import domain
import { Post } from "domain/posts";
// - Import utility components
import moment from 'moment';
@@ -13,7 +16,7 @@ import { PostActionType } from 'constants/postActionType';
// - Import actions
import * as globalActions from 'actions/globalActions';
declare const console: any;
@@ -23,27 +26,28 @@ import * as globalActions from 'actions/globalActions';
/**
* Add a normal post
* @param {object} newPost
* @param {function} callBack
* @param {any} newPost
* @param {Function} callBack
*/
export var dbAddPost = (newPost: any, callBack: any) => {
return (dispatch: any, getState: any) => {
export var dbAddPost = (newPost: any, callBack: Function) => {
return (dispatch: any, getState: Function) => {
var uid = getState().authorize.uid
var post = {
let uid: string = getState().authorize.uid
let post: Post = {
postTypeId: 0,
creationDate: moment().unix(),
deletationDate: '',
deleteDate: 0,
score: 0,
viewCount: 0,
body: newPost.body,
ownerUserId: uid,
ownerDisplayName: newPost.name,
ownerAvatar: newPost.avatar,
lastEditDate: '',
lastEditDate: 0,
tags: newPost.tags || [],
commentCounter: 0,
image: '',
imageFullPath:'',
video: '',
disableComments: newPost.disableComments,
disableSharing: newPost.disableSharing,
@@ -51,7 +55,7 @@ export var dbAddPost = (newPost: any, callBack: any) => {
}
var postRef = firebaseRef.child(`userPosts/${uid}/posts`).push(post)
let postRef: any = firebaseRef.child(`userPosts/${uid}/posts`).push(post)
return postRef.then(() => {
dispatch(addPost(uid, {
...post,
@@ -68,23 +72,23 @@ export var dbAddPost = (newPost: any, callBack: any) => {
* @param {object} newPost
* @param {function} callBack
*/
export const dbAddImagePost = (newPost: any, callBack: any) => {
return (dispatch: any, getState: any) => {
export const dbAddImagePost = (newPost: any, callBack: Function) => {
return (dispatch: any, getState: Function) => {
dispatch(globalActions.showTopLoading())
var uid = getState().authorize.uid
var post = {
let uid: string = getState().authorize.uid
let post: Post = {
postTypeId: 1,
creationDate: moment().unix(),
deletationDate: '',
deleteDate: 0,
score: 0,
viewCount: 0,
body: newPost.body,
ownerUserId: uid,
ownerDisplayName: newPost.name,
ownerAvatar: newPost.avatar,
lastEditDate: '',
lastEditDate: 0,
tags: newPost.tags || [],
commentCounter: 0,
image: newPost.image || '',
@@ -115,9 +119,9 @@ export const dbAddImagePost = (newPost: any, callBack: any) => {
* @param {object} newPost
* @param {func} callBack //TODO: anti pattern should change to parent state or move state to redux
*/
export const dbUpdatePost = (newPost: any, callBack: any) => {
export const dbUpdatePost = (newPost: any, callBack: Function) => {
console.log(newPost)
return (dispatch : any, getState: any) => {
return (dispatch : any, getState: Function) => {
dispatch(globalActions.showTopLoading())
@@ -126,11 +130,11 @@ export const dbUpdatePost = (newPost: any, callBack: any) => {
// Write the new data simultaneously in the list
let updates: any = {};
let post = getState().post.userPosts[uid][newPost.id]
let updatedPost = {
let post: Post = getState().post.userPosts[uid][newPost.id]
let updatedPost: Post = {
postTypeId: post.postTypeId,
creationDate: post.creationDate,
deletationDate: '',
deleteDate: 0,
score: post.score,
viewCount: post.viewCount,
body: newPost.body ? newPost.body : post.body || '',
@@ -141,6 +145,7 @@ export const dbUpdatePost = (newPost: any, callBack: any) => {
tags: newPost.tags ? newPost.tags : (post.tags || []),
commentCounter: post.commentCounter,
image: newPost.image ? newPost.image : post.image,
imageFullPath: newPost.imageFullPath!,
video: '',
disableComments: newPost.disableComments !== undefined ? newPost.disableComments : (post.disableComments ? post.disableComments : false),
disableSharing: newPost.disableSharing !== undefined ? newPost.disableSharing : (post.disableSharing ? post.disableSharing : false),
@@ -167,7 +172,7 @@ export const dbUpdatePost = (newPost: any, callBack: any) => {
* @param {string} id is post identifier
*/
export const dbDeletePost = (id: string) => {
return (dispatch:any, getState:any) => {
return (dispatch:any, getState:Function) => {
dispatch(globalActions.showTopLoading())
@@ -175,7 +180,7 @@ export const dbDeletePost = (id: string) => {
let uid : string = getState().authorize.uid
// Write the new data simultaneously in the list
var updates : any= {};
let updates : any= {};
updates[`userPosts/${uid}/posts/${id}`] = null;
return firebaseRef.update(updates).then((result) => {
@@ -191,17 +196,17 @@ export const dbDeletePost = (id: string) => {
}
/**
* Get all user posts from data base
* Get all user posts from data base
*/
export const dbGetPosts = () => {
return (dispatch:any, getState:any) => {
var uid = getState().authorize.uid
let uid: string = getState().authorize.uid
if (uid) {
var postsRef = firebaseRef.child(`userPosts/${uid}/posts`);
let postsRef: any = firebaseRef.child(`userPosts/${uid}/posts`);
return postsRef.once('value').then((snapshot) => {
var posts = snapshot.val() || {};
var parsedPosts : any = {};
return postsRef.once('value').then((snapshot: any) => {
var posts: any = snapshot.val() || {};
var parsedPosts : {[postId: string]: Post} = {};
Object.keys(posts).forEach((postId) => {
parsedPosts[postId] = {
id: postId,
@@ -217,14 +222,16 @@ export const dbGetPosts = () => {
}
/**
* Get all user posts from data base
*/
* Get all user posts from data base
* @param uid post owner identifier
* @param postId post identifier
*/
export const dbGetPostById = (uid:string, postId:string) => {
return (dispatch: any, getState: any) => {
return (dispatch: any, getState: Function) => {
if (uid) {
var postsRef = firebaseRef.child(`userPosts/${uid}/posts/${postId}`);
let postsRef: any = firebaseRef.child(`userPosts/${uid}/posts/${postId}`);
return postsRef.once('value').then((snapshot) => {
return postsRef.once('value').then((snapshot: any) => {
const newPost = snapshot.val() || {};
const post = {
id: postId,
@@ -239,17 +246,18 @@ export const dbGetPostById = (uid:string, postId:string) => {
/**
* Get all user posts from data base by user id
* Get all user posts from data base by user id
* @param uid posts owner identifier
*/
export const dbGetPostsByUserId = (uid: string) => {
return (dispatch: any, getState: any) => {
return (dispatch: any, getState: Function) => {
if (uid) {
let postsRef = firebaseRef.child(`userPosts/${uid}/posts`);
let postsRef: any = firebaseRef.child(`userPosts/${uid}/posts`);
return postsRef.once('value').then((snapshot) => {
let posts = snapshot.val() || {};
let parsedPosts: any = {};
return postsRef.once('value').then((snapshot: any) => {
let posts: any = snapshot.val() || {};
let parsedPosts: {[postId: string]: Post} = {};
Object.keys(posts).forEach((postId) => {
parsedPosts[postId] = {
id: postId,
@@ -274,9 +282,9 @@ export const dbGetPostsByUserId = (uid: string) => {
/**
* Add a normal post
* @param {string} uid is user identifier
* @param {object} post
* @param {Post} post
*/
export const addPost = (uid: string, post: any) => {
export const addPost = (uid: string, post: Post) => {
return {
type: PostActionType.ADD_POST,
payload: { uid, post }
@@ -286,9 +294,9 @@ export const addPost = (uid: string, post: any) => {
/**
* Update a post
* @param {string} uid is user identifier
* @param {object} post
* @param {Post} post
*/
export const updatePost = (uid: string, post: any) => {
export const updatePost = (uid: string, post: Post) => {
return {
type: PostActionType.UPDATE_POST,
payload: { uid, post }
@@ -313,7 +321,7 @@ export const deletePost = (uid: string, id: string) => {
* @param {string} uid
* @param {[object]} posts
*/
export const addPosts = (uid: string, posts: any) => {
export const addPosts = (uid: string, posts: {[postId: string]: Post}) => {
return {
type: PostActionType.ADD_LIST_POST,
payload: { uid, posts }

View File

@@ -1,210 +0,0 @@
// - Import react components
import { firebaseRef } from 'app/firebase/'
// - Import action types
import * as types from 'actionTypes'
// - Import actions
import * as globalActions from 'globalActions'
import * as userActions from 'userActions'
/* _____________ CRUD DB _____________ */
/**
* Get user info from database
*/
export const dbGetUserInfo = () => {
return (dispatch, getState) => {
var uid = getState().authorize.uid
if (uid) {
var userInfoRef = firebaseRef.child(`users/${uid}/info`);
return userInfoRef.once('value').then((snapshot) => {
var userInfo = snapshot.val() || {};
dispatch(addUserInfo(uid, {
avatar: userInfo.avatar,
email: userInfo.email,
fullName: userInfo.fullName,
banner: userInfo.banner,
tagLine: userInfo.tagLine
}))
}, error => console.log(error));
}
}
}
/**
* Get user info from database
* @param {string} uid
*/
export const dbGetUserInfoByUserId = (uid, sw) => {
return (dispatch, getState) => {
if (uid) {
var userInfoRef = firebaseRef.child(`users/${uid}/info`);
return userInfoRef.once('value').then((snapshot) => {
var userInfo = snapshot.val() || {};
dispatch(addUserInfo(uid, {
avatar: userInfo.avatar,
email: userInfo.email,
fullName: userInfo.fullName,
banner: userInfo.banner,
tagLine: userInfo.tagLine
}))
switch (sw) {
case 'header':
dispatch(globalActions.setHeaderTitle(userInfo.fullName))
break;
default:
break;
}
}, error => console.log(error));
}
}
}
/**
* Updata user information
* @param {object} newInfo
*/
export const dbUpdateUserInfo = (newInfo) => {
return (dispatch, getState) => {
// Get current user id
var uid = getState().authorize.uid
// Write the new data simultaneously in the list
let updates = {};
let info = getState().user.info[uid]
let updatedInfo = {
avatar: newInfo.avatar || info.avatar || '',
banner: newInfo.banner || info.banner || 'https://firebasestorage.googleapis.com/v0/b/open-social-33d92.appspot.com/o/images%2F751145a1-9488-46fd-a97e-04018665a6d3.JPG?alt=media&token=1a1d5e21-5101-450e-9054-ea4a20e06c57',
email: newInfo.email || info.email || '',
fullName: newInfo.fullName || info.fullName || '',
tagLine: newInfo.tagLine || info.tagLine || ''
}
updates[`users/${uid}/info`] = updatedInfo
return firebaseRef.update(updates).then((result) => {
dispatch(updateUserInfo(uid, updatedInfo))
dispatch(closeEditProfile())
}, (error) => {
dispatch(globalActions.showErrorMessage(error.message))
})
}
}
// - Get people info from database
export const dbGetPeopleInfo = () => {
return (dispatch, getState) => {
var uid = getState().authorize.uid
if (uid) {
var peopleRef = firebaseRef.child(`users`);
return peopleRef.once('value').then((snapshot) => {
let people = snapshot.val() || {};
let parsedPeople = {};
Object.keys(people).forEach((userId) => {
if (userId !== uid) {
let userInfo = people[userId].info
parsedPeople[userId] = {
avatar: userInfo.avatar,
email: userInfo.email,
fullName: userInfo.fullName,
banner: userInfo.banner,
tagLine: userInfo.tagLine
}
}
})
dispatch(addPeopleInfo(parsedPeople))
}, error => console.log(error));
}
}
}
/* _____________ CRUD State _____________ */
/**
* Add user information
* @param {string} uid is the user identifier
* @param {object} info is the information about user
*/
export const addUserInfo = (uid, info) => {
return {
type: types.ADD_USER_INFO,
payload: { uid, info }
}
}
/**
* Add people information
* @param {[object]} infoList is the lst of information about users
*/
export const addPeopleInfo = (infoList) => {
return {
type: types.ADD_PEOPLE_INFO,
payload: infoList
}
}
/**
* Update user information
* @param {string} uid is the user identifier
* @param {object} info is the information about user
*/
export const updateUserInfo = (uid, info) => {
return {
type: types.UPDATE_USER_INFO,
payload: { uid, info }
}
}
/**
* User info
* @param {object} info
*/
export const userInfo = (info) => {
return {
type: types.USER_INFO,
info
}
}
export const clearAllData = () => {
return {
type: types.CLEAR_ALL_DATA_USER
}
}
/**
* Open edit profile
*/
export const openEditProfile = () => {
return {
type: types.OPEN_EDIT_PROFILE
}
}
/**
* Close edit profile
*/
export const closeEditProfile = () => {
return {
type: types.CLOSE_EDIT_PROFILE
}
}

215
app/actions/userActions.ts Normal file
View File

@@ -0,0 +1,215 @@
// - Import react components
import { firebaseRef } from 'app/firebase/'
// - Import domain
import { Profile } from "domain/users";
// - Import action types
import {UserActionType} from 'constants/userActionType'
// - Import actions
import * as globalActions from 'actions/globalActions'
import * as userActions from 'actions/userActions'
declare const console: any;
/* _____________ CRUD DB _____________ */
/**
* Get user info from database
*/
export const dbGetUserInfo = () => {
return (dispatch: any, getState: Function) => {
let uid: string = getState().authorize.uid
if (uid) {
let userProfileRef: any = firebaseRef.child(`users/${uid}/info`);
return userProfileRef.once('value').then((snapshot: any) => {
let userProfile: Profile = snapshot.val() || {};
dispatch(addUserInfo(uid, {
avatar: userProfile.avatar,
email: userProfile.email,
fullName: userProfile.fullName,
banner: userProfile.banner,
tagLine: userProfile.tagLine
}))
}, (error: any) => console.log(error));
}
}
}
/**
* Get user info from database
* @param {string} uid
* @param {string} callerKey
*/
export const dbGetUserInfoByUserId = (uid: string, callerKey: string) => {
return (dispatch: any, getState: Function) => {
if (uid) {
let userProfileRef: any = firebaseRef.child(`users/${uid}/info`);
return userProfileRef.once('value').then((snapshot: any) => {
let userProfile = snapshot.val() || {};
dispatch(addUserInfo(uid, {
avatar: userProfile.avatar,
email: userProfile.email,
fullName: userProfile.fullName,
banner: userProfile.banner,
tagLine: userProfile.tagLine
}))
switch (callerKey) {
case 'header':
dispatch(globalActions.setHeaderTitle(userProfile.fullName))
break;
default:
break;
}
}, (error: any) => console.log(error));
}
}
}
/**
* Updata user information
* @param {object} newInfo
*/
export const dbUpdateUserInfo = (newProfile: Profile) => {
return (dispatch: any, getState: Function) => {
// Get current user id
let uid: string = getState().authorize.uid
// Write the new data simultaneously in the list
let updates: any = {};
let profile = getState().user.info[uid]
let updateProfie: Profile = {
avatar: newProfile.avatar || profile.avatar || '',
banner: newProfile.banner || profile.banner || 'https://firebasestorage.googleapis.com/v0/b/open-social-33d92.appspot.com/o/images%2F751145a1-9488-46fd-a97e-04018665a6d3.JPG?alt=media&token=1a1d5e21-5101-450e-9054-ea4a20e06c57',
email: newProfile.email || profile.email || '',
fullName: newProfile.fullName || profile.fullName || '',
tagLine: newProfile.tagLine || profile.tagLine || ''
}
updates[`users/${uid}/info`] = updateProfie
return firebaseRef.update(updates).then((result) => {
dispatch(updateUserInfo(uid, updateProfie))
dispatch(closeEditProfile())
}, (error) => {
dispatch(globalActions.showErrorMessage(error.message))
})
}
}
// - Get people info from database
export const dbGetPeopleInfo = () => {
return (dispatch: any, getState: Function) => {
let uid: string = getState().authorize.uid
if (uid) {
let peopleRef: any = firebaseRef.child(`users`);
return peopleRef.once('value').then((snapshot: any) => {
let people = snapshot.val() || {};
let parsedPeople: {[userId: string]: Profile} = {};
Object.keys(people).forEach((userId) => {
if (userId !== uid) {
let userInfo = people[userId].info
parsedPeople[userId] = {
avatar: userInfo.avatar,
email: userInfo.email,
fullName: userInfo.fullName,
banner: userInfo.banner,
tagLine: userInfo.tagLine
}
}
})
dispatch(addPeopleInfo(parsedPeople))
}, (error: any) => console.log(error));
}
}
}
/* _____________ CRUD State _____________ */
/**
* Add user information
* @param {string} uid is the user identifier
* @param {Profile} info is the information about user
*/
export const addUserInfo = (uid: string, info: Profile) => {
return {
type: UserActionType.ADD_USER_INFO,
payload: { uid, info }
}
}
/**
* Add people information
* @param {[userId: string]: Profile} infoList is the lst of information about users
*/
export const addPeopleInfo = (infoList: {[userId: string]: Profile}) => {
return {
type: UserActionType.ADD_PEOPLE_INFO,
payload: infoList
}
}
/**
* Update user information
* @param {string} uid is the user identifier
* @param {Profile} info is the information about user
*/
export const updateUserInfo = (uid: string, info: Profile) => {
return {
type: UserActionType.UPDATE_USER_INFO,
payload: { uid, info }
}
}
/**
* User info
* @param {Profile} info
*/
export const userInfo = (info: Profile) => {
return {
type: UserActionType.USER_INFO,
info
}
}
export const clearAllData = () => {
return {
type: UserActionType.CLEAR_ALL_DATA_USER
}
}
/**
* Open edit profile
*/
export const openEditProfile = () => {
return {
type: UserActionType.OPEN_EDIT_PROFILE
}
}
/**
* Close edit profile
*/
export const closeEditProfile = () => {
return {
type: UserActionType.CLOSE_EDIT_PROFILE
}
}

View File

@@ -1,130 +0,0 @@
// - Import react components
import {createAction as action} from 'redux-actions'
import moment from 'moment'
import { firebaseRef } from 'app/firebase/'
// - Import action types
import * as types from 'actionTypes'
// - Import actions
import * as globalActions from 'globalActions'
import * as notifyActions from 'notifyActions'
/* _____________ CRUD DB _____________ */
/**
* Add vote to database
* @param {string} postId is the identifier of the post which user vote
*/
export const dbAddVote = (postId,ownerPostUserId) => {
return (dispatch, getState) => {
var uid = getState().authorize.uid
var vote = {
postId: postId,
creationDate: moment().unix(),
userDisplayName: getState().user.info[uid].fullName,
userAvatar: getState().user.info[uid].avatar,
userId: uid
}
var voteRef = firebaseRef.child(`postVotes/${postId}`).push(vote)
return voteRef.then(() => {
dispatch(addVote(
{
vote,
postId: postId,
id: voteRef.key
}))
if(uid !== ownerPostUserId)
dispatch(notifyActions.dbAddNotify(
{
description:'Vote on your post.',
url:`/${ownerPostUserId}/posts/${postId}`,
notifyRecieverUserId:ownerPostUserId,notifierUserId:uid
}))
}, (error) => dispatch(globalActions.showErrorMessage(error.message)))
}
}
/**
* Get all votes from database
*/
export const dbGetVotes = () => {
return (dispatch, getState) => {
var uid = getState().authorize.uid
if (uid) {
var votesRef = firebaseRef.child(`postVotes`);
return votesRef.on('value',(snapshot) => {
var votes = snapshot.val() || {};
dispatch(addVoteList(votes))
})
}
}
}
/**
* Delete a vote from database
* @param {string} id of vote
* @param {string} postId is the identifier of the post which vote belong to
*/
export const dbDeleteVote = (postId) => {
return (dispatch, getState) => {
// Get current user id
var uid = getState().authorize.uid
// Write the new data simultaneously in the list
var updates = {};
let votes = getState().vote.postVotes[postId]
let id = Object.keys(votes).filter((key)=> votes[key].userId === uid)[0]
console.log(' Id : ',id)
updates[`postVotes/${postId}/${id}`] = null;
return firebaseRef.update(updates).then((result) => {
dispatch(deleteVote({id, postId}))
}, (error) => dispatch(globalActions.showErrorMessage(error.message)))
}
}
/**
* Add a vote
* @param {object} data
*/
export const addVote = (data) => {
return { type: types.ADD_VOTE, payload: data }
}
/**
* delete a vote
* @param {object} data
*/
export const deleteVote = (data) => {
return { type: types.DELETE_VOTE, payload: data }
}
/**
* Ad a list of vote
* @param {object} data
*/
export const addVoteList = (data) => {
return { type: types.ADD_VOTE_LIST, payload: data }
}
/**
* Clear all data
*/
export const clearAllvotes = () => {
return { type: types.CLEAR_ALL_DATA_VOTE }
}

135
app/actions/voteActions.ts Normal file
View File

@@ -0,0 +1,135 @@
import moment from 'moment'
import { firebaseRef } from 'app/firebase/'
// - Import action types
import {VoteActionType} from 'constants/voteActionType'
// - Import domain
import { Vote } from "domain/votes";
// - Import actions
import * as globalActions from 'actions/globalActions'
import * as notifyActions from 'actions/notifyActions'
declare const console: any;
/* _____________ CRUD DB _____________ */
/**
* Add vote to database
* @param {string} postId is the identifier of the post which user vote
* @param {string} ownerPostUserId is the identifier of the post owner which user vote
*/
export const dbAddVote = (postId: string,ownerPostUserId: string) => {
return (dispatch: any, getState: Function) => {
let uid: string = getState().authorize.uid;
var vote: Vote = {
postId: postId,
creationDate: moment().unix(),
userDisplayName: getState().user.info[uid].fullName,
userAvatar: getState().user.info[uid].avatar,
userId: uid
}
var voteRef = firebaseRef.child(`postVotes/${postId}`).push(vote)
return voteRef.then(() => {
dispatch(addVote(
{
...vote,
postId: postId,
id: voteRef.key
}))
if(uid !== ownerPostUserId)
dispatch(notifyActions.dbAddNotify(
{
description:'Vote on your post.',
url:`/${ownerPostUserId}/posts/${postId}`,
notifyRecieverUserId:ownerPostUserId,notifierUserId:uid,
isSeen:false
}))
}, (error) => dispatch(globalActions.showErrorMessage(error.message)))
}
}
/**
* Get all votes from database
*/
export const dbGetVotes = () => {
return (dispatch: any, getState: Function) => {
let uid: string = getState().authorize.uid
if (uid) {
let votesRef: any = firebaseRef.child(`postVotes`);
return votesRef.on('value',(snapshot: any) => {
let postVotes: {[postId:string]: {[voteId: string]: Vote}} = snapshot.val() || {};
dispatch(addVoteList(postVotes))
})
}
}
}
/**
* Delete a vote from database
* @param {string} id of vote
* @param {string} postId is the identifier of the post which vote belong to
*/
export const dbDeleteVote = (postId: string) => {
return (dispatch: any, getState: Function) => {
// Get current user id
let uid: string = getState().authorize.uid;
// Write the new data simultaneously in the list
var updates: any = {};
let votes: {[voteId: string]: Vote} = getState().vote.postVotes[postId]
let id: string = Object.keys(votes).filter((key)=> votes[key].userId === uid)[0]
updates[`postVotes/${postId}/${id}`] = null;
return firebaseRef.update(updates).then((result) => {
dispatch(deleteVote(id, postId))
})
.catch((error: any) => dispatch(globalActions.showErrorMessage(error.message)))
}
}
/**
* Add a vote
* @param {Vote} vote
*/
export const addVote = (vote: Vote) => {
return { type: VoteActionType.ADD_VOTE, payload: vote }
}
/**
* delete a vote
* @param {string} id vote identifier
* @param {string} postId post identifier which vote on
*/
export const deleteVote = (id: string, postId: string) => {
return { type: VoteActionType.DELETE_VOTE, payload: {id, postId} }
}
/**
* Ad a list of vote
* @param {[postId:string]: {[voteId: string]: Vote}} votes a list of vote
*/
export const addVoteList = (votes: {[postId:string]: {[voteId: string]: Vote}}) => {
return { type: VoteActionType.ADD_VOTE_LIST, payload: votes }
}
/**
* Clear all data
*/
export const clearAllvotes = () => {
return { type: VoteActionType.CLEAR_ALL_DATA_VOTE }
}

View File

@@ -243,10 +243,9 @@ static propTypes = {
const mapDispatchToProps = (dispatch, ownProps) => {
return {
send: (text, postId, callBack) => {
dispatch(commentActions.dbAddComment({
dispatch(commentActions.dbAddComment(ownProps.ownerPostUserId,{
postId: postId,
text: text,
ownerPostUserId:ownProps.ownerPostUserId
text: text
}, callBack))
}
}

View File

@@ -64,7 +64,7 @@ export class CommentWrite extends Component {
const mapDispatchToProps = (dispatch,ownProps) => {
return{
send: (text,postId,callBack) => {
dispatch(commentActions.dbAddComment({
dispatch(commentActions.dbAddComment(null,{
postId: postId,
text: text
},callBack))

View File

@@ -9,20 +9,13 @@ export const CLEAR_ALL_DATA_POST = 'CLEAR_ALL_DATA_POST'
/* image gallery actions */
export const OPEN_IMAGE_GALLERY = 'OPEN_IMAGE_GALLERY'
export const ADD_IMAGE_GALLERY = 'ADD_IMAGE_GALLERY'
export const ADD_IMAGE_LIST_GALLERY = 'ADD_IMAGES_LIST_GALLERY'
export const IMAGE_SELECT_GALLERY = 'IMAGE_SELECT_GALLERY'
export const CLEARS_SELECT_IMAGE_GALLERY = 'CLEARS_SELECT_IMAGE_GALLERY'
export const CLEAT_ALL_DATA_IMAGE_GALLERY = 'CLEAT_ALL_DATA_IMAGE_GALLERY'
export const DELETE_IMAGE = 'DELETE_IMAGE'
export const SET_IMAGE_URL = 'SET_IMAGE_URL'
export const SEND_IMAGE_REQUEST = 'SEND_IMAGE_REQUEST'
/* image uploader actions */
export const OPEN_IMAGE_UPLOADER = 'OPEN_IMAGE_UPLOADER'
export const OPEN_IMAGE_EDITOR = 'OPEN_IMAGE_EDITOR'
/* comment actions */
export const ADD_COMMENT = 'ADD_COMMENT'
export const ADD_COMMENT_LIST = 'ADD_COMMENT_LIST'
@@ -74,13 +67,6 @@ export const LOGOUT = 'LOGOUT'
export const SIGNUP = 'SIGNUP'
export const UPDATE_PASSWORD = 'UPDATE_PASSWORD'
/* file actions */
export const UPLOAD_FILE = 'UPLOAD_FILE'
export const UPLOAD_FILE_ERROR = 'UPLOAD_FILE_ERROR'
export const UPLOAD_FILE_COMPLETE = 'UPLOAD_FILE_COMPLETE'
export const DOWNLOAD_FILE = 'DOWNLOAD_FILE'
/* global actions */
export const PROGRESS_CHANGE = 'PROGRESS_CHANGE'
export const DEFAULT_DATA_DISABLE = 'DEFAULT_DATA_DISABLE'

View File

@@ -1,5 +1,5 @@
export enum AuthorizeActionType
{
export enum AuthorizeActionType {
LOGIN = 'LOGIN',
LOGOUT = 'LOGOUT',
SIGNUP = 'SIGNUP',

View File

@@ -0,0 +1,12 @@
export enum CircleActionType {
ADD_CIRCLE = 'ADD_CIRCLE',
DELETE_CIRCLE = 'DELETE_CIRCLE',
UPDATE_CIRCLE = 'UPDATE_CIRCLE',
ADD_LIST_CIRCLE = 'ADD_LIST_CIRCLE',
CLEAR_ALL_CIRCLES = 'CLEAR_ALL_CIRCLES',
OPEN_CIRCLE_SETTINGS = 'OPEN_CIRCLE_SETTINGS',
CLOSE_CIRCLE_SETTINGS = 'CLOSE_CIRCLE_SETTINGS',
ADD_FOLLOWING_USER = 'ADD_FOLLOWING_USER',
DELETE_FOLLOWING_USER = 'DELETE_FOLLOWING_USER',
}

View File

@@ -0,0 +1,10 @@
export enum CommentActionType {
ADD_COMMENT = 'ADD_COMMENT',
ADD_COMMENT_LIST = 'ADD_COMMENT_LIST',
DELETE_COMMENT = 'DELETE_COMMENT',
CLEAR_ALL_DATA_COMMENT = 'CLEAR_ALL_DATA_COMMENT',
UPDATE_COMMENT = 'UPDATE_COMMENT',
CLOSE_COMMENT_EDITOR = 'CLOSE_COMMENT_EDITOR',
OPEN_COMMENT_EDITOR = 'OPEN_COMMENT_EDITOR',
}

View File

@@ -0,0 +1,19 @@
export enum GlobalActionType {
PROGRESS_CHANGE = 'PROGRESS_CHANGE',
DEFAULT_DATA_DISABLE = 'DEFAULT_DATA_DISABLE',
DEFAULT_DATA_ENABLE = 'DEFAULT_DATA_ENABLE',
LOADING = 'LOADING',
HIDE_MESSAGE_GLOBAL = 'HIDE_MESSAGE_GLOBAL',
SHOW_ERROR_MESSAGE_GLOBAL = 'SHOW_ERROR_MESSAGE_GLOBAL',
SHOW_NORMAL_MESSAGE_GLOBAL = 'SHOW_NORMAL_MESSAGE_GLOBAL',
SHOW_SEND_REQUEST_MESSAGE_GLOBAL = 'SHOW_SEND_REQUEST_MESSAGE_GLOBAL',
SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL = 'SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL',
SET_HEADER_TITLE = 'SET_HEADER_TITLE',
SHOW_TOP_LOADING = 'SHOW_TOP_LOADING',
HIDE_TOP_LOADING = 'HIDE_TOP_LOADING',
TEMP = 'TEMP',
OPEN_POST_WRITE = 'OPEN_POST_WRITE',
CLOSE_POST_WRITE = 'CLOSE_POST_WRITE'
}

View File

@@ -0,0 +1,9 @@
export enum ImageGalleryActionType {
ADD_IMAGE_GALLERY = 'ADD_IMAGE_GALLERY',
ADD_IMAGE_LIST_GALLERY = 'ADD_IMAGES_LIST_GALLERY',
CLEAT_ALL_DATA_IMAGE_GALLERY = 'CLEAT_ALL_DATA_IMAGE_GALLERY',
DELETE_IMAGE = 'DELETE_IMAGE',
SET_IMAGE_URL = 'SET_IMAGE_URL',
SEND_IMAGE_REQUEST = 'SEND_IMAGE_REQUEST'
}

View File

@@ -0,0 +1,9 @@
export enum NotificationActionType {
ADD_NOTIFY = 'ADD_NOTIFY',
ADD_NOTIFY_LIST = 'ADD_NOTIFY_LIST',
DELETE_NOTIFY = 'DELETE_NOTIFY',
SEEN_NOTIFY = 'SEEN_NOTIFY',
CLEAR_ALL_DATA_NOTIFY = 'CLEAR_ALL_DATA_NOTIFY'
}

View File

@@ -1,5 +1,5 @@
export enum PostActionType {
ADD_IMAGE_POST = "ADD_IMAGE_POST",
ADD_VIDEO_POST = "ADD_VIDEO_POST",
ADD_POST = "ADD_POST",

View File

@@ -0,0 +1,11 @@
export enum UserActionType {
ADD_USERS = 'ADD_USERS',
ADD_USER_INFO = 'ADD_USER_INFO',
UPDATE_USER_INFO = 'UPDATE_USER_INFO',
USER_INFO = 'USER_INFO',
CLEAR_ALL_DATA_USER = 'CLEAR_ALL_DATA_USER',
OPEN_EDIT_PROFILE = 'OPEN_EDIT_PROFILE',
CLOSE_EDIT_PROFILE = 'CLOSE_EDIT_PROFILE',
ADD_PEOPLE_INFO = 'ADD_PEOPLE_INFO'
}

View File

@@ -0,0 +1,7 @@
export enum VoteActionType {
ADD_VOTE = 'ADD_VOTE',
DELETE_VOTE = 'DELETE_VOTE',
ADD_VOTE_LIST = 'ADD_VOTE_LIST',
CLEAR_ALL_DATA_VOTE = 'CLEAR_ALL_DATA_VOTE'
}

View File

@@ -0,0 +1,48 @@
import { BaseDomain } from "domain/common";
import { User } from "domain/users";
export class Circle extends BaseDomain {
/**
* Circle identifier
*
* @type {string}
* @memberof User
*/
public id?: string | null;
/**
* Circle creation date time
*
* @type {Date}
* @memberof Circle
*/
public creationDate?: number;
/**
* Circle owner identifier
*
* @type {string}
* @memberof Circle
*/
public ownerId?: string | null;
/**
* Circle name
*
* @type {string}
* @memberof User
*/
public name: string;
/**
* The users in a circle
*
* @type {string}
* @memberof User
*/
public users: {[userId:string]: User};
}

View File

@@ -0,0 +1,7 @@
import {Circle} from './circle';
import {UserFollower} from './userFollower';
export {
Circle,
UserFollower
}

View File

@@ -0,0 +1,40 @@
import { BaseDomain } from "domain/common";
export class UserFollower extends BaseDomain {
/**
* Circle creation date time
*
* @type {Date}
* @memberof Circle
*/
public creationDate?: number;
/**
* User full name
*
* @type {string}
* @memberof UserFollower
*/
public fullName: string;
/**
* Avatar URL address
*
* @type {string}
* @memberof UserFollower
*/
public avatar: string;
/**
* If following user approved {true} or not {false}
*
* @type {Boolean}
* @memberof UserFollower
*/
public approved: Boolean;
}

View File

@@ -0,0 +1,61 @@
import { BaseDomain } from "domain/common";
export class Comment extends BaseDomain {
/**
* Post identifier that comment belong to
*
* @type {string}
* @memberof Comment
*/
public postId: string;
/**
* Comment text
*
* @type {string}
* @memberof Comment
*/
public text: string;
/**
* Comment score
*
* @type {number}
* @memberof Comment
*/
public score: number;
/**
* Comment creation date
*
* @type {number}
* @memberof Comment
*/
public creationDate:number;
/**
* Comment owner full name
*
* @type {string}
* @memberof Comment
*/
public userDisplayName: string;
/**
* Comment owner avater address
*
* @type {string}
* @memberof Comment
*/
public userAvatar: string;
/**
* Comment owner identifier
*
* @type {string}
* @memberof Comment
*/
public userId: string;
}

View File

@@ -0,0 +1,5 @@
import {Comment} from './comment';
export {
Comment
}

View File

@@ -0,0 +1,69 @@
import { BaseDomain } from "domain/common";
export class Image extends BaseDomain {
/**
* Image identifier
*
* @type {string}
* @memberof Image
*/
public id?: string | null;
/**
* Image creation date
*
* @type {number}
* @memberof Image
*/
public creationDate: number;
/**
* Image delete date
*
* @type {string}
* @memberof Image
*/
public deleteDate: string;
/**
* Image URL address
*
* @type {string}
* @memberof Image
*/
public URL: string;
/**
* Image folder name with image name {folderName/imageName}
*
* @type {string}
* @memberof Image
*/
public fullPath: string;
/**
* Image owner identifier
*
* @type {string}
* @memberof Image
*/
public ownerUserId: string;
/**
* Last edit date
*
* @type {number}
* @memberof Image
*/
public lastEditDate: number;
/**
* If the image was deleted {true} or not {false}
*
* @type {Boolean}
* @memberof Image
*/
public deleted: Boolean;
}

View File

@@ -0,0 +1,5 @@
import { Image } from "./image";
export {
Image
}

View File

@@ -0,0 +1,5 @@
import {Notification} from './notification';
export {
Notification
}

View File

@@ -0,0 +1,45 @@
import { BaseDomain } from "domain/common";
export class Notification extends BaseDomain {
/**
* Description of notification
*
* @type {string}
* @memberof Notification
*/
public description: string;
/**
* The URL which notification refer to
*
* @type {string}
* @memberof Notification
*/
public url: string;
/**
* The identifier of the user who makes the notification
*
* @type {string}
* @memberof Notification
*/
public notifierUserId: string;
/**
* The identifier of the user who receive the notification
*
* @type {string}
* @memberof Notification
*/
public notifyRecieverUserId: string;
/**
* If the notification is seen {true} or not {false}
*
* @type {Boolean}
* @memberof Notification
*/
public isSeen: Boolean;
}

View File

@@ -0,0 +1,5 @@
import {Post} from './post';
export {
Post
}

158
app/domain/posts/post.ts Normal file
View File

@@ -0,0 +1,158 @@
import { BaseDomain } from "domain/common";
export class Post extends BaseDomain {
/**
* Post identifier
*
* @type {string}
* @memberof Post
*/
public id?: string | null;
/**
* The identifier of post type
*
* @type {number}
* @memberof Post
*/
public postTypeId: number;
/**
* The post creation date
*
* @type {number}
* @memberof Post
*/
public creationDate:number;
/**
* The post delete date
*
* @type {number}
* @memberof Post
*/
public deleteDate: number;
/**
* The score of post
*
* @type {number}
* @memberof Post
*/
public score: number;
/**
* Post view count
*
* @type {number}
* @memberof Post
*/
public viewCount: number;
/**
* The text of post
*
* @type {string}
* @memberof Post
*/
public body: string;
/**
* The identifier of post owner
*
* @type {string}
* @memberof Post
*/
public ownerUserId: string;
/**
* Full name of post owner
*
* @type {string}
* @memberof Post
*/
public ownerDisplayName: string;
/**
* Avatar address of post owner
*
* @type {string}
* @memberof Post
*/
public ownerAvatar: string;
/**
* Last post edit date
*
* @type {number}
* @memberof Post
*/
public lastEditDate: number;
/**
* Post tags
*
* @type {string[]}
* @memberof Post
*/
public tags: string[];
/**
* Numeber of comment on the post
*
* @type {number}
* @memberof Post
*/
public commentCounter: number;
/**
* The address of image on the post
*
* @type {string}
* @memberof Post
*/
public image: string;
/**
* Post image full path
*
* @type {string}
* @memberof Post
*/
public imageFullPath: string;
/**
* The adress of video on the post
*
* @type {string}
* @memberof Post
*/
public video: string;
/**
* If writing comment is disabled {true} or not {false}
*
* @type {Boolean}
* @memberof Post
*/
public disableComments: Boolean;
/**
* If sharing post is disabled {true} or not {false}
*
* @type {Boolean}
* @memberof Post
*/
public disableSharing: Boolean;
/**
* If the post is deleted {true} or not false
*
* @type {Boolean}
* @memberof Post
*/
public deleted: Boolean;
}

View File

@@ -1,5 +1,7 @@
import User from './user';
import {User} from './user';
import {Profile} from './profile';
export {
User
User,
Profile
}

View File

@@ -0,0 +1,45 @@
import { BaseDomain } from "domain/common";
export class Profile extends BaseDomain {
/**
* User avatar address
*
* @type {string}
* @memberof Profile
*/
public avatar: string;
/**
* User email
*
* @type {string}
* @memberof Profile
*/
public email: string;
/**
* User full name
*
* @type {string}
* @memberof Profile
*/
public fullName: string;
/**
* The banner address of user profile
*
* @type {string}
* @memberof Profile
*/
public banner: string;
/**
* User tag line
*
* @type {string}
* @memberof Profile
*/
public tagLine: string;
}

View File

@@ -1,13 +1,30 @@
import { BaseDomain } from "domain/common";
class User extends BaseDomain {
export class User extends BaseDomain {
/**
* Full name of user
*
* @type {string}
* @memberof User
*/
public fullName: string;
/**
* User avatar address
*
* @type {string}
* @memberof User
*/
public avatar: string;
/**
* Email of the user
*
* @type {string}
* @memberof User
*/
public email: string;
public email?: string | null;
/**
* Password of the user
@@ -15,7 +32,7 @@ class User extends BaseDomain {
* @type {string}
* @memberof User
*/
public password: string;
public password?: string | null;
/**
* User identifier
@@ -23,8 +40,14 @@ class User extends BaseDomain {
* @type {string}
* @memberof User
*/
public userId: string;
public userId?: string | null;
}
export default User;
/**
* User creation date
*
* @type {number}
* @memberof User
*/
public creationDate: number;
}

View File

@@ -0,0 +1,5 @@
import {Vote} from './vote';
export {
Vote
}

53
app/domain/votes/vote.ts Normal file
View File

@@ -0,0 +1,53 @@
import { BaseDomain } from "domain/common";
export class Vote extends BaseDomain {
/**
* Vote identifier
*
* @type {string}
* @memberof Vote
*/
public id?: string | null;
/**
* Post identifire which vote on
*
* @type {string}
* @memberof Vote
*/
public postId: string;
/**
* Vote date
*
* @type {number}
* @memberof Vote
*/
public creationDate: number;
/**
* Voter full name
*
* @type {string}
* @memberof Vote
*/
public userDisplayName: string;
/**
* Avatar of voter
*
* @type {string}
* @memberof Vote
*/
public userAvatar: string;
/**
* Voter identifier
*
* @type {string}
* @memberof Vote
*/
public userId: string;
}

View File

@@ -0,0 +1,27 @@
// - Import react components
import { firebaseRef, firebaseAuth } from 'app/firebase/';
import { SocialError } from "domain/common";
import { ICircleService } from 'services/circles';
import { Circle, UserFollower } from 'domain/circles';
import { User } from 'domain/users';
/**
* Firbase circle service
*
* @export
* @class CircleService
* @implements {ICircleService}
*/
export class CircleService implements ICircleService {
addCircle: (userId: string, circle: Circle) => Promise<string>;
addFollowingUser: (userId: string, circleId: string, userCircle: User, userFollower: UserFollower, userFollowingId: string) => Promise<void>;
deleteFollowingUser: (userId: string, circleId: string, userFollowingId: string) => Promise<void>;
updateCircle: (userId: string, circle: Circle, circleId: string) => Promise<void>;
deleteCircle: (circleId: string, userId: string) => Promise<void>;
getCircles: () => Promise<{ [circleId: string]: Circle; }>;
getCirclesByUserId: (userId: string) => Promise<{ [circleId: string]: Circle; }>;
}

View File

@@ -0,0 +1,5 @@
import { AuthorizeService } from "./CircleService";
export {
AuthorizeService
}

View File

@@ -0,0 +1,17 @@
// - Import react components
import { firebaseRef, firebaseAuth } from 'app/firebase/';
import { SocialError } from "domain/common";
import { ICommentService } from 'services/comments';
/**
* Firbase comment service
*
* @export
* @class CommentService
* @implements {ICommentService}
*/
export class CommentService implements ICommentService {
}

View File

@@ -0,0 +1,5 @@
import { CommentService } from "./CommentService";
export {
CommentService
}

View File

@@ -0,0 +1,17 @@
// - Import react components
import { firebaseRef, firebaseAuth } from 'app/firebase/';
import { SocialError } from "domain/common";
import { ICommonService } from 'services/common';
/**
* Firbase common service
*
* @export
* @class CommonService
* @implements {ICommonService}
*/
export class CommonService implements ICommonService {
}

View File

@@ -0,0 +1,5 @@
import { CommonService } from "./CommonService";
export {
CommonService
}

View File

@@ -0,0 +1,17 @@
// - Import react components
import { firebaseRef, firebaseAuth } from 'app/firebase/';
import { SocialError } from "domain/common";
import { IImageGalleryService } from 'services/imageGallery';
/**
* Firbase image gallery service
*
* @export
* @class ImageGalleryService
* @implements {IImageGalleryService}
*/
export class ImageGalleryService implements IImageGalleryService {
}

View File

@@ -0,0 +1,5 @@
import { ImageGalleryService } from "./ImageGalleryService";
export {
ImageGalleryService
}

View File

@@ -0,0 +1,5 @@
import { NotificationService } from "./NotificationService";
export {
NotificationService
}

View File

@@ -0,0 +1,17 @@
// - Import react components
import { firebaseRef, firebaseAuth } from 'app/firebase/';
import { SocialError } from "domain/common";
import { INotificationService } from 'services/notifications';
/**
* Firbase notification service
*
* @export
* @class NotificationService
* @implements {INotificationService}
*/
export class NotificationService implements INotificationService {
}

View File

@@ -0,0 +1,17 @@
// - Import react components
import { firebaseRef, firebaseAuth } from 'app/firebase/';
import { SocialError } from "domain/common";
import { IPostService } from 'services/posts';
/**
* Firbase post service
*
* @export
* @class PostService
* @implements {IPostService}
*/
export class PostService implements IPostService {
}

View File

@@ -0,0 +1,5 @@
import { PostService } from "./PostService";
export {
PostService
}

View File

@@ -0,0 +1,17 @@
// - Import react components
import { firebaseRef, firebaseAuth } from 'app/firebase/';
import { SocialError } from "domain/common";
import { IUserService } from 'services/users';
/**
* Firbase user service
*
* @export
* @class UserService
* @implements {IUserService}
*/
export class UserService implements IUserService {
}

View File

@@ -0,0 +1,5 @@
import { UserService } from "./UserService";
export {
UserService
}

View File

@@ -0,0 +1,17 @@
// - Import react components
import { firebaseRef, firebaseAuth } from 'app/firebase/';
import { SocialError } from "domain/common";
import { IVoteService } from 'services/votes';
/**
* Firbase vote service
*
* @export
* @class VoteService
* @implements {IVoteService}
*/
export class VoteService implements IVoteService {
}

View File

@@ -0,0 +1,5 @@
import { VoteService } from "./VoteService";
export {
VoteService
}

View File

@@ -0,0 +1,40 @@
/**
* Post state
*
* @export
* @class AuthorizeState
*/
export class AuthorizeState {
/**
* Authorized user identifier
*
* @type {number}
* @memberof AuthorizeState
*/
uid: number = 0;
/**
* If user is authed {true} or not {false}
*
* @type {Boolean}
* @memberof AuthorizeState
*/
authed: Boolean = false;
/**
* If user password is updated {true} or not {false}
*
* @type {Boolean}
* @memberof AuthorizeState
*/
updatePassword: Boolean = false;
/**
* If the user is guest {true} or not {false}
*
* @type {Boolean}
* @memberof AuthorizeState
*/
guest: Boolean = false;
}

View File

@@ -0,0 +1,15 @@
// - Import action types
import {AuthorizeActionType} from 'constants/authorizeActionType'
/**
* Authorize action interface
*
* @export
* @interface IAuthorizeAction
*/
export interface IAuthorizeAction {
payload: any;
type: AuthorizeActionType;
}

View File

@@ -0,0 +1,50 @@
// - Import react components
import {Reducer, Action} from "redux";
// - Import action types
import {AuthorizeActionType} from 'constants/authorizeActionType'
import { IAuthorizeAction } from "./IAuthorizeAction";
import { AuthorizeState } from "./AuthorizeState";
/**
* Authorize reducer
* @param {object} state
* @param {object} action
*/
export var authorizeReducer = (state : AuthorizeState = new AuthorizeState(), action: IAuthorizeAction) =>{
const { payload } = action;
switch (action.type) {
case AuthorizeActionType.LOGIN:
return{
...state,
uid: payload.uid,
authed: true,
guest:false
}
case AuthorizeActionType.LOGOUT:
return{
...state,
uid: 0,
authed: false,
guest:true
}
case AuthorizeActionType.SIGNUP:
return{
...state,
uid: payload.userId
}
case AuthorizeActionType.UPDATE_PASSWORD:
return{
...state,
updatePassword: payload.updatePassword
}
default:
return state
}
}

View File

@@ -0,0 +1,3 @@
import { authorizeReducer } from "./authorizeReducer";
export {authorizeReducer};

View File

@@ -1,96 +0,0 @@
// - Import react components
import {Reducer, Action} from "redux";
// - Import action types
import {AuthorizeActionType} from 'constants/authorizeActionType'
/**
* Default state
*/
var defaultState = {
uid: 0,
authed: false,
updatePassword: false,
guest:false
}
/**
* Default post state interface
*
* @export
* @interface IAuthorizeState
*/
export interface IAuthorizeState {
uid: number,
authed: Boolean,
updatePassword: Boolean,
guest:Boolean
}
/**
* Default authorize action interface
*
* @export
* @interface IAuthorizeAction
*/
export interface IAuthorizeAction {
payload: any,
type: AuthorizeActionType
}
/**
* Default authorize reducer state
*
* @export
* @class DefaultAuthorizeState
* @implements {IAuthorizeState}
*/
export class DefaultAuthorizeState implements IAuthorizeState{
uid: number = 0;
authed: Boolean = false;
updatePassword: Boolean = false;
guest: Boolean = false;
}
/**
* Authorize reducer
* @param {object} state
* @param {object} action
*/
export var authorizeReducer = (state : IAuthorizeState = new DefaultAuthorizeState(), action: IAuthorizeAction) =>{
const { payload } = action;
switch (action.type) {
case AuthorizeActionType.LOGIN:
return{
...state,
uid: payload.uid,
authed: true,
guest:false
}
case AuthorizeActionType.LOGOUT:
return{
...state,
uid: 0,
authed: false,
guest:true
}
case AuthorizeActionType.SIGNUP:
return{
...state,
uid: payload.userId
}
case AuthorizeActionType.UPDATE_PASSWORD:
return{
...state,
updatePassword: payload.updatePassword
}
default:
return state
}
}

View File

@@ -0,0 +1,26 @@
import { Circle } from "domain/circles";
/**
* Circle state
*
* @export
* @class CircleState
*/
export class CircleState {
/**
* The list of Circles belong to users
*
* @type {({[userId: string]: {[circleId: string]: Circle}} | null)}
* @memberof CircleState
*/
userCircles: {[userId: string]: {[circleId: string]: Circle}} = {};
/**
* If user circles are loaded {true} or not {false}
*
* @type {Boolean}
* @memberof CircleState
*/
loaded: Boolean = false;
}

View File

@@ -0,0 +1,14 @@
import {CircleActionType} from 'constants/circleActionType'
/**
* Circle action interface
*
* @export
* @interface ICircleAction
*/
export interface ICircleAction {
payload: any,
type: CircleActionType
}

View File

@@ -1,66 +1,62 @@
// - Import react components
var uuid = require('uuid');
import moment from 'moment'
import _ from 'lodash'
// - Import domain
import { User } from "domain/users";
import { Circle } from "domain/circles";
// - Import action types
import * as types from 'actionTypes'
import {CircleActionType} from 'constants/circleActionType'
/* ---------------- */
import { CircleState } from "./CircleState";
import { ICircleAction } from "./ICircleAction";
/**
* Default State
*/
var defaultState = {
userCircles: {},
loaded: false
}
/**
* Circle reducer
* @param {object} state
* @param {object} action
* @param state
* @param action
*/
export var circleReducer = (state = defaultState, action) => {
export var circleReducer = (state: CircleState = new CircleState(), action: ICircleAction) => {
const { payload } = action
switch (action.type) {
case types.CLEAR_ALL_CIRCLES:
return defaultState
case CircleActionType.CLEAR_ALL_CIRCLES:
return new CircleState();
case types.ADD_CIRCLE:
case CircleActionType.ADD_CIRCLE:
return {
...state,
userCircles: {
...state.userCircles,
[payload.uid]: {
...state.userCircles[payload.uid],
[payload.circle.ownerId]: {
...state.userCircles![payload.circle.ownerId],
[payload.circle.id]: { ...payload.circle }
}
}
}
case types.UPDATE_CIRCLE:
case CircleActionType.UPDATE_CIRCLE:
return {
...state,
userCircles: {
...state.userCircles,
[payload.uid]: {
...state.userCircles[payload.uid],
...state.userCircles![payload.uid],
[payload.circle.id]: {
...state.userCircles[payload.uid][payload.circle.id],
...state.userCircles![payload.uid][payload.circle.id],
...payload.circle,
openCircleSettings:false }
}
}
}
case types.DELETE_CIRCLE:
case CircleActionType.DELETE_CIRCLE:
let filteredCircles = {}
Object.keys(state.userCircles[payload.uid]).map((key) => {
Object.keys(state.userCircles![payload.uid]).map((key) => {
if (key !== payload.id) {
return _.merge(filteredCircles, { [key]: { ...state.userCircles[payload.uid][key] } })
return _.merge(filteredCircles, { [key]: { ...state.userCircles![payload.uid][key] } })
}
})
return {
@@ -72,13 +68,13 @@ export var circleReducer = (state = defaultState, action) => {
}
}
}
case types.ADD_LIST_CIRCLE:
case CircleActionType.ADD_LIST_CIRCLE:
return {
...state,
userCircles: {
...state.userCircles,
[payload.uid]: {
...state.userCircles[payload.uid],
...state.userCircles![payload.uid],
...payload.circles
}
},
@@ -86,17 +82,17 @@ export var circleReducer = (state = defaultState, action) => {
}
case types.ADD_FOLLOWING_USER:
case CircleActionType.ADD_FOLLOWING_USER:
return {
...state,
userCircles: {
...state.userCircles,
[payload.uid]: {
...state.userCircles[payload.uid],
...state.userCircles![payload.uid],
[payload.cid]: {
...state.userCircles[payload.uid][payload.cid],
...state.userCircles![payload.uid][payload.cid],
users:{
...state.userCircles[payload.uid][payload.cid].users,
...state.userCircles![payload.uid][payload.cid].users,
[payload.followingId]: {
...payload.userCircle
}
@@ -106,11 +102,11 @@ export var circleReducer = (state = defaultState, action) => {
}
}
case types.DELETE_FOLLOWING_USER:
case CircleActionType.DELETE_FOLLOWING_USER:
let filteredUserCircle = {}
Object.keys(state.userCircles[payload.uid][payload.cid].users).map((key) => {
Object.keys(state.userCircles![payload.uid][payload.cid].users).map((key) => {
if (key !== payload.followingId) {
return _.merge(filteredUserCircle, { [key]: { ...state.userCircles[payload.uid][payload.cid].users[key] } })
return _.merge(filteredUserCircle, { [key]: { ...state.userCircles![payload.uid][payload.cid].users[key] } })
}
})
return {
@@ -118,9 +114,9 @@ export var circleReducer = (state = defaultState, action) => {
userCircles: {
...state.userCircles,
[payload.uid]: {
...state.userCircles[payload.uid],
...state.userCircles![payload.uid],
[payload.cid]: {
...state.userCircles[payload.uid][payload.cid],
...state.userCircles![payload.uid][payload.cid],
users:{
...filteredUserCircle
}
@@ -129,30 +125,30 @@ export var circleReducer = (state = defaultState, action) => {
}
}
case types.CLOSE_CIRCLE_SETTINGS:
case CircleActionType.CLOSE_CIRCLE_SETTINGS:
return {
...state,
userCircles: {
...state.userCircles,
[payload.uid]: {
...state.userCircles[payload.uid],
...state.userCircles![payload.uid],
[payload.id]: {
...state.userCircles[payload.uid][payload.id],
...state.userCircles![payload.uid][payload.id],
openCircleSettings: false
}
}
}
}
case types.OPEN_CIRCLE_SETTINGS:
case CircleActionType.OPEN_CIRCLE_SETTINGS:
return {
...state,
userCircles: {
...state.userCircles,
[payload.uid]: {
...state.userCircles[payload.uid],
...state.userCircles![payload.uid],
[payload.id]: {
...state.userCircles[payload.uid][payload.id],
...state.userCircles![payload.uid][payload.id],
openCircleSettings: true
}
}

View File

@@ -0,0 +1,3 @@
import { circleReducer } from "./circleReducer";
export {circleReducer};

View File

@@ -0,0 +1,27 @@
import { Comment } from "domain/comments";
/**
* Comment state
*
* @export
* @class CommentState
*/
export class CommentState {
/**
* The list of comments on the posts
*
* @type {({[postId: string]: {[commentId: string]: Comment}} | null)}
* @memberof CommentState
*/
postComments: {[postId: string]: {[commentId: string]: Comment}} = {};
/**
* If the comments are loaded {true} or not {false}
*
* @type {Boolean}
* @memberof CommentState
*/
loaded: Boolean = false;
}

View File

@@ -0,0 +1,14 @@
import {CommentActionType} from 'constants/commentActionType'
/**
* Comment action interface
*
* @export
* @interface ICommentAction
*/
export interface ICommentAction {
payload: any;
type: CommentActionType;
}

View File

@@ -2,38 +2,34 @@
import moment from 'moment'
import _ from 'lodash'
// - Import domain
import { User } from "domain/users";
import { Comment } from "domain/comments";
// - Import action types
import * as types from 'actionTypes'
import {CommentActionType} from 'constants/commentActionType'
import { CommentState } from "./CommentState";
import { ICommentAction } from "./ICommentAction";
/**
* Default state
* Comment reducer
* @param state
* @param action
*/
var defaultState = {
postComments: {},
loaded:false
}
/**
* Comment actions
* @param {object} state
* @param {object} action
*/
export var commentReducer = (state = defaultState, action) => {
export var commentReducer = (state: CommentState = new CommentState(), action: ICommentAction) => {
var { payload } = action
switch (action.type) {
/* _____________ CRUD _____________ */
case types.ADD_COMMENT:
case CommentActionType.ADD_COMMENT:
return {
...state,
postComments: {
...state.postComments,
[payload.postId]: {
...state.postComments[payload.postId],
...state.postComments![payload.postId],
[payload.id]: {
...payload.comment,
editorStatus: false
@@ -42,7 +38,7 @@ export var commentReducer = (state = defaultState, action) => {
}
}
case types.ADD_COMMENT_LIST:
case CommentActionType.ADD_COMMENT_LIST:
return {
...state,
postComments: {
@@ -50,29 +46,29 @@ export var commentReducer = (state = defaultState, action) => {
},
loaded:true
}
case types.UPDATE_COMMENT:
case CommentActionType.UPDATE_COMMENT:
return {
...state,
postComments: {
...state.postComments,
[payload.postId]: {
...state.postComments[payload.postId],
...state.postComments![payload.postId],
[payload.id]: {
...state.postComments[payload.postId][payload.id],
...state.postComments![payload.postId][payload.id],
text: payload.text,
editorStatus: payload.editorStatus
editorStatus: false
}
}
}
}
case types.DELETE_COMMENT:
case CommentActionType.DELETE_COMMENT:
var parsedComments = {}
if (!state.postComments[payload.postId]) {
if (!state.postComments![payload.postId]) {
return state
}
Object.keys(state.postComments[payload.postId]).map((id) => {
Object.keys(state.postComments![payload.postId]).map((id) => {
if (id !== payload.id) {
_.merge(parsedComments, { [id]: { ...state.postComments[payload.postId][id] } })
_.merge(parsedComments, { [id]: { ...state.postComments![payload.postId][id] } })
}
})
@@ -85,37 +81,37 @@ export var commentReducer = (state = defaultState, action) => {
}
}
}
case types.CLOSE_COMMENT_EDITOR:
case CommentActionType.CLOSE_COMMENT_EDITOR:
return {
...state,
postComments: {
...state.postComments,
[payload.postId]: {
...state.postComments[payload.postId],
...state.postComments![payload.postId],
[payload.id]: {
...state.postComments[payload.postId][payload.id],
...state.postComments![payload.postId][payload.id],
editorStatus: false
}
}
}
}
case types.OPEN_COMMENT_EDITOR:
case CommentActionType.OPEN_COMMENT_EDITOR:
return {
...state,
postComments: {
...state.postComments,
[payload.postId]: {
...state.postComments[payload.postId],
...state.postComments![payload.postId],
[payload.id]: {
...state.postComments[payload.postId][payload.id],
...state.postComments![payload.postId][payload.id],
editorStatus: true
}
}
}
}
case types.CLEAR_ALL_DATA_COMMENT:
return defaultState
case CommentActionType.CLEAR_ALL_DATA_COMMENT:
return new CommentState();
default:

View File

@@ -0,0 +1,3 @@
import { commentReducer } from "./commentReducer";
export {commentReducer};

View File

@@ -0,0 +1,107 @@
/**
* Global state
*
* @export
* @class GlobalState
*/
export class GlobalState {
/**
* Set percent of loading progress and visibility for Master component
*
* @type {{
* percent: number,
* visible: Boolean
* }}
* @memberof IGlobalState
*/
progress: {
percent: number;
visible: Boolean;
} = {
percent : 0,
visible : false
}
/**
* If loading is enabled {true} or not false
*
* @type {Boolean}
* @memberof IGlobalState
*/
loadingStatus: Boolean = true;
/**
* If user date is loaded {true} or not {false}
*
* @type {Boolean}
* @memberof IGlobalState
*/
defaultLoadDataStatus: Boolean = false;
/**
* If message popup is open {true} or not {false}
*
* @type {Boolean}
* @memberof IGlobalState
*/
messageOpen: Boolean = false;
/**
* The text of popup global message
*
* @type {string}
* @memberof IGlobalState
*/
message: string = '';
/**
* Window size
*
* @type {number}
* @memberof IGlobalState
*/
windowWidth: number = 0;
/**
* Window height
*
* @type {number}
* @memberof IGlobalState
*/
windowHeight: number = 0;
/**
* The text of website header
*
* @type {string}
* @memberof IGlobalState
*/
headerTitle: string = '';
/**
* Top loading is visible {true} or not {false}
*
* @type {Boolean}
* @memberof IGlobalState
*/
showTopLoading: Boolean = false;
/**
* Top loading message queue
*
* @type {number}
* @memberof IGlobalState
*/
topLoadingQueue: number = 0;
/**
* Temp date storage
*
* @type {*}
* @memberof IGlobalState
*/
temp: any = {};
}

View File

@@ -0,0 +1,13 @@
import { GlobalActionType } from 'constants/globalActionType';
/**
* Global action interface
*
* @export
* @interface IGlobalAction
*/
export interface IGlobalAction {
payload: any,
type: GlobalActionType
}

View File

@@ -1,35 +1,9 @@
// - Import action types
import * as types from 'actionTypes'
import { GlobalActionType } from 'constants/globalActionType';
/**
* Default state
*/
var defaultState = {
progress: {
percent: 0,
visible: false
},
loadingStatus: true,
defaultLoadDataStatus: false,
messageOpen: false,
message: '',
sidebarMainStyle: {},
sidebarStyle: { width: "210px" },
sidebarClass: "",
sidebarOpen: (window.innerWidth > 750) ? true : false,
windowWidth: 0,
windowHeight: 0,
overSidebarStatus: false,
onResizeOpenSidebar: false,
sidebarAuto: false,
headerTitle: '',
editProfileOpen: false,
showTopLoading: false,
topLoadingQueue: 0,
temp: {}
}
import { GlobalState } from "./GlobalState";
import { IGlobalAction } from "./IGlobalAction";
/**
@@ -37,10 +11,10 @@ var defaultState = {
* @param {object} state
* @param {object} action
*/
export const globalReducer = (state = defaultState, action) => {
export const globalReducer = (state: GlobalState = new GlobalState(), action: IGlobalAction) => {
const { payload } = action
switch (action.type) {
case types.PROGRESS_CHANGE:
case GlobalActionType.PROGRESS_CHANGE:
return {
...state,
progress: {
@@ -49,53 +23,53 @@ export const globalReducer = (state = defaultState, action) => {
visible: payload.visible
}
}
case types.DEFAULT_DATA_DISABLE:
case GlobalActionType.DEFAULT_DATA_DISABLE:
return {
...state,
defaultLoadDataStatus: false
}
case types.DEFAULT_DATA_ENABLE:
case GlobalActionType.DEFAULT_DATA_ENABLE:
return {
...state,
defaultLoadDataStatus: true
}
case types.SHOW_ERROR_MESSAGE_GLOBAL:
case GlobalActionType.SHOW_ERROR_MESSAGE_GLOBAL:
return {
...state,
message: action.payload,
messageOpen: true
}
case types.SHOW_NORMAL_MESSAGE_GLOBAL:
case GlobalActionType.SHOW_NORMAL_MESSAGE_GLOBAL:
return {
...state,
message: action.payload,
messageOpen: true
}
case types.SHOW_SEND_REQUEST_MESSAGE_GLOBAL:
case GlobalActionType.SHOW_SEND_REQUEST_MESSAGE_GLOBAL:
return {
...state,
message: "Request has been sent",
messageOpen: true
}
case types.SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL:
case GlobalActionType.SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL:
return {
...state,
message: "Your request has processed successfuly",
messageOpen: true
}
case types.HIDE_MESSAGE_GLOBAL:
case GlobalActionType.HIDE_MESSAGE_GLOBAL:
return {
...state,
message: '',
messageOpen: false,
messageColor: ''
}
case types.SET_HEADER_TITLE:
case GlobalActionType.SET_HEADER_TITLE:
return {
...state,
headerTitle: action.payload
}
case types.HIDE_TOP_LOADING:
case GlobalActionType.HIDE_TOP_LOADING:
const queue = state.topLoadingQueue > 0 ? (state.topLoadingQueue - 1) : 0
return {
...state,
@@ -103,13 +77,13 @@ export const globalReducer = (state = defaultState, action) => {
showTopLoading: (queue > 0 ? true : false)
}
case types.SHOW_TOP_LOADING:
case GlobalActionType.SHOW_TOP_LOADING:
return {
...state,
topLoadingQueue: (state.topLoadingQueue + 1),
showTopLoading: true
}
case types.TEMP:
case GlobalActionType.TEMP:
return {
...state,
temp: {

View File

@@ -0,0 +1,3 @@
import { globalReducer } from "./globalReducer";
export {globalReducer};

View File

@@ -0,0 +1,13 @@
import {ImageGalleryActionType} from 'constants/imageGalleryActionType'
/**
* ImageGallery action interface
*
* @export
* @interface IImageGalleryAction
*/
export interface IImageGalleryAction {
payload: any,
type: ImageGalleryActionType
}

View File

@@ -0,0 +1,67 @@
import { Image } from "domain/imageGallery";
/**
* ImageGallery state
*
* @export
* @class ImageGalleryState
*/
export class ImageGalleryState {
/**
* Image gallery is open {true} or not {false}
*
* @type {Boolean}
* @memberof ImageGalleryState
*/
status: Boolean = false;
/**
* The list of image
*
* @type {(Image[] | null)}
* @memberof ImageGalleryState
*/
images: Image[] = [];
/**
* Selected image name
*
* @type {string}
* @memberof ImageGalleryState
*/
selectImage: string = '';
/**
* Selected image address
*
* @type {string}
* @memberof ImageGalleryState
*/
selectURL: string = '';
/**
* If image gallery is loaded {true} or not false
*
* @type {Boolean}
* @memberof ImageGalleryState
*/
loaded: Boolean = false;
/**
* Images address list
*
* @type {*}
* @memberof ImageGalleryState
*/
imageURLList: any = {};
/**
* Store image requested
*
* @type {*}
* @memberof ImageGalleryState
*/
imageRequests: any = {};
}

View File

@@ -0,0 +1,71 @@
// - Import react components
import _ from 'lodash'
// - Import domain
import { User } from "domain/users";
import { Image } from "domain/imageGallery";
// - Import image gallery action types
import {ImageGalleryActionType} from 'constants/imageGalleryActionType'
import { IImageGalleryAction } from "./IImageGalleryAction";
import { ImageGalleryState } from "./ImageGalleryState";
/**
* Image gallery reducer
*/
export var imageGalleryReducer = (state: ImageGalleryState = new ImageGalleryState(), action: IImageGalleryAction) => {
const { payload } = action
switch (action.type) {
/* ----------------- CRUD ----------------- */
case ImageGalleryActionType.ADD_IMAGE_GALLERY:
return {
...state,
images: [...state.images!, payload.image]
}
case ImageGalleryActionType.ADD_IMAGE_LIST_GALLERY:
return {
...state,
images: [...payload],
loaded: true
}
case ImageGalleryActionType.DELETE_IMAGE:
return {
...state,
images: [
...state.images!.filter((item: Image) => {
return item.id !== payload.id
})
]
}
case ImageGalleryActionType.SET_IMAGE_URL:
return {
...state,
imageURLList: {
...state.imageURLList,
[payload.name]: payload.url
}
}
case ImageGalleryActionType.SEND_IMAGE_REQUEST:
return {
...state,
imageRequests: [
...state.imageRequests,
payload
]
}
case ImageGalleryActionType.CLEAT_ALL_DATA_IMAGE_GALLERY:
return new ImageGalleryState()
default:
return state;
}
}

View File

@@ -0,0 +1,3 @@
import { imageGalleryReducer } from "./imageGalleryReducer";
export {imageGalleryReducer};

View File

@@ -1,95 +0,0 @@
// - Import react components
import _ from 'lodash'
// - Import image gallery action types
import * as types from 'actionTypes'
/**
* Default state for reducer
*/
var defaultState = {
status: false,
images: [],
selectImage: '',
selectURL: '',
loaded: false,
imageURLList: {},
imageRequests: []
}
/**
* Image gallery reducer
*/
export var imageGalleryReducer = (state = defaultState, action) => {
const { payload } = action
switch (action.type) {
case types.OPEN_IMAGE_GALLERY:
return {
...state,
status: action.status
}
/* ----------------- CRUD ----------------- */
case types.ADD_IMAGE_GALLERY:
return {
...state,
images: [...state.images, action.image]
}
case types.ADD_IMAGE_LIST_GALLERY:
{
return {
...state,
images: [...action.images],
loaded: true
}
}
case types.DELETE_IMAGE:
return {
...state,
images: [
...state.images.filter((item) => {
return item.id !== action.id
})
]
}
case types.IMAGE_SELECT_GALLERY:
return {
...state,
selectImage: action.image,
selectURL: action.URL
}
case types.CLEARS_SELECT_IMAGE_GALLERY:
return {
...state,
selectImage: '',
selectURL: ''
}
case types.SET_IMAGE_URL:
return {
...state,
imageURLList: {
...state.imageURLList,
[payload.name]: payload.url
}
}
case types.SEND_IMAGE_REQUEST:
return {
...state,
imageRequests: [
...state.imageRequests,
payload
]
}
case types.CLEAT_ALL_DATA_IMAGE_GALLERY:
return defaultState
default:
return state;
}
}

21
app/reducers/index.ts Normal file
View File

@@ -0,0 +1,21 @@
import { authorizeReducer } from "./authorize";
import { circleReducer } from "./circles";
import { commentReducer } from "./comments";
import { globalReducer } from "./global";
import { imageGalleryReducer } from "./imageGallery";
import { notificationReducer } from "./notifications";
import { postReducer } from "./posts";
import { userReducer } from "./users";
import { voteReducer } from "./votes";
export{
authorizeReducer,
circleReducer,
commentReducer,
globalReducer,
imageGalleryReducer,
notificationReducer,
postReducer,
userReducer,
voteReducer
}

View File

@@ -0,0 +1,14 @@
import {NotificationActionType} from 'constants/notificationActionType'
/**
* Notification action interface
*
* @export
* @interface INotificationAction
*/
export interface INotificationAction {
payload: any,
type: NotificationActionType
}

View File

@@ -0,0 +1,26 @@
import { Notification } from "domain/notifications";
/**
* Notification state
*
* @export
* @class NotificationState
*/
export class NotificationState {
/**
* The list of users notification
*
* @type {({[userId: string]: {[notificationId: string]: Notification}} | null)}
* @memberof NotificationState
*/
userNotifies: {[userId: string]: {[notificationId: string]: Notification}} = {};
/**
* If user notifications are loaded {true} or not {false}
*
* @type {Boolean}
* @memberof NotificationState
*/
loaded: Boolean = false;
}

View File

@@ -0,0 +1,3 @@
import { notificationReducer } from "./notificationReducer";
export {notificationReducer};

View File

@@ -2,19 +2,14 @@
import moment from 'moment'
import _ from 'lodash'
// - Import domain
import { Notification } from "domain/notifications";
// - Import action types
import * as types from 'actionTypes'
import {NotificationActionType} from 'constants/notificationActionType'
/**
* Default state
*/
var defaultState = {
userNotifies: {},
loaded:false
}
import { NotificationState } from "./NotificationState";
import { INotificationAction } from "./INotificationAction";
/**
@@ -22,15 +17,15 @@ var defaultState = {
* @param {object} state
* @param {object} action
*/
export var notifyReducer = (state = defaultState, action) => {
export var notificationReducer = (state: NotificationState = new NotificationState(), action: INotificationAction) => {
var { payload } = action
switch (action.type) {
/* _____________ CRUD _____________ */
case types.ADD_NOTIFY:
case NotificationActionType.ADD_NOTIFY:
return state
case types.ADD_NOTIFY_LIST:
case NotificationActionType.ADD_NOTIFY_LIST:
return {
...state,
userNotifies: {
@@ -39,24 +34,24 @@ export var notifyReducer = (state = defaultState, action) => {
loaded:true
}
case types.SEEN_NOTIFY:
case NotificationActionType.SEEN_NOTIFY:
return {
...state,
userNotifies: {
...state.userNotifies,
[payload]:{
...state.userNotifies[payload],
...state.userNotifies![payload],
isSeen:true
}
},
loaded:true
}
case types.DELETE_NOTIFY:
case NotificationActionType.DELETE_NOTIFY:
var parsedNotifies = {}
Object.keys(state.userNotifies).map((id) => {
Object.keys(state.userNotifies!).map((id) => {
if (id !== payload) {
_.merge(parsedNotifies, { [id]: { ...state.userNotifies[id] } })
_.merge(parsedNotifies, { [id]: { ...state.userNotifies![id] } })
}
})
@@ -68,8 +63,8 @@ export var notifyReducer = (state = defaultState, action) => {
}
case types.CLEAR_ALL_DATA_NOTIFY:
return defaultState
case NotificationActionType.CLEAR_ALL_DATA_NOTIFY:
return new NotificationState()
default:

View File

@@ -0,0 +1,13 @@
import { PostActionType } from "constants/postActionType";
/**
* Post action interface
*
* @export
* @interface IPostAction
*/
export interface IPostAction {
payload: any,
type: PostActionType
}

View File

@@ -0,0 +1,25 @@
/**
* Post state
*
* @export
* @class PostState
*/
export class PostState {
/**
* The list of user posts
*
* @type {*}
* @memberof PostState
*/
userPosts: any = {};
/**
* If user posts are loaded {true} or not {false}
*
* @type {Boolean}
* @memberof PostState
*/
loaded: Boolean = false;
}

View File

@@ -0,0 +1,3 @@
import { postReducer } from "./postReducer";
export {postReducer};

View File

@@ -1,5 +1,4 @@
// - Import react components
var uuid = require('uuid');
import moment from 'moment'
import _ from 'lodash'
import {Reducer, Action} from "redux";
@@ -8,57 +7,21 @@ import {Reducer, Action} from "redux";
// - Import action types
import { PostActionType } from "constants/postActionType";
/* ---------------- */
import { PostState } from "./PostState";
import { IPostAction } from "./IPostAction";
// - Import react components
/**
* Default post state
*
* @export
* @interface IPostState
*/
export interface IPostState {
userPosts: any,
loaded: boolean
}
/**
*
*
* @export
* @interface IPostAction
*/
export interface IPostAction {
payload: any,
type: PostActionType
}
/**
* Default post reducer state
*
* @export
* @class DefaultPostState
* @implements {IPostState}
*/
export class DefaultPostState implements IPostState{
userPosts: any = {};
loaded: boolean = false;
}
/**
* Post reducer
* @param {object} state
* @param {object} action
*/
export var postReducer = (state : IPostState = new DefaultPostState(), action : IPostAction) => {
export var postReducer = (state : PostState = new PostState(), action : IPostAction) => {
const { payload } = action;
switch (action.type) {
case PostActionType.CLEAR_ALL_DATA_POST:
return new DefaultPostState()
return new PostState()
case PostActionType.ADD_IMAGE_POST:
return {

View File

@@ -0,0 +1,13 @@
import {UserActionType} from 'constants/userActionType'
/**
* User action interface
*
* @export
* @interface IUserAction
*/
export interface IUserAction {
payload: any,
type: UserActionType
}

View File

@@ -0,0 +1,33 @@
import { User,Profile } from "domain/users";
/**
* User state
*
* @export
* @class UserState
*/
export class UserState {
/**
* The list of users information
*
* @type {({[userId: string]: Profile} | null)}
* @memberof UserState
*/
info: {[userId: string]: Profile} = {};
/**
* If users profile are loaded
*
* @type {Boolean}
* @memberof UserState
*/
loaded: Boolean = false;
/**
* If edit profile is open {true} or not {false}
*
* @type {Boolean}
* @memberof UserState
*/
openEditProfile: Boolean = false;
}

View File

@@ -0,0 +1,3 @@
import { userReducer } from "./userReducer";
export {userReducer};

View File

@@ -1,22 +1,19 @@
// - Import action types
import * as types from 'actionTypes'
import {UserActionType} from 'constants/userActionType'
/**
* Default state for reducer
*/
var defaultState = {
info: {},
loaded: false,
openEditProfile: false
}
// - Import domain
import { User,Profile } from "domain/users";
import { UserState } from "./UserState";
import { IUserAction } from "./IUserAction";
/**
* User reducer
*/
export var userReducer = (state = defaultState, action) => {
export var userReducer = (state: UserState = new UserState(), action: IUserAction) => {
const { payload } = action
switch (action.type) {
case types.USER_INFO:
case UserActionType.USER_INFO:
return {
...state,
info: {
@@ -26,7 +23,7 @@ export var userReducer = (state = defaultState, action) => {
}
}
}
case types.ADD_USER_INFO:
case UserActionType.ADD_USER_INFO:
return {
...state,
info: {
@@ -37,7 +34,7 @@ export var userReducer = (state = defaultState, action) => {
},
loaded: true
}
case types.ADD_PEOPLE_INFO:
case UserActionType.ADD_PEOPLE_INFO:
return {
...state,
info: {
@@ -46,29 +43,29 @@ export var userReducer = (state = defaultState, action) => {
}
}
case types.UPDATE_USER_INFO:
case UserActionType.UPDATE_USER_INFO:
return {
...state,
info: {
...state.info,
[payload.uid]: {
...state.info[payload.uid],
...state.info![payload.uid],
...payload.info
}
}
}
case types.CLEAR_ALL_DATA_USER:
return defaultState
case UserActionType.CLEAR_ALL_DATA_USER:
return new UserState();
case types.CLOSE_EDIT_PROFILE:
case UserActionType.CLOSE_EDIT_PROFILE:
return {
...state,
openEditProfile: false
}
case types.OPEN_EDIT_PROFILE:
case UserActionType.OPEN_EDIT_PROFILE:
return {
...state,
openEditProfile: true

View File

@@ -0,0 +1,14 @@
import {VoteActionType} from 'constants/voteActionType'
/**
* Vote action interface
*
* @export
* @interface IVoteAction
*/
export interface IVoteAction {
payload: any,
type: VoteActionType
}

View File

@@ -0,0 +1,26 @@
import { Vote } from "domain/votes";
/**
* Vote state
*
* @export
* @class VoteState
*/
export class VoteState {
/**
* The list of posts vote
*
* @type {({[postId: string]: {[voteId: string]: Vote}} | null)}
* @memberof VoteState
*/
postVotes: {[postId: string]: {[voteId: string]: Vote}} | null = null;
/**
* If posts vote are loaded {true} or not {false}
*
* @type {Boolean}
* @memberof VoteState
*/
loaded: Boolean = false;
}

View File

@@ -0,0 +1,3 @@
import { voteReducer } from "./voteReducer";
export {voteReducer};

View File

@@ -2,19 +2,15 @@
import moment from 'moment'
import _ from 'lodash'
// - Import action types
import * as types from 'actionTypes'
import {VoteActionType} from 'constants/voteActionType'
// Import domain
import { Vote } from "domain/votes";
/**
* Default state
*/
var defaultState = {
postVotes: {},
loaded:false
}
import { VoteState } from "./VoteState";
import { IVoteAction } from "./IVoteAction";
/**
@@ -22,26 +18,26 @@ var defaultState = {
* @param {object} state
* @param {object} action
*/
export var voteReducer = (state = defaultState, action) => {
export var voteReducer = (state: VoteState = new VoteState(), action: IVoteAction) => {
var { payload } = action
switch (action.type) {
/* _____________ CRUD _____________ */
case types.ADD_VOTE:
case VoteActionType.ADD_VOTE:
return {
...state,
postVotes: {
...state.postVotes,
[payload.postId]: {
...state.postVotes[payload.postId],
...state.postVotes![payload.postId],
[payload.id]: {
...payload.vote
...payload
}
}
}
}
case types.ADD_VOTE_LIST:
case VoteActionType.ADD_VOTE_LIST:
return {
...state,
postVotes: {
@@ -50,12 +46,12 @@ export var voteReducer = (state = defaultState, action) => {
loaded:true
}
case types.DELETE_VOTE:
case VoteActionType.DELETE_VOTE:
var parsedVotes = {}
if (state.postVotes[payload.postId])
Object.keys(state.postVotes[payload.postId]).map((id) => {
if (state.postVotes![payload.postId])
Object.keys(state.postVotes![payload.postId]).map((id) => {
if (id !== payload.id) {
_.merge(parsedVotes, { [id]: { ...state.postVotes[payload.postId][id] } })
_.merge(parsedVotes, { [id]: { ...state.postVotes![payload.postId][id] } })
}
})
@@ -70,8 +66,8 @@ export var voteReducer = (state = defaultState, action) => {
}
case types.CLEAR_ALL_DATA_VOTE:
return defaultState
case VoteActionType.CLEAR_ALL_DATA_VOTE:
return new VoteState();
default:

View File

@@ -0,0 +1,19 @@
import { User } from "domain/users";
import { Circle, UserFollower } from "domain/circles";
/**
* Circle service interface
*
* @export
* @interface ICircleService
*/
export interface ICircleService {
addCircle: (userId: string, circle: Circle) => Promise<string>;
addFollowingUser: (userId: string, circleId:string, userCircle: User, userFollower: UserFollower, userFollowingId: string) => Promise<void>;
deleteFollowingUser: (userId: string, circleId: string,userFollowingId: string) => Promise<void>;
updateCircle: (userId: string, circle: Circle, circleId: string) => Promise<void>;
deleteCircle: (circleId: string, userId: string) => Promise<void>;
getCircles: () => Promise<{ [circleId: string]: Circle }>;
getCirclesByUserId: (userId: string) => Promise<{ [circleId: string]: Circle }>;
}

View File

@@ -0,0 +1,5 @@
import { ICircleService } from "./ICircleService";
export {
ICircleService
}

View File

@@ -0,0 +1,15 @@
import { User } from "domain/users";
/**
* Comment service interface
*
* @export
* @interface ICommentService
*/
export interface ICommentService {
}

View File

@@ -0,0 +1,5 @@
import { ICommentService } from "./ICommentService";
export {
ICommentService
}

View File

@@ -0,0 +1,16 @@
import { User } from "domain/users";
/**
* Common service interface
*
* @export
* @interface ICommonService
*/
export interface ICommonService {
}

Some files were not shown because too many files have changed in this diff Show More