Skip to content

Commit

Permalink
Merge pull request #1748 from RodriSanchez1/fix/DeepCopyForBoardIniti…
Browse files Browse the repository at this point in the history
…alState

Fix / DeepCopy For Board Initial State
  • Loading branch information
RodriSanchez1 authored Jul 24, 2024
2 parents cfc9c27 + a3e6dcc commit 5ad5fcc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
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

0 comments on commit 5ad5fcc

Please sign in to comment.