Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor / import cbuilder board #1764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading