Skip to content

Commit

Permalink
Merge pull request #1743 from RodriSanchez1/fixes
Browse files Browse the repository at this point in the history
Fix / Create neccesary default boards on DB
  • Loading branch information
RodriSanchez1 authored Jul 23, 2024
2 parents c85429f + 59ae755 commit 3bbb425
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/components/Board/Board.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 !== '');
Expand Down
14 changes: 13 additions & 1 deletion src/components/Board/Board.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit 3bbb425

Please sign in to comment.