Skip to content

refactor editorAccessibility reducers and actions using redux toolkit #3120

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
Show file tree
Hide file tree
Changes from 2 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
2 changes: 0 additions & 2 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export const CLEAR_CONSOLE = 'CLEAR_CONSOLE';
export const EXPAND_CONSOLE = 'EXPAND_CONSOLE';
export const COLLAPSE_CONSOLE = 'COLLAPSE_CONSOLE';

export const UPDATE_LINT_MESSAGE = 'UPDATE_LINT_MESSAGE';
export const CLEAR_LINT_MESSAGE = 'CLEAR_LINT_MESSAGE';
export const TOGGLE_FORCE_DESKTOP = 'TOGGLE_FORCE_DESKTOP';

export const UPDATE_FILE_NAME = 'UPDATE_FILE_NAME';
Expand Down
27 changes: 5 additions & 22 deletions client/modules/IDE/actions/editorAccessibility.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
import * as ActionTypes from '../../../constants';

export function updateLintMessage(severity, line, message) {
return {
type: ActionTypes.UPDATE_LINT_MESSAGE,
severity,
line,
message
};
}

export function clearLintMessage() {
return {
type: ActionTypes.CLEAR_LINT_MESSAGE
};
}

export function toggleForceDesktop() {
return {
type: ActionTypes.TOGGLE_FORCE_DESKTOP
};
}
export {
updateLintMessage,
clearLintMessage,
toggleForceDesktop
} from '../reducers/editorAccessibility';
46 changes: 27 additions & 19 deletions client/modules/IDE/reducers/editorAccessibility.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import * as ActionTypes from '../../../constants';
import { createSlice } from '@reduxjs/toolkit';

const initialState = {
lintMessages: [],
forceDesktop: false
};

let messageId = 0;

const editorAccessibility = (state = initialState, action) => {
switch (action.type) {
case ActionTypes.UPDATE_LINT_MESSAGE:
const editorAccessibilitySlice = createSlice({
name: 'editorAccessibility',
initialState,
reducers: {
updateLintMessage: (state, action) => {
messageId += 1;
return Object.assign({}, state, {
lintMessages: state.lintMessages.concat({
severity: action.severity,
line: action.line,
message: action.message,
id: messageId
})
state.lintMessages.push({
severity: action.payload.severity,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got the mutations right here 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lindapaiste Thanks for the feedback, these are really helpful :)

line: action.payload.line,
message: action.payload.message,
id: messageId
});
case ActionTypes.CLEAR_LINT_MESSAGE:
return Object.assign({}, state, { lintMessages: [] });
case ActionTypes.TOGGLE_FORCE_DESKTOP:
return Object.assign({}, state, { forceDesktop: !state.forceDesktop });
default:
return state;
},
clearLintMessage: (state) => {
state.lintMessages = [];
},
toggleForceDesktop: (state) => {
state.forceDesktop = !state.forceDesktop;
}
}
};
});

export const {
updateLintMessage,
clearLintMessage,
toggleForceDesktop
} = editorAccessibilitySlice.actions;

export default editorAccessibility;
export default editorAccessibilitySlice.reducer;
Loading