This repository has been archived by the owner on Jul 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improvement] Move get comments action to saga (#48)
- Loading branch information
Showing
17 changed files
with
233 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import StringAPI from 'api/StringAPI' | ||
import { ServerRequestType } from 'constants/serverRequestType' | ||
import { ServerRequestModel } from 'models/server' | ||
import { ServerRequestStatusType } from 'actions/serverRequestStatusType' | ||
import { comments } from 'models/comments/commentTypes' | ||
import * as _ from 'lodash' | ||
|
||
/** | ||
* Create get comments server request model | ||
*/ | ||
const createGetCommentsRequest = (postId: string) => { | ||
const requestId = StringAPI.createServerRequestId(ServerRequestType.CommentGetComments, postId) | ||
return new ServerRequestModel( | ||
ServerRequestType.CommentGetComments, | ||
requestId, | ||
'', | ||
ServerRequestStatusType.Sent | ||
) | ||
} | ||
|
||
const sortCommentsByDate = (sortedObjects: comments) => { | ||
const commentKeys = Object.keys(sortedObjects) | ||
if (commentKeys.length > 1) { | ||
return _.fromPairs(_.toPairs(sortedObjects) | ||
.sort((a: any, b: any) => parseInt(b[1].creationDate, 10) - parseInt(a[1].creationDate, 10)).slice(0, 3)) | ||
|
||
} | ||
} | ||
|
||
export default { | ||
createGetCommentsRequest, | ||
sortCommentsByDate | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {Comment} from 'core/domain/comments' | ||
export type postComments = {[postId: string]: {[commentId: string]: Comment}} | ||
export type comments = {[commentId: string]: Comment} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const getCurrentUser = (state: any) => (state.user.info && state.authorize.uid) ? state.user.info[state.authorize.uid] : null | ||
|
||
export const authorizeSelector = { | ||
getCurrentUser | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { authorizeReducer } from './authorizeReducer' | ||
|
||
export {authorizeReducer} | ||
import {authorizeSelector} from './authorizeSelector' | ||
export { | ||
authorizeReducer, | ||
authorizeSelector | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { postReducer } from './postReducer' | ||
import { postSelector } from './postSelector' | ||
|
||
export {postReducer} | ||
export { | ||
postReducer, | ||
postSelector | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const getPost = (state: any, userId: string, postId: string) => { | ||
return (state.post.userPosts && state.post.userPosts[userId] && state.post.userPosts[userId][postId]) | ||
? state.post.userPosts[userId][postId] | ||
: null | ||
} | ||
|
||
export const postSelector = { | ||
getPost | ||
} |
Oops, something went wrong.