Skip to content

Commit ecce49b

Browse files
committed
Add list loading message
1 parent 1409585 commit ecce49b

File tree

7 files changed

+18
-3
lines changed

7 files changed

+18
-3
lines changed

client/src/components/Categories/CategoryList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class CategoryList extends Component {
2424
/>
2525
</div>,
2626
)}
27+
{resourceList.empty && resourceList.loading && <p>Loading...</p>}
2728
<CategoryForm
2829
isNew={true}
2930
form="category-new"

client/src/components/Dashboard.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class Dashobard extends Component {
2323
return (
2424
<div>
2525
<h4>Latest posts</h4>
26+
{postsList.empty && postsList.loading && <p>Loading...</p>}
2627
{postsList.data.map(post =>
2728
<div key={post.id}>
2829
<Link to={`/posts/${post.id}`}>{post.title}</Link>

client/src/components/Posts/PostList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class PostList extends Component {
7575
</tbody>
7676
</Table>
7777
<Pagination {...this.props}></Pagination>
78+
{resourceList.empty && resourceList.loading && <p>Loading...</p>}
7879
</div>
7980
);
8081
}

client/src/components/Users/UserList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class UserList extends Component {
4343
</tbody>
4444
</Table>
4545
<Pagination {...this.props}></Pagination>
46+
{resourceList.empty && resourceList.loading && <p>Loading...</p>}
4647
</div>
4748
);
4849
}

client/src/store/api/reducer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ export default (state = initialState, action) => {
4848
case actionType(GET_ONE, SUCCESS): {
4949
return addNormalized(newState, payload);
5050
}
51+
case actionType(GET_LIST, STARTED): {
52+
console.log('loading');
53+
return imm.set(newState, [key, list, 'loading'], true);
54+
}
5155
case actionType(GET_LIST, SUCCESS): {
56+
console.log('loaded');
5257
newState = addNormalized(newState, payload);
5358
newState = imm.set(newState, [key, list, 'ids'], map(payload.data, 'id'));
5459
newState = imm.set(newState, [key, list, 'params'], payload.params);
5560
newState = imm.set(newState, [key, list, 'links'], payload.links);
5661
newState = imm.set(newState, [key, list, 'meta'], payload.meta);
62+
newState = imm.set(newState, [key, list, 'loading'], false);
5763
return newState;
5864
}
5965
case actionType(GET_MANY, SUCCESS): {

client/src/store/api/selectors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const getMany = (state, resourceName, ids) => {
1919
export const getList = (state, resourceName, listName = 'list') => {
2020
const byId = get(state, ['api', resourceName, 'byId']) || {};
2121
const list = get(state, ['api', resourceName, listName]) || {};
22-
return isEmpty(list)
23-
? { data: [], ids: [], links: {}, params: { page: {}, filter: {} } }
24-
: { ...list, data: list.ids.map(id => byId[id]) };
22+
return isEmpty(list.ids)
23+
? { data: [], ids: [], links: {}, params: { page: {}, filter: {} }, loading: true, empty: true }
24+
: { ...list, empty: false, data: list.ids.map(id => byId[id]) };
2525
};

client/webpack.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ module.exports = removeEmpty({
5151
'/**': {
5252
target: 'http://localhost:3001',
5353
},
54+
// '/**': {
55+
// target: 'https://rails-json-api-react.herokuapp.com',
56+
// secure: true,
57+
// changeOrigin: true,
58+
// },
5459
}
5560
}),
5661

0 commit comments

Comments
 (0)