mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
Redux store is not a singleton anymore (-> bug fixes)
This commit is contained in:
@@ -61,8 +61,9 @@ class PostsController < ApplicationController
|
|||||||
defaults = { board_id: Board.first.id }
|
defaults = { board_id: Board.first.id }
|
||||||
|
|
||||||
params
|
params
|
||||||
.permit(:board_id, :post_status_id)
|
.permit(:board_id, :post_status_id, :page, :search)
|
||||||
.with_defaults(defaults)
|
.with_defaults(defaults)
|
||||||
|
.except(:page, :search)
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_params
|
def post_params
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ class BoardP extends React.Component<Props> {
|
|||||||
handleSearchFilterChange,
|
handleSearchFilterChange,
|
||||||
handlePostStatusFilterChange,
|
handlePostStatusFilterChange,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
const { filters } = posts;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="boardContainer">
|
<div className="boardContainer">
|
||||||
@@ -81,7 +82,7 @@ class BoardP extends React.Component<Props> {
|
|||||||
authenticityToken={authenticityToken}
|
authenticityToken={authenticityToken}
|
||||||
/>
|
/>
|
||||||
<SearchFilter
|
<SearchFilter
|
||||||
searchQuery={posts.filters.searchQuery}
|
searchQuery={filters.searchQuery}
|
||||||
handleChange={handleSearchFilterChange}
|
handleChange={handleSearchFilterChange}
|
||||||
/>
|
/>
|
||||||
<PostStatusFilter
|
<PostStatusFilter
|
||||||
@@ -89,7 +90,7 @@ class BoardP extends React.Component<Props> {
|
|||||||
areLoading={postStatuses.areLoading}
|
areLoading={postStatuses.areLoading}
|
||||||
error={postStatuses.error}
|
error={postStatuses.error}
|
||||||
|
|
||||||
currentFilter={posts.filters.postStatusId}
|
currentFilter={filters.postStatusId}
|
||||||
handleFilterClick={handlePostStatusFilterChange}
|
handleFilterClick={handlePostStatusFilterChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -102,7 +103,9 @@ class BoardP extends React.Component<Props> {
|
|||||||
areLoading={posts.areLoading}
|
areLoading={posts.areLoading}
|
||||||
error={posts.error}
|
error={posts.error}
|
||||||
|
|
||||||
handleLoadMore={() => posts.areLoading ? null : requestPosts(board.id, posts.page + 1)}
|
handleLoadMore={() =>
|
||||||
|
requestPosts(board.id, posts.page + 1, filters.searchQuery, filters.postStatusId)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,20 +1,41 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
|
|
||||||
import store from '../../stores';
|
|
||||||
|
|
||||||
import Board from '../../containers/Board';
|
import Board from '../../containers/Board';
|
||||||
|
import createStoreHelper from '../../helpers/createStore';
|
||||||
|
|
||||||
import '../../stylesheets/components/Board.scss';
|
import '../../stylesheets/components/Board.scss';
|
||||||
|
|
||||||
const BoardRoot = ({ board, isLoggedIn, authenticityToken }) => (
|
import IBoard from '../../interfaces/IBoard';
|
||||||
<Provider store={store}>
|
|
||||||
<Board
|
interface Props {
|
||||||
board={board}
|
board: IBoard;
|
||||||
isLoggedIn={isLoggedIn}
|
isLoggedIn: boolean;
|
||||||
authenticityToken={authenticityToken}
|
authenticityToken: string;
|
||||||
/>
|
}
|
||||||
</Provider>
|
|
||||||
);
|
class BoardRoot extends React.Component<Props> {
|
||||||
|
store: any;
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.store = createStoreHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { board, isLoggedIn, authenticityToken } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Provider store={this.store}>
|
||||||
|
<Board
|
||||||
|
board={board}
|
||||||
|
isLoggedIn={isLoggedIn}
|
||||||
|
authenticityToken={authenticityToken}
|
||||||
|
/>
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default BoardRoot;
|
export default BoardRoot;
|
||||||
@@ -1,23 +1,53 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
|
|
||||||
import store from '../../stores';
|
import createStoreHelper from '../../helpers/createStore';
|
||||||
|
|
||||||
import Post from '../../containers/Post';
|
import Post from '../../containers/Post';
|
||||||
|
|
||||||
|
import IPostStatus from '../../interfaces/IPostStatus';
|
||||||
|
|
||||||
import '../../stylesheets/components/Post.scss';
|
import '../../stylesheets/components/Post.scss';
|
||||||
|
|
||||||
const PostRoot = ({ postId, postStatuses, isLoggedIn, isPowerUser, authenticityToken }) => (
|
interface Props {
|
||||||
<Provider store={store}>
|
postId: number;
|
||||||
<Post
|
postStatuses: Array<IPostStatus>;
|
||||||
postId={postId}
|
isLoggedIn: boolean;
|
||||||
postStatuses={postStatuses}
|
isPowerUser: boolean;
|
||||||
|
authenticityToken: string;
|
||||||
|
}
|
||||||
|
|
||||||
isLoggedIn={isLoggedIn}
|
class PostRoot extends React.Component<Props> {
|
||||||
isPowerUser={isPowerUser}
|
store: any;
|
||||||
authenticityToken={authenticityToken}
|
|
||||||
/>
|
constructor(props) {
|
||||||
</Provider>
|
super(props);
|
||||||
);
|
|
||||||
|
this.store = createStoreHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
postId,
|
||||||
|
postStatuses,
|
||||||
|
isLoggedIn,
|
||||||
|
isPowerUser,
|
||||||
|
authenticityToken
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Provider store={this.store}>
|
||||||
|
<Post
|
||||||
|
postId={postId}
|
||||||
|
postStatuses={postStatuses}
|
||||||
|
|
||||||
|
isLoggedIn={isLoggedIn}
|
||||||
|
isPowerUser={isPowerUser}
|
||||||
|
authenticityToken={authenticityToken}
|
||||||
|
/>
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default PostRoot;
|
export default PostRoot;
|
||||||
@@ -17,7 +17,7 @@ const mapStateToProps = (state: State) => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
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));
|
dispatch(requestPosts(boardId, page, searchQuery, postStatusId));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
15
app/javascript/helpers/createStore.ts
Normal file
15
app/javascript/helpers/createStore.ts
Normal file
@@ -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;
|
||||||
@@ -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;
|
|
||||||
Reference in New Issue
Block a user