Skip to content

Commit

Permalink
Merge pull request #1717 from RodriSanchez1/fix/copyPublicBoards
Browse files Browse the repository at this point in the history
Fix / Copy public boards
  • Loading branch information
tomivm authored Jun 28, 2024
2 parents cd351ad + a92bf9a commit ebb62a9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
57 changes: 31 additions & 26 deletions src/components/Board/Board.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,9 +1182,23 @@ export class BoardContainer extends Component {
}

handleCopyRemoteBoard = async () => {
const { intl, showNotification } = this.props;
const { intl, showNotification, history, switchBoard } = this.props;
try {
await this.createBoardsRecursively(this.state.copyPublicBoard);
const copiedBoard = await this.createBoardsRecursively(
this.state.copyPublicBoard
);
if (!copiedBoard?.id) {
throw new Error('Board not copied correctly');
}
switchBoard(copiedBoard.id);
history.replace(`/board/${copiedBoard.id}`, []);
const translatedBoard = this.translateBoard(copiedBoard);
this.setState({
translatedBoard,
isSaving: false,
copyPublicBoard: false,
blockedPrivateBoard: false
});
showNotification(intl.formatMessage(messages.boardCopiedSuccessfully));
} catch (err) {
console.log(err.message);
Expand All @@ -1195,9 +1209,7 @@ export class BoardContainer extends Component {
async createBoardsRecursively(board, records) {
const {
createBoard,
switchBoard,
addBoardCommunicator,
history,
communicator,
userData,
updateApiObjectsNoChild,
Expand All @@ -1208,13 +1220,13 @@ export class BoardContainer extends Component {

//prevent shit
if (!board) {
return;
return null;
}
if (records) {
//get the list of next boards in records
let nextBoardsRecords = records.map(entry => entry.next);
if (nextBoardsRecords.includes(board.id)) {
return;
return null;
}
}

Expand Down Expand Up @@ -1244,6 +1256,13 @@ export class BoardContainer extends Component {
addBoardCommunicator(newBoard.id);
}

if (!records) {
records = [{ prev: board.id, next: newBoard.id }];
} else {
records.push({ prev: board.id, next: newBoard.id });
}
this.updateBoardReferences(board, newBoard, records);

// Loggedin user?
if ('name' in userData && 'email' in userData) {
this.setState({
Expand All @@ -1260,43 +1279,29 @@ export class BoardContainer extends Component {
console.log(err.message);
}
}
if (!records) {
records = [{ prev: board.id, next: newBoard.id }];
switchBoard(newBoard.id);
history.replace(`/board/${newBoard.id}`, []);
const translatedBoard = this.translateBoard(newBoard);
this.setState({
translatedBoard,
isSaving: false,
copyPublicBoard: false,
blockedPrivateBoard: false
});
} else {
records.push({ prev: board.id, next: newBoard.id });
}
this.updateBoardReferences(board, newBoard, records);

if (board.tiles.length < 1) {
return;
return newBoard;
}

//return condition
board.tiles.forEach(async tile => {
for (const tile of board.tiles) {
if (tile.loadBoard && !tile.linkedBoard) {
try {
const nextBoard = await API.getBoard(tile.loadBoard);
this.createBoardsRecursively(nextBoard, records);
await this.createBoardsRecursively(nextBoard, records);
} catch (err) {
if (err.response.status === 404) {
//look for this board in available boards
const localBoard = boards.find(b => b.id === tile.loadBoard);
if (localBoard) {
this.createBoardsRecursively(localBoard, records);
await this.createBoardsRecursively(localBoard, records);
}
}
}
}
});
}
return newBoard;
}

updateBoardReferences(board, newBoard, records) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ class CommunicatorDialogContainer extends React.Component {
addBoardCommunicator(newBoard.id);
}

if (!records) {
records = [{ prev: board.id, next: newBoard.id }];
} else {
records.push({ prev: board.id, next: newBoard.id });
}
this.updateBoardReferences(board, newBoard, records);

// Loggedin user?
if ('name' in userData && 'email' in userData) {
try {
Expand All @@ -302,36 +309,30 @@ class CommunicatorDialogContainer extends React.Component {
});
}
}
if (!records) {
records = [{ prev: board.id, next: newBoard.id }];
} else {
records.push({ prev: board.id, next: newBoard.id });
}
this.updateBoardReferences(board, newBoard, records);

if (board.tiles.length < 1) {
return;
}

//return condition
board.tiles.forEach(async tile => {
for (const tile of board.tiles) {
if (tile.loadBoard && !tile.linkedBoard) {
try {
const nextBoard = await API.getBoard(tile.loadBoard);
this.createBoardsRecursively(nextBoard, records);
await this.createBoardsRecursively(nextBoard, records);
} catch (err) {
if (err.response.status === 404) {
//look for this board in available boards
const localBoard = availableBoards.find(
b => b.id === tile.loadBoard
);
if (localBoard) {
this.createBoardsRecursively(localBoard, records);
await this.createBoardsRecursively(localBoard, records);
}
}
}
}
});
}
}

updateBoardReferences(board, newBoard, records) {
Expand Down

0 comments on commit ebb62a9

Please sign in to comment.