From 476f720119a30f8bfad1259ecc787bdea38aa519 Mon Sep 17 00:00:00 2001 From: riggraz Date: Tue, 17 Sep 2019 15:03:25 +0200 Subject: [PATCH] Remove comments pagination --- app/controllers/comments_controller.rb | 1 - app/javascript/actions/requestComments.ts | 8 ++------ .../components/Comments/CommentsP.tsx | 4 ---- app/javascript/components/Post/PostP.tsx | 1 - app/javascript/containers/Comments.tsx | 6 ++---- app/javascript/containers/Post.tsx | 4 ---- app/javascript/reducers/commentsReducer.ts | 18 +++--------------- app/models/comment.rb | 2 -- 8 files changed, 7 insertions(+), 37 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 37bc3d19..df7d4224 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -7,7 +7,6 @@ class CommentsController < ApplicationController .left_outer_joins(:user) .select('comments.id, comments.body, comments.updated_at, users.full_name as user_full_name') .order(updated_at: :desc) - .page(params[:page]) render json: comments end diff --git a/app/javascript/actions/requestComments.ts b/app/javascript/actions/requestComments.ts index 74e93c79..95570438 100644 --- a/app/javascript/actions/requestComments.ts +++ b/app/javascript/actions/requestComments.ts @@ -14,7 +14,6 @@ export const COMMENTS_REQUEST_SUCCESS = 'COMMENTS_REQUEST_SUCCESS'; interface CommentsRequestSuccessAction { type: typeof COMMENTS_REQUEST_SUCCESS; comments: Array; - page: number; } export const COMMENTS_REQUEST_FAILURE = 'COMMENTS_REQUEST_FAILURE'; @@ -35,11 +34,9 @@ const commentsRequestStart = (): CommentsRequestActionTypes => ({ const commentsRequestSuccess = ( comments: Array, - page: number ): CommentsRequestActionTypes => ({ type: COMMENTS_REQUEST_SUCCESS, comments, - page, }); const commentsRequestFailure = (error: string): CommentsRequestActionTypes => ({ @@ -49,14 +46,13 @@ const commentsRequestFailure = (error: string): CommentsRequestActionTypes => ({ export const requestComments = ( postId: number, - page: number, ): ThunkAction> => async (dispatch) => { dispatch(commentsRequestStart()); try { - const response = await fetch(`/posts/${postId}/comments?page=${page}`); + const response = await fetch(`/posts/${postId}/comments`); const json = await response.json(); - dispatch(commentsRequestSuccess(json, page)); + dispatch(commentsRequestSuccess(json)); } catch (e) { dispatch(commentsRequestFailure(e)); } diff --git a/app/javascript/components/Comments/CommentsP.tsx b/app/javascript/components/Comments/CommentsP.tsx index c10de968..d799f7e2 100644 --- a/app/javascript/components/Comments/CommentsP.tsx +++ b/app/javascript/components/Comments/CommentsP.tsx @@ -8,8 +8,6 @@ interface Props { comments: Array; areLoading: boolean; error: string; - page: number; - haveMore: boolean; requestComments(postId: number, page?: number); } @@ -24,8 +22,6 @@ class CommentsP extends React.Component { comments, areLoading, error, - page, - haveMore, } = this.props; return ( diff --git a/app/javascript/components/Post/PostP.tsx b/app/javascript/components/Post/PostP.tsx index 4f3fb383..70e0ebde 100644 --- a/app/javascript/components/Post/PostP.tsx +++ b/app/javascript/components/Post/PostP.tsx @@ -16,7 +16,6 @@ interface Props { authenticityToken: string; requestPost(postId: number): void; - requestComments(postId: number, page?: number): void; changePostStatus( postId: number, newPostStatusId: number, diff --git a/app/javascript/containers/Comments.tsx b/app/javascript/containers/Comments.tsx index 4ac7879c..9879542c 100644 --- a/app/javascript/containers/Comments.tsx +++ b/app/javascript/containers/Comments.tsx @@ -10,13 +10,11 @@ const mapStateToProps = (state: State) => ({ comments: state.currentPost.comments.items, areLoading: state.currentPost.comments.areLoading, error: state.currentPost.comments.error, - page: state.currentPost.comments.page, - haveMore: state.currentPost.comments.haveMore, }); const mapDispatchToProps = (dispatch) => ({ - requestComments(postId: number, page: number = 1) { - dispatch(requestComments(postId, page)); + requestComments(postId: number) { + dispatch(requestComments(postId)); }, }); diff --git a/app/javascript/containers/Post.tsx b/app/javascript/containers/Post.tsx index e1ff68e5..876bbbea 100644 --- a/app/javascript/containers/Post.tsx +++ b/app/javascript/containers/Post.tsx @@ -18,10 +18,6 @@ const mapDispatchToProps = (dispatch) => ({ dispatch(requestPost(postId)); }, - requestComments(postId: number, page: number = 1) { - dispatch(requestComments(postId, page)); - }, - changePostStatus(postId: number, newPostStatusId: number, authenticityToken: string) { if (isNaN(newPostStatusId)) newPostStatusId = null; diff --git a/app/javascript/reducers/commentsReducer.ts b/app/javascript/reducers/commentsReducer.ts index eda17cc1..c55f0356 100644 --- a/app/javascript/reducers/commentsReducer.ts +++ b/app/javascript/reducers/commentsReducer.ts @@ -14,16 +14,12 @@ export interface CommentsState { items: Array; areLoading: boolean; error: string; - page: number; - haveMore: boolean; } const initialState: CommentsState = { items: [], areLoading: false, error: '', - page: 0, - haveMore: true, }; const commentsReducer = ( @@ -40,17 +36,9 @@ const commentsReducer = ( case COMMENTS_REQUEST_SUCCESS: return { ...state, - items: action.page === 1 ? - action.comments.map(comment => commentReducer(undefined, commentRequestSuccess(comment))) - : - [ - ...state.items, - ...action.comments.map( - comment => commentReducer(undefined, commentRequestSuccess(comment)) - ), - ], - page: action.page, - haveMore: action.comments.length === 15, + items: action.comments.map( + comment => commentReducer(undefined, commentRequestSuccess(comment)) + ), areLoading: false, error: '', }; diff --git a/app/models/comment.rb b/app/models/comment.rb index 62da3d65..d3c4f2dc 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -5,6 +5,4 @@ class Comment < ApplicationRecord has_many :children, class_name: 'Comment', foreign_key: 'parent_id', dependent: :destroy validates :body, presence: true, length: { minimum: 4 } - - paginates_per 15 end