From 3cc3570529d8cd283c987c459d4159ae655140b3 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 7 Dec 2023 23:20:19 -0300 Subject: [PATCH 1/3] Update the load board of a new folder when parentBoard is created on API --- src/components/Board/Board.actions.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 From 2057a71b019974b3be116226a36faa58fc5b1c37 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 7 Dec 2023 23:22:38 -0300 Subject: [PATCH 2/3] Add comments to improve the understanding of the logic of the code --- src/components/Board/Board.container.js | 7 ++++++- src/components/Board/Board.reducer.js | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index ebee0820f..b437a59f4 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,10 @@ export class BoardContainer extends Component { ) .then(parentBoardId => { if (createParentBoard) { + console.log('parent board created', parentBoardData); + /* 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; } From 5d07d1d601f298aee1c0a1de237bbb33e38a6a27 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 7 Dec 2023 23:23:44 -0300 Subject: [PATCH 3/3] Remove console log --- src/components/Board/Board.container.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index b437a59f4..14afd000e 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -1167,7 +1167,6 @@ export class BoardContainer extends Component { ) .then(parentBoardId => { if (createParentBoard) { - console.log('parent board created', parentBoardData); /* 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 */