diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index f431d867..e6205367 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -61,8 +61,9 @@ class PostsController < ApplicationController defaults = { board_id: Board.first.id } params - .permit(:board_id, :post_status_id) + .permit(:board_id, :post_status_id, :page, :search) .with_defaults(defaults) + .except(:page, :search) end def post_params diff --git a/app/javascript/components/Board/BoardP.tsx b/app/javascript/components/Board/BoardP.tsx index be04f4f9..882945ba 100644 --- a/app/javascript/components/Board/BoardP.tsx +++ b/app/javascript/components/Board/BoardP.tsx @@ -71,6 +71,7 @@ class BoardP extends React.Component { handleSearchFilterChange, handlePostStatusFilterChange, } = this.props; + const { filters } = posts; return (
@@ -81,7 +82,7 @@ class BoardP extends React.Component { authenticityToken={authenticityToken} /> { areLoading={postStatuses.areLoading} error={postStatuses.error} - currentFilter={posts.filters.postStatusId} + currentFilter={filters.postStatusId} handleFilterClick={handlePostStatusFilterChange} />
@@ -102,7 +103,9 @@ class BoardP extends React.Component { areLoading={posts.areLoading} error={posts.error} - handleLoadMore={() => posts.areLoading ? null : requestPosts(board.id, posts.page + 1)} + handleLoadMore={() => + requestPosts(board.id, posts.page + 1, filters.searchQuery, filters.postStatusId) + } /> ); diff --git a/app/javascript/components/Board/index.tsx b/app/javascript/components/Board/index.tsx index b060221b..42090b49 100644 --- a/app/javascript/components/Board/index.tsx +++ b/app/javascript/components/Board/index.tsx @@ -1,20 +1,41 @@ import * as React from 'react'; import { Provider } from 'react-redux'; -import store from '../../stores'; - import Board from '../../containers/Board'; +import createStoreHelper from '../../helpers/createStore'; import '../../stylesheets/components/Board.scss'; -const BoardRoot = ({ board, isLoggedIn, authenticityToken }) => ( - - - -); +import IBoard from '../../interfaces/IBoard'; + +interface Props { + board: IBoard; + isLoggedIn: boolean; + authenticityToken: string; +} + +class BoardRoot extends React.Component { + store: any; + + constructor(props) { + super(props); + + this.store = createStoreHelper(); + } + + render() { + const { board, isLoggedIn, authenticityToken } = this.props; + + return ( + + + + ); + } +} export default BoardRoot; \ No newline at end of file diff --git a/app/javascript/components/Post/index.tsx b/app/javascript/components/Post/index.tsx index a8c45c4e..ff9cfdd9 100644 --- a/app/javascript/components/Post/index.tsx +++ b/app/javascript/components/Post/index.tsx @@ -1,23 +1,53 @@ import * as React from 'react'; import { Provider } from 'react-redux'; -import store from '../../stores'; +import createStoreHelper from '../../helpers/createStore'; import Post from '../../containers/Post'; +import IPostStatus from '../../interfaces/IPostStatus'; + import '../../stylesheets/components/Post.scss'; -const PostRoot = ({ postId, postStatuses, isLoggedIn, isPowerUser, authenticityToken }) => ( - - ; + isLoggedIn: boolean; + isPowerUser: boolean; + authenticityToken: string; +} - isLoggedIn={isLoggedIn} - isPowerUser={isPowerUser} - authenticityToken={authenticityToken} - /> - -); +class PostRoot extends React.Component { + store: any; + + constructor(props) { + super(props); + + this.store = createStoreHelper(); + } + + render() { + const { + postId, + postStatuses, + isLoggedIn, + isPowerUser, + authenticityToken + } = this.props; + + return ( + + + + ); + } +} export default PostRoot; \ No newline at end of file diff --git a/app/javascript/containers/Board.tsx b/app/javascript/containers/Board.tsx index da82e870..1f640441 100644 --- a/app/javascript/containers/Board.tsx +++ b/app/javascript/containers/Board.tsx @@ -17,7 +17,7 @@ const mapStateToProps = (state: State) => ({ }); const mapDispatchToProps = (dispatch) => ({ - requestPosts(boardId: number, page: number = 1, searchQuery: string = '', postStatusId: number) { + requestPosts(boardId: number, page: number = 1, searchQuery: string = '', postStatusId: number = null) { dispatch(requestPosts(boardId, page, searchQuery, postStatusId)); }, diff --git a/app/javascript/helpers/createStore.ts b/app/javascript/helpers/createStore.ts new file mode 100644 index 00000000..5f093898 --- /dev/null +++ b/app/javascript/helpers/createStore.ts @@ -0,0 +1,15 @@ +import { createStore, applyMiddleware } from 'redux'; +import thunkMiddleware from 'redux-thunk'; + +import rootReducer from '../reducers/rootReducer'; + +const createStoreHelper = () => ( + createStore( + rootReducer, + applyMiddleware( + thunkMiddleware, + ), + ) +); + +export default createStoreHelper; \ No newline at end of file diff --git a/app/javascript/stores/index.ts b/app/javascript/stores/index.ts deleted file mode 100644 index bfd9c99e..00000000 --- a/app/javascript/stores/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { createStore, applyMiddleware } from 'redux'; -import thunkMiddleware from 'redux-thunk'; - -import rootReducer from '../reducers/rootReducer'; - -const store = createStore( - rootReducer, - applyMiddleware( - thunkMiddleware, - ), -); - -store.subscribe(() => console.log(store.getState())); - -export default store; \ No newline at end of file