From 3794cbdb2c6ea891dd4e37a4135cb459bbc4f2ae Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 22 Jul 2024 21:42:41 -0300 Subject: [PATCH 1/4] Add try catch block to remoteIdChecker --- src/components/Board/Board.container.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 62a6aad54..90c7f5fa7 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -277,8 +277,10 @@ export class BoardContainer extends Component { const homeBoard = communicator.rootBoard; boardExists = boards.find(b => b.id === homeBoard); if (!boardExists) { - if (isRemoteIdChecker(homeBoard)) - boardExists = this.tryRemoteBoard(homeBoard); + try { + if (isRemoteIdChecker(homeBoard)) + boardExists = await this.tryRemoteBoard(homeBoard); + } catch (err) {} if (!boardExists) boardExists = this.addDefaultBoardIfnecessary(homeBoard); if (!boardExists) boardExists = boards.find(b => b.id !== ''); From 43da260550d5e4d4c3fe053a575dda5b2fec552e Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 22 Jul 2024 21:43:54 -0300 Subject: [PATCH 2/4] Get defaultBoardBlackList from active communicator --- .../Communicator/Communicator.actions.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index aa817b10e..a16d899f2 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -249,12 +249,14 @@ export function getApiMyCommunicators() { } catch (e) { console.error(e); } - const activeCommunicator = - res.data.find( - communicator => - communicator.id === getState().communicator.activeCommunicator - ) ?? res.data[res.data.length - 1]; - const defaultBoardBlackList = activeCommunicator?.defaultBoardBlackList; + const getActiveCommunicator = getState => { + return getState().communicator.communicators.find( + c => c.id === getState().communicator.activeCommunicatorId + ); + }; + const activeCommunicator = getActiveCommunicator(getState); + const defaultBoardBlackList = + activeCommunicator?.defaultBoardBlackList ?? []; dispatch( removeBoardsFromList( defaultBoardBlackList, From 489c51003b4761a2b0fa4a208bc7578b41fe17a8 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 22 Jul 2024 23:18:37 -0300 Subject: [PATCH 3/4] Avoid creating duplicated default boards on the db --- src/components/Board/Board.reducer.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index 713f39ce4..659c31196 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -319,6 +319,8 @@ function boardReducer(state = initialState, action) { }; case CREATE_API_BOARD_SUCCESS: const creadBoards = [...state.boards]; + const tilesToUpdateIds = []; + const boardsToMarkForCreation = []; for (let i = 0; i < creadBoards.length; i++) { let tiles = creadBoards[i].tiles; if (tiles) { @@ -330,17 +332,27 @@ function boardReducer(state = initialState, action) { creadBoards[i].hasOwnProperty('email') ) { creadBoards[i].markToUpdate = true; + const tileUpdatedId = creadBoards[i].tiles[j].id; + tilesToUpdateIds.push(tileUpdatedId); } const shouldCreateBoard = creadBoards[i].id.length < SHORT_ID_MAX_LENGTH; if (shouldCreateBoard) { - creadBoards[i].shouldCreateBoard = true; + boardsToMarkForCreation.push(creadBoards[i]); } } } } } + boardsToMarkForCreation.forEach(board => { + //if the tile id is already in a api board, we don't need to create it + const boardTileIds = board.tiles.map(tile => tile.id); + const boardIsAlreadyCreatedOnDb = boardTileIds.some(tileId => + tilesToUpdateIds.includes(tileId) + ); + if (!boardIsAlreadyCreatedOnDb) board.shouldCreateBoard = true; + }); return { ...state, isFetching: false, From 59ae755eb37dfd063f359ceed2a161792ea65f7e Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 23 Jul 2024 12:39:57 -0300 Subject: [PATCH 4/4] Revert "Get defaultBoardBlackList from active communicator" This reverts commit 43da260550d5e4d4c3fe053a575dda5b2fec552e. --- .../Communicator/Communicator.actions.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index a16d899f2..aa817b10e 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -249,14 +249,12 @@ export function getApiMyCommunicators() { } catch (e) { console.error(e); } - const getActiveCommunicator = getState => { - return getState().communicator.communicators.find( - c => c.id === getState().communicator.activeCommunicatorId - ); - }; - const activeCommunicator = getActiveCommunicator(getState); - const defaultBoardBlackList = - activeCommunicator?.defaultBoardBlackList ?? []; + const activeCommunicator = + res.data.find( + communicator => + communicator.id === getState().communicator.activeCommunicator + ) ?? res.data[res.data.length - 1]; + const defaultBoardBlackList = activeCommunicator?.defaultBoardBlackList; dispatch( removeBoardsFromList( defaultBoardBlackList,