Skip to content

Refactor loading actions #2996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ export const SET_SORT_PARAMS = 'SET_SORT_PARAMS';
export const SET_SEARCH_TERM = 'SET_SEARCH_TERM';
export const CLOSE_SKETCHLIST_MODAL = 'CLOSE_SKETCHLIST_MODAL';

export const START_LOADING = 'START_LOADING';
export const STOP_LOADING = 'STOP_LOADING';

export const START_SAVING_PROJECT = 'START_SAVING_PROJECT';
export const END_SAVING_PROJECT = 'END_SAVING_PROJECT';

Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/actions/assets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import apiClient from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from './loader';
import { startLoader, stopLoader } from '../reducers/loading';
import { assetsActions } from '../reducers/assets';

const { setAssets, deleteAsset } = assetsActions;
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/actions/collections.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import browserHistory from '../../../browserHistory';
import apiClient from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from './loader';
import { startLoader, stopLoader } from '../reducers/loading';
import { setToastText, showToast } from './toast';

const TOAST_DISPLAY_TIME_MS = 1500;
Expand Down
9 changes: 0 additions & 9 deletions client/modules/IDE/actions/loader.js

This file was deleted.

2 changes: 1 addition & 1 deletion client/modules/IDE/actions/projects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import apiClient from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from './loader';
import { startLoader, stopLoader } from '../reducers/loading';

// eslint-disable-next-line
export function getProjects(username) {
Expand Down
5 changes: 3 additions & 2 deletions client/modules/IDE/actions/projects.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { rest } from 'msw';

import * as ProjectActions from './projects';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from '../reducers/loading';
import {
initialTestState,
mockProjects
Expand Down Expand Up @@ -33,9 +34,9 @@ describe('projects action creator tests', () => {
store = mockStore(initialTestState);

const expectedActions = [
{ type: ActionTypes.START_LOADING },
{ type: startLoader.type },
{ type: ActionTypes.SET_PROJECTS, projects: mockProjects },
{ type: ActionTypes.STOP_LOADING }
{ type: stopLoader.type }
];

return store
Expand Down
21 changes: 10 additions & 11 deletions client/modules/IDE/reducers/loading.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as ActionTypes from '../../../constants';
import { createSlice } from '@reduxjs/toolkit';

const loading = (state = false, action) => {
switch (action.type) {
case ActionTypes.START_LOADING:
return true;
case ActionTypes.STOP_LOADING:
return false;
default:
return state;
const loadingSlice = createSlice({
name: 'loading',
initialState: false,
reducers: {
startLoader: () => true,
stopLoader: () => false
}
};
});

export default loading;
export const { startLoader, stopLoader } = loadingSlice.actions;
export default loadingSlice.reducer;