diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index cee628515..2602b092b 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -758,8 +758,20 @@ export function updateApiObjects( .then(res => { const updatedChildBoardId = res.id; //create - update parent board + const updateTilesParentBoard = () => + parentBoard.tiles.map(tile => { + if (tile.loadBoard === childBoard.id) + return { ...tile, loadBoard: updatedChildBoardId }; + return tile; + }); + const updatedParentBoard = { + ...parentBoard, + tiles: createParentBoard + ? updateTilesParentBoard() + : parentBoard.tiles + }; const action = createParentBoard ? createApiBoard : updateApiBoard; - return dispatch(action(parentBoard, parentBoard.id)) + return dispatch(action(updatedParentBoard, parentBoard.id)) .then(res => { const updatedParentBoardId = res.id; //add new boards to the active communicator diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index ebee0820f..14afd000e 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -644,7 +644,7 @@ export class BoardContainer extends Component { // Loggedin user? if ('name' in userData && 'email' in userData) { - await this.handleApiUpdates(tile); + await this.handleApiUpdates(tile); // this function could mutate tthe tile return; } @@ -1125,6 +1125,7 @@ export class BoardContainer extends Component { //update the parent updateBoard(parentBoardData); } + // Untill here all is with shorts ids //api updates if (tile && tile.type === 'board') { //child becomes parent @@ -1166,6 +1167,9 @@ export class BoardContainer extends Component { ) .then(parentBoardId => { if (createParentBoard) { + /* Here the parentBoardData is not updated with the values + that updatedApiObjects store on the API. Inside the boards are already updated + an the value is not replaced because the oldboard Id was replaced on the updateApiObjects inside createApiBoardSuccess */ replaceBoard( { ...parentBoardData }, { ...parentBoardData, id: parentBoardId } diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index 03b5fd327..b7db1bd49 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -71,6 +71,8 @@ function tileReducer(board, action) { return { ...board, tiles: [...board.tiles, { ...action.tile }] + /* some times when a tile folder is created here the last tile change loadBoard to a long Id with no reason + action tile before this copy has a short ID*/ }; case DELETE_TILES: return { @@ -165,6 +167,8 @@ function boardReducer(state = initialState, action) { if (prev.id !== current.id) { const boardIndex = boards.findIndex(b => b.id === prev.id); + /* On create a parent board the prev board doesn't exist with a short Id + because is already replaced by a long one */ if (boardIndex >= 0) { boards[boardIndex] = current; }