diff --git a/.env-example b/.env-example index 57194182..11a53b5b 100644 --- a/.env-example +++ b/.env-example @@ -5,4 +5,5 @@ POSTGRES_PASSWORD=yourpasswordhere APP_NAME="You App Name Here" -EMAIL_CONFIRMATION=0 \ No newline at end of file +EMAIL_CONFIRMATION=0 +POSTS_PER_PAGE=15 \ No newline at end of file diff --git a/app/javascript/constants/index.js b/app/javascript/constants/index.js new file mode 100644 index 00000000..e0d254d4 --- /dev/null +++ b/app/javascript/constants/index.js @@ -0,0 +1 @@ +export const POSTS_PER_PAGE = parseInt(process.env.POSTS_PER_PAGE); \ No newline at end of file diff --git a/app/javascript/reducers/postsReducer.ts b/app/javascript/reducers/postsReducer.ts index 193733d9..c263584c 100644 --- a/app/javascript/reducers/postsReducer.ts +++ b/app/javascript/reducers/postsReducer.ts @@ -5,6 +5,8 @@ import { FiltersState } from './filtersReducer'; import postReducer from './postReducer'; import filtersReducer from './filtersReducer'; +import { POSTS_PER_PAGE } from '../constants'; + import { PostsRequestActionTypes, POSTS_REQUEST_START, @@ -60,7 +62,7 @@ const postsReducer = ( : [...state.items, ...action.posts.map(post => postReducer(undefined, postRequestSuccess(post)))], page: action.page, - haveMore: action.posts.length === 15, + haveMore: action.posts.length === POSTS_PER_PAGE, areLoading: false, error: '', }; diff --git a/app/models/post.rb b/app/models/post.rb index 26540ab6..09f70f66 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -6,7 +6,7 @@ class Post < ApplicationRecord validates :title, presence: true, length: { in: 4..64 } - paginates_per 15 + paginates_per Rails.application.posts_per_page class << self def find_with_post_status_in(post_statuses) diff --git a/config/application.rb b/config/application.rb index e9e3b3cf..6b51a91b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,5 +23,9 @@ module App def email_confirmation? ENV["EMAIL_CONFIRMATION"] == "1" end + + def posts_per_page + ENV["POSTS_PER_PAGE"].to_i + end end end