Skip to content

Commit a9e518c

Browse files
authored
Merge pull request #2996 from adityagarg06/refactor/loading
Refactor loading actions
2 parents 96c5470 + 88f6526 commit a9e518c

File tree

7 files changed

+16
-28
lines changed

7 files changed

+16
-28
lines changed

client/constants.js

-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ export const SET_SORT_PARAMS = 'SET_SORT_PARAMS';
137137
export const SET_SEARCH_TERM = 'SET_SEARCH_TERM';
138138
export const CLOSE_SKETCHLIST_MODAL = 'CLOSE_SKETCHLIST_MODAL';
139139

140-
export const START_LOADING = 'START_LOADING';
141-
export const STOP_LOADING = 'STOP_LOADING';
142-
143140
export const START_SAVING_PROJECT = 'START_SAVING_PROJECT';
144141
export const END_SAVING_PROJECT = 'END_SAVING_PROJECT';
145142

client/modules/IDE/actions/assets.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import apiClient from '../../../utils/apiClient';
22
import * as ActionTypes from '../../../constants';
3-
import { startLoader, stopLoader } from './loader';
3+
import { startLoader, stopLoader } from '../reducers/loading';
44
import { assetsActions } from '../reducers/assets';
55

66
const { setAssets, deleteAsset } = assetsActions;

client/modules/IDE/actions/collections.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import browserHistory from '../../../browserHistory';
22
import apiClient from '../../../utils/apiClient';
33
import * as ActionTypes from '../../../constants';
4-
import { startLoader, stopLoader } from './loader';
4+
import { startLoader, stopLoader } from '../reducers/loading';
55
import { setToastText, showToast } from './toast';
66

77
const TOAST_DISPLAY_TIME_MS = 1500;

client/modules/IDE/actions/loader.js

-9
This file was deleted.

client/modules/IDE/actions/projects.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import apiClient from '../../../utils/apiClient';
22
import * as ActionTypes from '../../../constants';
3-
import { startLoader, stopLoader } from './loader';
3+
import { startLoader, stopLoader } from '../reducers/loading';
44

55
// eslint-disable-next-line
66
export function getProjects(username) {

client/modules/IDE/actions/projects.unit.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { rest } from 'msw';
55

66
import * as ProjectActions from './projects';
77
import * as ActionTypes from '../../../constants';
8+
import { startLoader, stopLoader } from '../reducers/loading';
89
import {
910
initialTestState,
1011
mockProjects
@@ -33,9 +34,9 @@ describe('projects action creator tests', () => {
3334
store = mockStore(initialTestState);
3435

3536
const expectedActions = [
36-
{ type: ActionTypes.START_LOADING },
37+
{ type: startLoader.type },
3738
{ type: ActionTypes.SET_PROJECTS, projects: mockProjects },
38-
{ type: ActionTypes.STOP_LOADING }
39+
{ type: stopLoader.type }
3940
];
4041

4142
return store
+10-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import * as ActionTypes from '../../../constants';
1+
import { createSlice } from '@reduxjs/toolkit';
22

3-
const loading = (state = false, action) => {
4-
switch (action.type) {
5-
case ActionTypes.START_LOADING:
6-
return true;
7-
case ActionTypes.STOP_LOADING:
8-
return false;
9-
default:
10-
return state;
3+
const loadingSlice = createSlice({
4+
name: 'loading',
5+
initialState: false,
6+
reducers: {
7+
startLoader: () => true,
8+
stopLoader: () => false
119
}
12-
};
10+
});
1311

14-
export default loading;
12+
export const { startLoader, stopLoader } = loadingSlice.actions;
13+
export default loadingSlice.reducer;

0 commit comments

Comments
 (0)