Skip to content

Commit

Permalink
Merge pull request #1764 from RodriSanchez1/feature/ImportCbuilderBoard
Browse files Browse the repository at this point in the history
Refactor / import cbuilder board
  • Loading branch information
RodriSanchez1 authored Sep 3, 2024
2 parents 7a62a8d + fa2f028 commit ab4e49d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
15 changes: 13 additions & 2 deletions src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,19 @@ class API {
return data;
}

async getTemporaryBoard(id) {
const { data } = await this.axiosInstance.get(`/board/temporary/${id}`);
async getCbuilderBoard(id) {
const authToken = getAuthToken();
if (!(authToken && authToken.length)) {
throw new Error('Need to be authenticated to perform this request', {
cause: 401
});
}
const headers = {
Authorization: `Bearer ${authToken}`
};
const { data } = await this.axiosInstance.get(`/board/cbuilder/${id}`, {
headers
});
return data;
}

Expand Down
53 changes: 31 additions & 22 deletions src/components/Board/Board.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,33 +382,42 @@ export class BoardContainer extends Component {

const queryParams = new URLSearchParams(location.search);
const isCbuilderBoard = queryParams.get('cbuilder');

const remoteBoard = isCbuilderBoard
? await API.getTemporaryBoard(boardId)
: await API.getBoard(boardId);

this.setState({ isCbuilderBoard });
//if requested board is from the user just add it
if (
'name' in userData &&
'email' in userData &&
remoteBoard.email === userData.email &&
remoteBoard.author === userData.name
) {
if (isCbuilderBoard) {
this.setState({ copyPublicBoard: remoteBoard });

try {
const remoteBoard = isCbuilderBoard
? await API.getCbuilderBoard(boardId)
: await API.getBoard(boardId);

//if requested board is from the user just add it
if (
'name' in userData &&
'email' in userData &&
remoteBoard.email === userData.email &&
remoteBoard.author === userData.name
) {
if (isCbuilderBoard) {
this.setState({ copyPublicBoard: remoteBoard });
return null;
}
return remoteBoard;
} else {
//if requested board is public, ask about copy it
if (remoteBoard.isPublic) {
this.setState({ copyPublicBoard: remoteBoard });
} else {
this.setState({ blockedPrivateBoard: true });
}
return null;
}
return remoteBoard;
} else {
//if requested board is public, ask about copy it
if (remoteBoard.isPublic) {
this.setState({ copyPublicBoard: remoteBoard });
} else {
} catch (err) {
if (
isCbuilderBoard &&
(err?.response?.status === 401 || err?.cause === 401)
)
this.setState({ blockedPrivateBoard: true });
}
throw new Error('Cannot get the remote board');
}
return null;
}

translateBoard(board) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Board/Board.messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,6 @@ export default defineMessages({
loginToImport: {
id: 'cboard.components.Board.loginToImport',
defaultMessage:
'In order to import a CBuilder board you have to be logged in.'
'To import a CBuilder board, you must be logged in with the same account that was used to create the board.'
}
});
2 changes: 1 addition & 1 deletion src/translations/src/cboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
"cboard.components.Board.writeAndSay": "Write and say",
"cboard.components.Board.importCbuilderBoardTitle": "Import CBuilder Board",
"cboard.components.Board.importCbuilderBoardDesc": "You are trying to import a CBuilder board. In order to use and edit this board you have to copy it into your communicator boards.",
"cboard.components.Board.loginToImport": "In order to import a CBuilder board you have to be logged in.",
"cboard.components.Board.loginToImport": "To import a CBuilder board, you must be logged in with the same account that was used to create the board.",
"cboard.components.Board.ImageEditor.title": "Image editor",
"cboard.components.Board.ImageEditor.rotateRight": "Rotate right",
"cboard.components.Board.ImageEditor.cropImage": "Crop image",
Expand Down

0 comments on commit ab4e49d

Please sign in to comment.