From db694a39b0e5ba2a6ad25ac9aaccdf9ca0e12d4a Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 25 Jul 2024 14:40:24 -0300 Subject: [PATCH 1/5] Fix loading state in BoardContainer's handleCopyRemoteBoard method --- src/components/Board/Board.container.js | 29 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 1ed954ec0..67e50e39c 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -70,6 +70,7 @@ import { IS_BROWSING_FROM_APPLE_TOUCH, IS_BROWSING_FROM_SAFARI } from '../../constants'; +import LoadingIcon from '../UI/LoadingIcon'; //import { isAndroid } from '../../cordova-util'; const ogv = require('ogv'); @@ -1183,6 +1184,9 @@ export class BoardContainer extends Component { handleCopyRemoteBoard = async () => { const { intl, showNotification, history, switchBoard } = this.props; try { + this.setState({ + isSaving: true + }); const copiedBoard = await this.createBoardsRecursively( this.state.copyPublicBoard ); @@ -1194,7 +1198,6 @@ export class BoardContainer extends Component { const translatedBoard = this.translateBoard(copiedBoard); this.setState({ translatedBoard, - isSaving: false, copyPublicBoard: false, blockedPrivateBoard: false }); @@ -1203,6 +1206,9 @@ export class BoardContainer extends Component { console.log(err.message); showNotification(intl.formatMessage(messages.boardCopyError)); } + this.setState({ + isSaving: false + }); }; async createBoardsRecursively(board, records) { @@ -1264,10 +1270,6 @@ export class BoardContainer extends Component { // Loggedin user? if ('name' in userData && 'email' in userData) { - this.setState({ - isSaving: true - }); - try { const boardId = await updateApiObjectsNoChild(newBoard, true); newBoard = { @@ -1348,7 +1350,9 @@ export class BoardContainer extends Component { }); } - handleCloseDialog = () => { + handleCloseDialog = (event, reason) => { + const { isSaving } = this.state; + if (isSaving) return; this.setState({ copyPublicBoard: false, blockedPrivateBoard: false @@ -1611,7 +1615,11 @@ export class BoardContainer extends Component { - @@ -1619,8 +1627,13 @@ export class BoardContainer extends Component { onClick={this.handleCopyRemoteBoard} color="primary" variant="contained" + disabled={this.state.isSaving} > - {this.props.intl.formatMessage(messages.boardCopyAccept)} + {this.state.isSaving ? ( + + ) : ( + this.props.intl.formatMessage(messages.boardCopyAccept) + )} From c652386ecf0cc77f280950b2c972a1f6c3884ff5 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 25 Jul 2024 15:40:21 -0300 Subject: [PATCH 2/5] Remove set loading on createBoardsRecursively on CommunicatorDialog container --- .../CommunicatorDialog/CommunicatorDialog.container.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js index 3891f1ae2..bfe946ded 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -293,9 +293,6 @@ class CommunicatorDialogContainer extends React.Component { // Loggedin user? if ('name' in userData && 'email' in userData) { try { - this.setState({ - loading: true - }); const boardId = await updateApiObjectsNoChild(newBoard, true); newBoard = { ...newBoard, @@ -303,10 +300,6 @@ class CommunicatorDialogContainer extends React.Component { }; } catch (err) { console.log(err.message); - } finally { - this.setState({ - loading: false - }); } } From ddf4120409ca5af5632d174b2f731ceea6d30d19 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 25 Jul 2024 20:57:39 +0200 Subject: [PATCH 3/5] Improve error mananger --- src/components/Board/Board.container.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 67e50e39c..ada9adc83 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -1205,6 +1205,7 @@ export class BoardContainer extends Component { } catch (err) { console.log(err.message); showNotification(intl.formatMessage(messages.boardCopyError)); + this.handleCloseDialog(); } this.setState({ isSaving: false @@ -1292,7 +1293,7 @@ export class BoardContainer extends Component { const nextBoard = await API.getBoard(tile.loadBoard); await this.createBoardsRecursively(nextBoard, records); } catch (err) { - if (err.response.status === 404) { + if (!err.respose || err.response?.status === 404) { //look for this board in available boards const localBoard = boards.find(b => b.id === tile.loadBoard); if (localBoard) { From 084181ae9687adaec4ffb33ac7358846c39eb300 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 25 Jul 2024 16:03:51 -0300 Subject: [PATCH 4/5] Show loading state on Dialog accept button and avoid close it on saving --- .../CommunicatorDialogBoardItem.component.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialogBoardItem.component.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialogBoardItem.component.js index 43b5f6df3..d6642dbe2 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialogBoardItem.component.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialogBoardItem.component.js @@ -30,6 +30,7 @@ import TextField from '@material-ui/core/TextField'; import CircularProgress from '@material-ui/core/CircularProgress'; import Slide from '@material-ui/core/Slide'; import DialogContentText from '@material-ui/core/DialogContentText'; +import LoadingIcon from '../../UI/LoadingIcon'; import IconButton from '../../UI/IconButton'; import { TAB_INDEXES } from './CommunicatorDialog.constants'; @@ -73,6 +74,8 @@ class CommunicatorDialogBoardItem extends React.Component { ? props.board.description : '' }; + + this.handleDialogClose = this.handleDialogClose.bind(this); } openMenu(e) { @@ -149,7 +152,6 @@ class CommunicatorDialogBoardItem extends React.Component { async handleBoardCopy(board) { this.setState({ - openCopyBoard: false, loading: true }); try { @@ -157,6 +159,7 @@ class CommunicatorDialogBoardItem extends React.Component { } catch (err) { } finally { this.setState({ + openCopyBoard: false, loading: false }); } @@ -839,7 +842,9 @@ class CommunicatorDialogBoardItem extends React.Component { { + if (!this.state.loading) this.handleDialogClose(); + }} aria-labelledby="board-copy-dialog" open={this.state.openCopyBoard} > @@ -858,6 +863,7 @@ class CommunicatorDialogBoardItem extends React.Component { @@ -868,8 +874,13 @@ class CommunicatorDialogBoardItem extends React.Component { }} variant="contained" color="primary" + disabled={this.state.loading} > - {intl.formatMessage(messages.accept)} + {this.state.loading ? ( + + ) : ( + intl.formatMessage(messages.accept) + )} From f46aee982bf4ea0d3c9c6c688301be07c5dabedf Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 25 Jul 2024 16:07:24 -0300 Subject: [PATCH 5/5] Improve error manager --- .../CommunicatorDialog/CommunicatorDialog.container.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js index bfe946ded..0f1551fb6 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -314,7 +314,7 @@ class CommunicatorDialogContainer extends React.Component { const nextBoard = await API.getBoard(tile.loadBoard); await this.createBoardsRecursively(nextBoard, records); } catch (err) { - if (err.response.status === 404) { + if (!err.respose || err.response?.status === 404) { //look for this board in available boards const localBoard = availableBoards.find( b => b.id === tile.loadBoard