Skip to content
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

Fix / DeepCopy For Board Initial State #1748

Merged
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
12 changes: 8 additions & 4 deletions src/components/Board/Board.reducer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moment from 'moment';

import { DEFAULT_BOARDS } from '../../helpers';
import { DEFAULT_BOARDS, deepCopy } from '../../helpers';

import {
IMPORT_BOARDS,
Expand Down Expand Up @@ -42,9 +42,13 @@ import {
} from './Board.constants';
import { LOGOUT, LOGIN_SUCCESS } from '../Account/Login/Login.constants';

const [...boards] = [...DEFAULT_BOARDS.advanced, ...DEFAULT_BOARDS.picSeePal];
const initialBoardsState = [
...DEFAULT_BOARDS.advanced,
...DEFAULT_BOARDS.picSeePal
];

const initialState = {
boards,
boards: deepCopy(initialBoardsState),
output: [],
activeBoardId: null,
navHistory: [],
Expand Down Expand Up @@ -116,7 +120,7 @@ function boardReducer(state = initialState, action) {
};

case LOGOUT:
return initialState;
return { ...initialState, boards: deepCopy(initialBoardsState) };

case IMPORT_BOARDS:
return {
Expand Down
8 changes: 6 additions & 2 deletions src/components/Communicator/Communicator.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import {
} from './Communicator.constants';
import { LOGIN_SUCCESS, LOGOUT } from '../Account/Login/Login.constants';
import moment from 'moment';
import { deepCopy } from '../../helpers';

export const defaultCommunicatorID = 'cboard_default';
const initialState = {
communicators: defaultCommunicators,
communicators: deepCopy(defaultCommunicators),
activeCommunicatorId: defaultCommunicatorID
};

Expand All @@ -48,7 +49,10 @@ function communicatorReducer(state = initialState, action) {
};

case LOGOUT:
return initialState;
return {
...initialState,
communicators: deepCopy(defaultCommunicators)
};

case IMPORT_COMMUNICATOR:
return {
Expand Down
2 changes: 2 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const DEFAULT_BOARDS = {
picSeePal: picSeePal
};

export const deepCopy = obj => JSON.parse(JSON.stringify(obj));

export const dataURLtoFile = (dataurl, filename, checkExtension = false) => {
// https://stackoverflow.com/a/38936042
const arr = dataurl.split(',');
Expand Down
Loading