From 3e9e7b2732f0d4a8855ec9c8ceb77dd83c62fb66 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 23 May 2024 08:56:49 -0300 Subject: [PATCH 01/85] Use updateApiObjectsNoChild recursively to create board if local change --- src/components/Board/Board.actions.js | 29 ++++++++++++++++++++++++- src/components/Board/Board.constants.js | 3 +++ src/components/Board/Board.reducer.js | 19 +++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 2602b092b..910a05682 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -38,7 +38,9 @@ import { DOWNLOAD_IMAGES_FAILURE, DOWNLOAD_IMAGES_STARTED, DOWNLOAD_IMAGE_SUCCESS, - DOWNLOAD_IMAGE_FAILURE + DOWNLOAD_IMAGE_FAILURE, + UNMARK_SHOULD_CREATE_API_BOARD, + REMOTE_BOARD_ID_LENGTH } from './Board.constants'; import API from '../../api'; @@ -741,11 +743,36 @@ export function updateApiMarkedBoards() { throw new Error(e.message); }); } + if ( + allBoards[i].id.length < REMOTE_BOARD_ID_LENGTH && + allBoards[i].shouldCreateBoard + ) { + const state = getState(); + + let boardData = { + ...allBoards[i], + author: state.app.userData.name, + email: state.app.userData.email, + hidden: false, + locale: state.lang + }; + delete boardData.shouldCreateBoard; + + dispatch(updateApiObjectsNoChild(boardData, false, true)); + dispatch(unmarkShouldCreateBoard(allBoards[i].id)); + } } return; }; } +function unmarkShouldCreateBoard(boardId) { + return { + type: UNMARK_SHOULD_CREATE_API_BOARD, + boardId + }; +} + export function updateApiObjects( childBoard, parentBoard, diff --git a/src/components/Board/Board.constants.js b/src/components/Board/Board.constants.js index 7d820d648..0dcc20cad 100644 --- a/src/components/Board/Board.constants.js +++ b/src/components/Board/Board.constants.js @@ -19,6 +19,8 @@ export const CHANGE_IMPROVED_PHRASE = 'cboard/Board/CHANGE_IMPROVED_PHRASE'; export const CHANGE_LIVE_MODE = 'cboard/Board/CHANGE_LIVE_MODE'; export const HISTORY_REMOVE_BOARD = 'cboard/Board/HISTORY_REMOVE_BOARD'; export const UNMARK_BOARD = 'cboard/Board/UNMARK_BOARD'; +export const UNMARK_SHOULD_CREATE_API_BOARD = + 'cboard/Board/UNMARK_SHOULD_CREATE_API_BOARD'; export const CREATE_API_BOARD_SUCCESS = 'cboard/Board/CREATE_API_BOARD_SUCCESS'; export const CREATE_API_BOARD_FAILURE = 'cboard/Board/CREATE_API_BOARD_FAILURE'; export const CREATE_API_BOARD_STARTED = 'cboard/Board/CREATE_API_BOARD_STARTED'; @@ -41,3 +43,4 @@ export const DOWNLOAD_IMAGE_SUCCESS = 'cboard/Board/DOWNLOAD_IMAGE_SUCCESS'; export const DOWNLOAD_IMAGE_FAILURE = 'cboard/Board/DOWNLOAD_IMAGE_FAILURE'; export const DEFAULT_ROWS_NUMBER = 5; export const DEFAULT_COLUMNS_NUMBER = 5; +export const REMOTE_BOARD_ID_LENGTH = 14; diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index b7db1bd49..ceaf7ab86 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -36,7 +36,9 @@ import { GET_API_MY_BOARDS_STARTED, DOWNLOAD_IMAGES_STARTED, DOWNLOAD_IMAGE_SUCCESS, - DOWNLOAD_IMAGE_FAILURE + DOWNLOAD_IMAGE_FAILURE, + UNMARK_SHOULD_CREATE_API_BOARD, + REMOTE_BOARD_ID_LENGTH } from './Board.constants'; import { LOGOUT, LOGIN_SUCCESS } from '../Account/Login/Login.constants'; @@ -289,6 +291,15 @@ function boardReducer(state = initialState, action) { : { ...board, markToUpdate: false } ) }; + case UNMARK_SHOULD_CREATE_API_BOARD: + return { + ...state, + boards: state.boards.map(board => + board.id !== action.boardId + ? board + : { ...board, shouldCreateBoard: false } + ) + }; case CHANGE_OUTPUT: return { ...state, @@ -313,6 +324,12 @@ function boardReducer(state = initialState, action) { ) { creadBoards[i].markToUpdate = true; } + + const shouldCreateBoard = + creadBoards[i].id.length < REMOTE_BOARD_ID_LENGTH; + if (shouldCreateBoard) { + creadBoards[i].shouldCreateBoard = true; + } } } } From 615f9c741ce39b1035b4574eba8b7e47300c04fe Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 23 May 2024 09:50:25 -0300 Subject: [PATCH 02/85] Replace old board id with the new one on the Navigation History --- src/components/Board/Board.actions.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 910a05682..bc08e2b92 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -758,7 +758,18 @@ export function updateApiMarkedBoards() { }; delete boardData.shouldCreateBoard; - dispatch(updateApiObjectsNoChild(boardData, false, true)); + dispatch(updateApiObjectsNoChild(boardData, false, true)) + .then(boardId => { + if (createBoard) { + dispatch( + replaceBoard({ ...boardData }, { ...boardData, id: boardId }) + ); + } + }) + .catch(err => { + console.log(err.message); + }); + dispatch(unmarkShouldCreateBoard(allBoards[i].id)); } } From 147101e6bf548839a4cf2473e5170a6104269f9b Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 23 May 2024 11:29:52 -0300 Subject: [PATCH 03/85] Extract name from NameKey to create default boards on db Todo - use intl to translateName --- src/components/Board/Board.actions.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index bc08e2b92..4ec619c84 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -749,12 +749,21 @@ export function updateApiMarkedBoards() { ) { const state = getState(); + // TODO - translate name using intl in a redux action + //name: intl.formatMessage({ id: allBoards[i].nameKey }) + const extractName = () => { + const splitedNameKey = allBoards[i].nameKey.split('.'); + const NAMEKEY_LAST_INDEX = splitedNameKey.length - 1; + return splitedNameKey[NAMEKEY_LAST_INDEX]; + }; + const name = allBoards[i].name ?? extractName(); let boardData = { ...allBoards[i], author: state.app.userData.name, email: state.app.userData.email, hidden: false, - locale: state.lang + locale: state.lang, + name }; delete boardData.shouldCreateBoard; From 8fb86b97d8e6bf221bb95d73647f781af9e04b5e Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 27 May 2024 21:17:55 -0300 Subject: [PATCH 04/85] Refactor upserApiCommunicator, return a Promise on action call --- src/components/Communicator/Communicator.actions.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 57e0373bc..c970ff802 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -58,17 +58,20 @@ export function upsertApiCommunicator(communicator) { const SHORT_ID_MAX_LENGTH = 14; // If the communicator is not on the local state return - if (!communicators.find(c => c.id === communicator.id)) return; + if (!communicators.find(c => c.id === communicator.id)) + return Promise.reject({ + message: 'Communicator not found on local state' + }); - communicator.id.length < SHORT_ID_MAX_LENGTH || - communicator.id === defaultCommunicatorID + return communicator.id.length < SHORT_ID_MAX_LENGTH || + communicator.id === defaultCommunicatorID ? dispatch(createApiCommunicator(communicator, communicator.id)).catch( error => { - console.error(error); + throw new Error(error); } ) : dispatch(updateApiCommunicator(communicator)).catch(error => { - console.error(error); + throw new Error(error); }); }; } From 3d557ecc59f8172bf0ecfa50b01b52e5027444dd Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 27 May 2024 21:20:27 -0300 Subject: [PATCH 05/85] Add catch block after upsertApiCommunicator on changeDefaultBoard --- src/components/Board/Board.actions.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index f06d8db12..3d06910d7 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -196,7 +196,9 @@ export function changeDefaultBoard(selectedBoardNameOnJson) { dispatch(editCommunicator(communicatorWithRootBoardReplaced)); if (userData?.role) { - dispatch(upsertApiCommunicator(communicatorWithRootBoardReplaced)); + dispatch( + upsertApiCommunicator(communicatorWithRootBoardReplaced) + ).catch(console.error); } }; From ab1d40fe6d478348027e4dada92c7ea084ab8256 Mon Sep 17 00:00:00 2001 From: tomivm Date: Tue, 28 May 2024 12:07:01 -0300 Subject: [PATCH 06/85] chore: Refactor updateApiObjectsNoChild to await for API calls --- src/components/Board/Board.actions.js | 34 ++++++++++++------------- src/components/Board/Board.container.js | 6 ++++- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 4ec619c84..2e7a62a20 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -503,7 +503,7 @@ export function getApiMyBoards() { } export function createApiBoard(boardData, boardId) { - return dispatch => { + return async dispatch => { dispatch(createApiBoardStarted()); boardData = { ...boardData, @@ -522,7 +522,7 @@ export function createApiBoard(boardData, boardId) { } export function updateApiBoard(boardData) { - return dispatch => { + return async dispatch => { dispatch(updateApiBoardStarted()); return API.updateBoard(boardData) .then(res => { @@ -676,10 +676,10 @@ export function updateApiObjectsNoChild( createCommunicator = false, createParentBoard = false ) { - return (dispatch, getState) => { + return async (dispatch, getState) => { //create - update parent board const action = createParentBoard ? createApiBoard : updateApiBoard; - return dispatch(action(parentBoard, parentBoard.id)) + return await dispatch(action(parentBoard, parentBoard.id)) .then(res => { const updatedParentBoardId = res.id; //add new boards to the active communicator @@ -710,8 +710,8 @@ export function updateApiObjectsNoChild( ? createApiCommunicator : updateApiCommunicator; return dispatch(caction(comm, comm.id)) - .then(() => { - dispatch(updateApiMarkedBoards()); + .then(async () => { + await dispatch(updateApiMarkedBoards()); return updatedParentBoardId; }) .catch(e => { @@ -724,7 +724,7 @@ export function updateApiObjectsNoChild( }; } export function updateApiMarkedBoards() { - return (dispatch, getState) => { + return async (dispatch, getState) => { const allBoards = [...getState().board.boards]; for (let i = 0; i < allBoards.length; i++) { if ( @@ -734,7 +734,7 @@ export function updateApiMarkedBoards() { allBoards[i].hasOwnProperty('markToUpdate') && allBoards[i].markToUpdate ) { - dispatch(updateApiBoard(allBoards[i])) + await dispatch(updateApiBoard(allBoards[i])) .then(() => { dispatch(unmarkBoard(allBoards[i].id)); return; @@ -766,23 +766,23 @@ export function updateApiMarkedBoards() { name }; delete boardData.shouldCreateBoard; + dispatch(unmarkShouldCreateBoard(boardData.id)); - dispatch(updateApiObjectsNoChild(boardData, false, true)) + dispatch(updateBoard(boardData)); + await dispatch(updateApiObjectsNoChild(boardData, false, true)) .then(boardId => { - if (createBoard) { - dispatch( - replaceBoard({ ...boardData }, { ...boardData, id: boardId }) - ); - } + dispatch( + replaceBoard({ ...boardData }, { ...boardData, id: boardId }) + ); + + return; }) .catch(err => { console.log(err.message); + return; }); - - dispatch(unmarkShouldCreateBoard(allBoards[i].id)); } } - return; }; } diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 8a01dcc98..f88e2452c 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -535,7 +535,11 @@ export class BoardContainer extends Component { updateBoard(boardData); } //api updates - updateApiObjectsNoChild(boardData, createCommunicator, createBoard) + await updateApiObjectsNoChild( + boardData, + createCommunicator, + createBoard + ) .then(boardId => { if (createBoard) { replaceBoard({ ...boardData }, { ...boardData, id: boardId }); From d9943f82c3da4bb7e45f9c821588bebfe0b1569e Mon Sep 17 00:00:00 2001 From: tomivm Date: Tue, 28 May 2024 13:10:05 -0300 Subject: [PATCH 07/85] chore: Refactor a for inside updateApiMarkedBoards to await for API calls --- src/components/Board/Board.actions.js | 62 +++++++++++++-------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 2e7a62a20..17f8611bd 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -726,39 +726,37 @@ export function updateApiObjectsNoChild( export function updateApiMarkedBoards() { return async (dispatch, getState) => { const allBoards = [...getState().board.boards]; - for (let i = 0; i < allBoards.length; i++) { + for (const board of allBoards) { + const boardsIds = getState().board.boards?.map(board => board.id); + if (!boardsIds.includes(board.id)) return; + if ( - allBoards[i].id.length > 14 && - allBoards[i].hasOwnProperty('email') && - allBoards[i].email === getState().app.userData.email && - allBoards[i].hasOwnProperty('markToUpdate') && - allBoards[i].markToUpdate + board.id.length > 14 && + board.hasOwnProperty('email') && + board.email === getState().app.userData.email && + board.hasOwnProperty('markToUpdate') && + board.markToUpdate ) { - await dispatch(updateApiBoard(allBoards[i])) - .then(() => { - dispatch(unmarkBoard(allBoards[i].id)); - return; - }) - .catch(e => { - throw new Error(e.message); - }); + try { + await dispatch(updateApiBoard(board)); + dispatch(unmarkBoard(board.id)); + } catch (e) { + throw new Error(e.message); + } } - if ( - allBoards[i].id.length < REMOTE_BOARD_ID_LENGTH && - allBoards[i].shouldCreateBoard - ) { + if (board.id.length < REMOTE_BOARD_ID_LENGTH && board.shouldCreateBoard) { const state = getState(); // TODO - translate name using intl in a redux action //name: intl.formatMessage({ id: allBoards[i].nameKey }) const extractName = () => { - const splitedNameKey = allBoards[i].nameKey.split('.'); + const splitedNameKey = board.nameKey.split('.'); const NAMEKEY_LAST_INDEX = splitedNameKey.length - 1; return splitedNameKey[NAMEKEY_LAST_INDEX]; }; - const name = allBoards[i].name ?? extractName(); + const name = board.name ?? extractName(); let boardData = { - ...allBoards[i], + ...board, author: state.app.userData.name, email: state.app.userData.email, hidden: false, @@ -769,18 +767,16 @@ export function updateApiMarkedBoards() { dispatch(unmarkShouldCreateBoard(boardData.id)); dispatch(updateBoard(boardData)); - await dispatch(updateApiObjectsNoChild(boardData, false, true)) - .then(boardId => { - dispatch( - replaceBoard({ ...boardData }, { ...boardData, id: boardId }) - ); - - return; - }) - .catch(err => { - console.log(err.message); - return; - }); + try { + const boardId = await dispatch( + updateApiObjectsNoChild(boardData, false, true) + ); + dispatch( + replaceBoard({ ...boardData }, { ...boardData, id: boardId }) + ); + } catch (err) { + console.log(err.message); + } } } }; From e2cf08b34712eed256bcbe9696c24bce38c44f45 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 31 May 2024 15:26:19 -0300 Subject: [PATCH 08/85] Use upsertApiCommunicator --- src/components/Board/Board.actions.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 3d06910d7..c70d7ac25 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -724,10 +724,7 @@ export function updateApiObjectsNoChild( comm.activeBoardId = updatedParentBoardId; dispatch(upsertCommunicator(comm)); } - const caction = createCommunicator - ? createApiCommunicator - : updateApiCommunicator; - return dispatch(caction(comm, comm.id)) + return dispatch(upsertApiCommunicator(comm)) .then(() => { dispatch(updateApiMarkedBoards()); return updatedParentBoardId; @@ -821,10 +818,7 @@ export function updateApiObjects( comm.activeBoardId = updatedParentBoardId; dispatch(upsertCommunicator(comm)); } - const caction = createCommunicator - ? createApiCommunicator - : updateApiCommunicator; - return dispatch(caction(comm, comm.id)) + return dispatch(upsertApiCommunicator(comm)) .then(() => { dispatch(updateApiMarkedBoards()); return updatedParentBoardId; From a2ab358765c0b188eda6171420d5534fdec40aa4 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 3 Jun 2024 11:19:22 -0300 Subject: [PATCH 09/85] Refactor for loop in updateApiMarkedBoards to use async/await --- src/components/Board/Board.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 712fbee39..385da6f11 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -744,7 +744,7 @@ export function updateApiObjectsNoChild( export function updateApiMarkedBoards() { return async (dispatch, getState) => { const allBoards = [...getState().board.boards]; - for (const board of allBoards) { + for await (const board of allBoards) { const boardsIds = getState().board.boards?.map(board => board.id); if (!boardsIds.includes(board.id)) return; From 9db7c8059aed7cf6461e51cda9d427707110b313 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 3 Jun 2024 11:27:43 -0300 Subject: [PATCH 10/85] Refactor updateApiObjectsNoChild to use async/await for API calls --- src/components/Board/Board.container.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index f88e2452c..5b6162ffa 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -535,20 +535,15 @@ export class BoardContainer extends Component { updateBoard(boardData); } //api updates - await updateApiObjectsNoChild( + const boardId = await updateApiObjectsNoChild( boardData, createCommunicator, createBoard - ) - .then(boardId => { - if (createBoard) { - replaceBoard({ ...boardData }, { ...boardData, id: boardId }); - } - this.props.history.replace(`/board/${boardId}`); - }) - .catch(err => { - console.log(err.message); - }); + ); + if (createBoard) { + replaceBoard({ ...boardData }, { ...boardData, id: boardId }); + } + this.props.history.replace(`/board/${boardId}`); } catch (err) { console.log(err.message); } finally { From 2998cb007663b45281b394c7730571b409edf2c3 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 6 Jun 2024 23:11:00 -0300 Subject: [PATCH 11/85] Remove unused createCommunicator flag varables --- src/components/Board/Board.actions.js | 4 --- src/components/Board/Board.container.js | 29 ++++--------------- .../CommunicatorDialog.container.js | 8 +---- 3 files changed, 6 insertions(+), 35 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index c70d7ac25..797963d0c 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -44,8 +44,6 @@ import { import API from '../../api'; import { - updateApiCommunicator, - createApiCommunicator, replaceBoardCommunicator, upsertCommunicator, getApiMyCommunicators, @@ -691,7 +689,6 @@ function getFileNameFromUrl(url) { export function updateApiObjectsNoChild( parentBoard, - createCommunicator = false, createParentBoard = false ) { return (dispatch, getState) => { @@ -766,7 +763,6 @@ export function updateApiMarkedBoards() { export function updateApiObjects( childBoard, parentBoard, - createCommunicator = false, createParentBoard = false ) { return (dispatch, getState) => { diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 8a01dcc98..97634d34e 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -493,7 +493,6 @@ export class BoardContainer extends Component { lang } = this.props; - var createCommunicator = false; var createBoard = false; // Loggedin user? if ('name' in userData && 'email' in userData) { @@ -521,7 +520,6 @@ export class BoardContainer extends Component { }; upsertCommunicator(communicatorData); changeCommunicator(communicatorData.id); - createCommunicator = true; } //check if we have to create a copy of the board if (boardData.id.length < 14) { @@ -535,7 +533,7 @@ export class BoardContainer extends Component { updateBoard(boardData); } //api updates - updateApiObjectsNoChild(boardData, createCommunicator, createBoard) + updateApiObjectsNoChild(boardData, createBoard) .then(boardId => { if (createBoard) { replaceBoard({ ...boardData }, { ...boardData, id: boardId }); @@ -1044,7 +1042,6 @@ export class BoardContainer extends Component { editedTiles = _editedTiles; } - var createCommunicator = false; var createParentBoard = false; var createChildBoard = false; var childBoardData = null; @@ -1095,7 +1092,6 @@ export class BoardContainer extends Component { }; upsertCommunicator(communicatorData); changeCommunicator(communicatorData.id); - createCommunicator = true; } //check for a new own board if (tile && tile.loadBoard && !tile.linkedBoard) { @@ -1130,7 +1126,7 @@ export class BoardContainer extends Component { //api updates if (tile && tile.type === 'board') { //child becomes parent - updateApiObjectsNoChild(childBoardData, createCommunicator, true) + updateApiObjectsNoChild(childBoardData, true) .then(parentBoardId => { switchBoard(parentBoardId); this.props.history.replace(`/board/${parentBoardId}`, []); @@ -1141,11 +1137,7 @@ export class BoardContainer extends Component { }); } else { if (!createChildBoard) { - updateApiObjectsNoChild( - parentBoardData, - createCommunicator, - createParentBoard - ) + updateApiObjectsNoChild(parentBoardData, createParentBoard) .then(parentBoardId => { if (createParentBoard) { replaceBoard( @@ -1160,12 +1152,7 @@ export class BoardContainer extends Component { this.setState({ isSaving: false }); }); } else { - updateApiObjects( - childBoardData, - parentBoardData, - createCommunicator, - createParentBoard - ) + updateApiObjects(childBoardData, parentBoardData, createParentBoard) .then(parentBoardId => { if (createParentBoard) { /* Here the parentBoardData is not updated with the values @@ -1279,7 +1266,6 @@ export class BoardContainer extends Component { this.setState({ isSaving: true }); - let createCommunicator = false; if (communicator.email !== userData.email) { //need to create a new communicator const communicatorData = { @@ -1290,14 +1276,9 @@ export class BoardContainer extends Component { }; upsertCommunicator(communicatorData); changeCommunicator(communicatorData.id); - createCommunicator = true; } try { - const boardId = await updateApiObjectsNoChild( - newBoard, - createCommunicator, - true - ); + const boardId = await updateApiObjectsNoChild(newBoard, true); newBoard = { ...newBoard, id: boardId diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js index e0a91a520..365f22b18 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -287,7 +287,6 @@ class CommunicatorDialogContainer extends React.Component { // Loggedin user? if ('name' in userData && 'email' in userData) { - let createCommunicator = false; if (currentCommunicator.email !== userData.email) { //need to create a new communicator const communicatorData = { @@ -298,17 +297,12 @@ class CommunicatorDialogContainer extends React.Component { }; upsertCommunicator(communicatorData); changeCommunicator(communicatorData.id); - createCommunicator = true; } try { this.setState({ loading: true }); - const boardId = await updateApiObjectsNoChild( - newBoard, - createCommunicator, - true - ); + const boardId = await updateApiObjectsNoChild(newBoard, true); newBoard = { ...newBoard, id: boardId From 58771e7a70f349b76566a0086398b81f248e29d1 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 7 Jun 2024 19:59:25 -0300 Subject: [PATCH 12/85] Create verifyAndUpsertCommunicator --- .../Communicator/Communicator.actions.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index c970ff802..9340cafd3 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -21,6 +21,7 @@ import { } from './Communicator.constants'; import { defaultCommunicatorID } from './Communicator.reducer'; import API from '../../api'; +import shortid from 'shortid'; export function importCommunicator(communicator) { return { @@ -178,6 +179,49 @@ export function updateApiCommunicatorFailure(message) { }; } +export function verifyAndUpsertCommunicator( + communicator, + changeCommunicator = false +) { + return async (dispatch, getState) => { + const { + app: { userData } + } = getState(); + + if (!communicator) return Promise.reject('No communicator provided'); + const updatedCommunicatorData = { + ...communicator, + boards: [...communicator.boards] + }; + + if ( + 'name' in userData && + 'email' in userData && + communicator.email !== userData.email + ) { + //need to create a new communicator + updatedCommunicatorData.author = userData.name; + updatedCommunicatorData.email = userData.email; + updatedCommunicatorData.id = shortid.generate(); + } + + dispatch(upsertCommunicator(updatedCommunicatorData)); + + if (changeCommunicator) + dispatch(changeCommunicator(updatedCommunicatorData.id)); + + // Loggedin user? + if ('name' in userData && 'email' in userData) { + try { + await dispatch(upsertApiCommunicator(updatedCommunicatorData)); + } catch (err) { + Promise.reject(err); + } + } + return Promise.resolve(updatedCommunicatorData); + }; +} + /* * Thunk functions */ From c29e70dc975cc2089c0a905bfcbd4c8641625f75 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 7 Jun 2024 20:03:50 -0300 Subject: [PATCH 13/85] Add async definition to thunk actions --- src/components/Communicator/Communicator.actions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 9340cafd3..d89d096b6 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -52,7 +52,7 @@ export function upsertCommunicator(communicator) { } export function upsertApiCommunicator(communicator) { - return (dispatch, getState) => { + return async (dispatch, getState) => { const { communicator: { communicators } } = getState(); @@ -261,7 +261,7 @@ export function createApiCommunicator(communicatorData, communicatorId) { } export function updateApiCommunicator(communicatorData) { - return dispatch => { + return async dispatch => { dispatch(updateApiCommunicatorStarted()); return API.updateCommunicator(communicatorData) .then(res => { From 780adfda6a7a11a68361799d8a86abd15f4135fa Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 7 Jun 2024 20:05:28 -0300 Subject: [PATCH 14/85] Refactor CommunicatorDialogContainer to use verifyAndUpsertCommunicator for updating boards and root board --- .../CommunicatorDialog.container.js | 79 +++++++------------ 1 file changed, 28 insertions(+), 51 deletions(-) diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js index 365f22b18..05b388023 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -6,12 +6,12 @@ import { injectIntl } from 'react-intl'; import shortid from 'shortid'; import API from '../../../api'; import { - createCommunicator, editCommunicator, changeCommunicator, deleteBoardCommunicator, addBoardCommunicator, - upsertCommunicator + upsertCommunicator, + verifyAndUpsertCommunicator } from '../Communicator.actions'; import { deleteBoard, deleteApiBoard } from '../../Board/Board.actions'; import { showNotification } from '../../Notifications/Notifications.actions'; @@ -425,29 +425,16 @@ class CommunicatorDialogContainer extends React.Component { } async updateCommunicatorBoards(boards) { - const { - userData, - communicators, - currentCommunicator, - changeCommunicator, - editCommunicator - } = this.props; + const { currentCommunicator, verifyAndUpsertCommunicator } = this.props; const updatedCommunicatorData = { ...currentCommunicator, boards: boards.map(cb => cb.id) }; - - if (communicators.findIndex(c => c.id === currentCommunicator.id) >= 0) { - editCommunicator(updatedCommunicatorData); - changeCommunicator(updatedCommunicatorData.id); - - // Loggedin user? - if ('name' in userData && 'email' in userData) { - try { - await API.updateCommunicator(updatedCommunicatorData); - } catch (err) {} - } + try { + await verifyAndUpsertCommunicator(updatedCommunicatorData); + } catch (err) { + console.log(err.message); } } @@ -487,29 +474,16 @@ class CommunicatorDialogContainer extends React.Component { } async setRootBoard(board) { - const { - userData, - communicators, - currentCommunicator, - changeCommunicator, - editCommunicator - } = this.props; + const { currentCommunicator, verifyAndUpsertCommunicator } = this.props; const updatedCommunicatorData = { ...currentCommunicator, rootBoard: board.id }; - - if (communicators.findIndex(c => c.id === currentCommunicator.id) >= 0) { - editCommunicator(updatedCommunicatorData); - changeCommunicator(updatedCommunicatorData.id); - - // Loggedin user? - if ('name' in userData && 'email' in userData) { - try { - await API.updateCommunicator(updatedCommunicatorData); - } catch (err) {} - } + try { + await verifyAndUpsertCommunicator(updatedCommunicatorData); + } catch (err) { + console.log(err.message); } } @@ -522,7 +496,7 @@ class CommunicatorDialogContainer extends React.Component { showNotification, deleteBoard, communicators, - editCommunicator, + verifyAndUpsertCommunicator, deleteApiBoard, userData, intl @@ -535,21 +509,24 @@ class CommunicatorDialogContainer extends React.Component { await deleteApiBoard(board.id); } catch (err) {} } - communicators.forEach(async comm => { + for await (const comm of communicators) { if (comm.boards.includes(board.id)) { - editCommunicator({ + const filteredCommunicator = { ...comm, boards: comm.boards.filter(b => b !== board.id) - }); - - // Loggedin user? - if ('name' in userData && 'email' in userData) { - try { - await API.updateCommunicator(comm); - } catch (err) {} + }; + try { + const changeCommunicator = false; + await verifyAndUpsertCommunicator( + filteredCommunicator, + changeCommunicator + ); + } catch (err) { + console.log(err.message); } } - }); + } + const sBoards = this.state.boards; const index = sBoards.findIndex(b => board.id === b.id); sBoards.splice(index, 1); @@ -640,7 +617,6 @@ const mapStateToProps = ({ board, communicator, language, app }, ownProps) => { }; const mapDispatchToProps = { - createCommunicator, editCommunicator, changeCommunicator, addBoards, @@ -655,7 +631,8 @@ const mapDispatchToProps = { upsertCommunicator, updateApiObjectsNoChild, updateApiBoard, - disableTour + disableTour, + verifyAndUpsertCommunicator }; export default connect( From cf3cdae9eabc83cc3ced030eb68f931f36f1f189 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 7 Jun 2024 20:05:41 -0300 Subject: [PATCH 15/85] Refactor CommunicatorToolbar.container.js and use verifyAndUpsertCommunicator for updating communicators --- .../CommunicatorToolbar.container.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js b/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js index dd7dab4d2..63e3af527 100644 --- a/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js +++ b/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js @@ -12,12 +12,11 @@ import { import { showNotification } from '../../Notifications/Notifications.actions'; import { importCommunicator, - createCommunicator, deleteCommunicator, changeCommunicator, - upsertCommunicator + upsertCommunicator, + verifyAndUpsertCommunicator } from '../Communicator.actions'; -import API from '../../../api'; class CommunicatorContainer extends React.Component { constructor(props) { @@ -37,17 +36,17 @@ class CommunicatorContainer extends React.Component { } editCommunicatorTitle = async name => { + const { currentCommunicator, verifyAndUpsertCommunicator } = this.props; + const updatedCommunicatorData = { - ...this.props.currentCommunicator, + ...currentCommunicator, name }; - - const communicatorData = await API.updateCommunicator( - updatedCommunicatorData - ); - - this.props.upsertCommunicator(communicatorData); - this.props.changeCommunicator(communicatorData.id); + try { + verifyAndUpsertCommunicator(updatedCommunicatorData); + } catch (e) { + console.error('Error updating communicator title', e); + } }; render() { @@ -102,7 +101,7 @@ const mapStateToProps = ( const mapDispatchToProps = { importCommunicator, - createCommunicator, + verifyAndUpsertCommunicator, deleteCommunicator, changeCommunicator, upsertCommunicator, From 6dfd43911503012d541562905024bbe4d2be4aed Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 7 Jun 2024 20:20:58 -0300 Subject: [PATCH 16/85] Refactor ImportContainer to use verifyAndUpsertCommunicator for updating communicators and boards --- .../Settings/Import/Import.container.js | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/components/Settings/Import/Import.container.js b/src/components/Settings/Import/Import.container.js index 28fdfd8e0..ebbc189d1 100644 --- a/src/components/Settings/Import/Import.container.js +++ b/src/components/Settings/Import/Import.container.js @@ -7,7 +7,8 @@ import shortid from 'shortid'; import { addBoards, changeBoard } from '../../Board/Board.actions'; import { upsertCommunicator, - changeCommunicator + changeCommunicator, + verifyAndUpsertCommunicator } from '../../Communicator/Communicator.actions'; import { switchBoard } from '../../Board/Board.actions'; import { showNotification } from '../../Notifications/Notifications.actions'; @@ -97,7 +98,7 @@ export class ImportContainer extends PureComponent { return response; } catch (err) { console.log(err.message); - return board + return board; } }) ); @@ -121,7 +122,7 @@ export class ImportContainer extends PureComponent { } async addBoardsToCommunicator(boards) { - const { userData, currentCommunicator } = this.props; + const { currentCommunicator, verifyAndUpsertCommunicator } = this.props; const communicatorBoards = new Set( currentCommunicator.boards.concat(boards.map(b => b.id)) @@ -131,16 +132,11 @@ export class ImportContainer extends PureComponent { boards: Array.from(communicatorBoards) }; - if (userData && userData.authToken && userData.authToken.length) { - try { - communicatorModified = await API.updateCommunicator(communicatorModified); - } catch (err) { - console.log(err.message); - } + try { + await verifyAndUpsertCommunicator(communicatorModified); + } catch (e) { + console.error('Error upserting communicator', e); } - - this.props.upsertCommunicator(communicatorModified); - this.props.changeCommunicator(communicatorModified.id); } async handleImportClick(e, doneCallback) { @@ -231,7 +227,8 @@ const mapDispatchToProps = { switchBoard, upsertCommunicator, changeCommunicator, - showNotification + showNotification, + verifyAndUpsertCommunicator }; export default connect( From 1967e72968de217ef416aa74338bb3d5a096fe88 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 10 Jun 2024 14:02:23 -0300 Subject: [PATCH 17/85] Change communicator by default on verifyAndUpsertCommunicator --- src/components/Communicator/Communicator.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index d89d096b6..315e15e47 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -181,7 +181,7 @@ export function updateApiCommunicatorFailure(message) { export function verifyAndUpsertCommunicator( communicator, - changeCommunicator = false + changeCommunicator = true ) { return async (dispatch, getState) => { const { From c80b7f914f53d380fdf66263bcd0b3d5598651c0 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 10 Jun 2024 15:04:04 -0300 Subject: [PATCH 18/85] Shallow copy of boards and defaultBoardsIncluded on communicator creation --- .../Communicator/Communicator.actions.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 315e15e47..79caa6e83 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -56,7 +56,7 @@ export function upsertApiCommunicator(communicator) { const { communicator: { communicators } } = getState(); - const SHORT_ID_MAX_LENGTH = 14; + const SHORT_ID_MAX_LENGTH = 15; // If the communicator is not on the local state return if (!communicators.find(c => c.id === communicator.id)) @@ -181,7 +181,7 @@ export function updateApiCommunicatorFailure(message) { export function verifyAndUpsertCommunicator( communicator, - changeCommunicator = true + needToChangeCommunicator = true ) { return async (dispatch, getState) => { const { @@ -189,10 +189,7 @@ export function verifyAndUpsertCommunicator( } = getState(); if (!communicator) return Promise.reject('No communicator provided'); - const updatedCommunicatorData = { - ...communicator, - boards: [...communicator.boards] - }; + const updatedCommunicatorData = { ...communicator }; if ( 'name' in userData && @@ -203,11 +200,18 @@ export function verifyAndUpsertCommunicator( updatedCommunicatorData.author = userData.name; updatedCommunicatorData.email = userData.email; updatedCommunicatorData.id = shortid.generate(); + updatedCommunicatorData.boards = [...communicator.boards]; + + if (communicator.defaultBoardsIncluded) { + updatedCommunicatorData.defaultBoardsIncluded = communicator.defaultBoardsIncluded.map( + item => ({ ...item }) + ); + } } dispatch(upsertCommunicator(updatedCommunicatorData)); - if (changeCommunicator) + if (needToChangeCommunicator) dispatch(changeCommunicator(updatedCommunicatorData.id)); // Loggedin user? From c2d8fb3378b222eba2a97e21852fd38ed7d381bc Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 10 Jun 2024 15:04:30 -0300 Subject: [PATCH 19/85] Change console.log for console.error --- .../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 05b388023..e99efa087 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -434,7 +434,7 @@ class CommunicatorDialogContainer extends React.Component { try { await verifyAndUpsertCommunicator(updatedCommunicatorData); } catch (err) { - console.log(err.message); + console.error(err.message); } } From 22e874b2cef85d747ea554a8aba9478af39a0399 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 10 Jun 2024 20:56:21 -0300 Subject: [PATCH 20/85] Add await on try catch block --- .../CommunicatorToolbar/CommunicatorToolbar.container.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js b/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js index 63e3af527..6eac5a214 100644 --- a/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js +++ b/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js @@ -43,7 +43,7 @@ class CommunicatorContainer extends React.Component { name }; try { - verifyAndUpsertCommunicator(updatedCommunicatorData); + await verifyAndUpsertCommunicator(updatedCommunicatorData); } catch (e) { console.error('Error updating communicator title', e); } From 05568ae49d83d01687934d9b6887f20b15247ec0 Mon Sep 17 00:00:00 2001 From: tomivm Date: Tue, 11 Jun 2024 17:20:00 -0300 Subject: [PATCH 21/85] Add actions to clean all boards and add the necessary default boards --- src/components/Board/Board.actions.js | 61 ++++++++++++++++++++++++- src/components/Board/Board.constants.js | 1 + src/components/Board/Board.reducer.js | 9 +++- src/helpers.js | 4 ++ 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index f06d8db12..cb5c6a502 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -38,7 +38,8 @@ import { DOWNLOAD_IMAGES_FAILURE, DOWNLOAD_IMAGES_STARTED, DOWNLOAD_IMAGE_SUCCESS, - DOWNLOAD_IMAGE_FAILURE + DOWNLOAD_IMAGE_FAILURE, + CLEAN_ALL_BOARDS } from './Board.constants'; import API from '../../api'; @@ -57,7 +58,7 @@ import { changeCommunicator } from '../Communicator/Communicator.actions'; import { isAndroid, writeCvaFile } from '../../cordova-util'; -import { DEFAULT_BOARDS } from '../../helpers'; +import { ALL_DEFAULT_BOARDS, DEFAULT_BOARDS } from '../../helpers'; import history from './../../history'; import { improvePhraseAbortController } from '../../api/api'; import shortid from 'shortid'; @@ -840,3 +841,59 @@ export function updateApiObjects( }); }; } + +export function cleanAllBoards() { + return { + type: CLEAN_ALL_BOARDS + }; +} +export function addRootBoard() { + return (dispatch, getState) => { + try { + const activeCommunicator = getActiveCommunicator(getState); + const rootBoard = activeCommunicator.rootBoard; + const board = getState().board.boards.find( + board => board.id === rootBoard + ); + if (!board) { + ALL_DEFAULT_BOARDS.advanced.some(defaultBoard => { + if (defaultBoard.id === rootBoard) { + dispatch(addBoards([defaultBoard])); + return true; + } + return false; + }); + } + } catch (e) { + console.error(e); + } + }; +} + +export function addDefaultBoards() { + return (dispatch, getState) => { + const boardsIdsToAdd = []; + // These are all boards including the boards that are getted from the API if this is called in the finally of getApiMyBoards thunk + const allStoreBoards = getState().board.boards; + allStoreBoards.forEach(includedBoard => { + includedBoard.tiles.forEach(tile => { + if (tile.loadBoard && !boardsIdsToAdd.includes(tile.loadBoard)) + boardsIdsToAdd.push(tile.loadBoard); + }); + }); + + boardsIdsToAdd.forEach(boardId => { + const allStoreBoards = getState().board.boards; + const board = allStoreBoards.find(board => board.id === boardId); + if (!board) { + ALL_DEFAULT_BOARDS.some(defaultBoard => { + if (defaultBoard.id === boardId) { + dispatch(addBoards([defaultBoard])); + return true; + } + return false; + }); + } + }); + }; +} diff --git a/src/components/Board/Board.constants.js b/src/components/Board/Board.constants.js index 7d820d648..297649f99 100644 --- a/src/components/Board/Board.constants.js +++ b/src/components/Board/Board.constants.js @@ -19,6 +19,7 @@ export const CHANGE_IMPROVED_PHRASE = 'cboard/Board/CHANGE_IMPROVED_PHRASE'; export const CHANGE_LIVE_MODE = 'cboard/Board/CHANGE_LIVE_MODE'; export const HISTORY_REMOVE_BOARD = 'cboard/Board/HISTORY_REMOVE_BOARD'; export const UNMARK_BOARD = 'cboard/Board/UNMARK_BOARD'; +export const CLEAN_ALL_BOARDS = 'cboard/Board/CLEAN_ALL_BOARDS'; export const CREATE_API_BOARD_SUCCESS = 'cboard/Board/CREATE_API_BOARD_SUCCESS'; export const CREATE_API_BOARD_FAILURE = 'cboard/Board/CREATE_API_BOARD_FAILURE'; export const CREATE_API_BOARD_STARTED = 'cboard/Board/CREATE_API_BOARD_STARTED'; diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index b7db1bd49..4e595138d 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -36,7 +36,8 @@ import { GET_API_MY_BOARDS_STARTED, DOWNLOAD_IMAGES_STARTED, DOWNLOAD_IMAGE_SUCCESS, - DOWNLOAD_IMAGE_FAILURE + DOWNLOAD_IMAGE_FAILURE, + CLEAN_ALL_BOARDS } from './Board.constants'; import { LOGOUT, LOGIN_SUCCESS } from '../Account/Login/Login.constants'; @@ -249,7 +250,11 @@ function boardReducer(state = initialState, action) { board => action.boardId.indexOf(board.id) === -1 ) }; - + case CLEAN_ALL_BOARDS: + return { + ...state, + boards: [] + }; case CREATE_TILE: return { ...state, diff --git a/src/helpers.js b/src/helpers.js index 6ac74ee2f..9327fd56f 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -5,6 +5,10 @@ export const DEFAULT_BOARDS = { advanced: boards.advanced, picSeePal: picSeePal }; +let advancedCopy = JSON.parse(JSON.stringify(DEFAULT_BOARDS.advanced)); +let picSeePalCopy = JSON.parse(JSON.stringify(DEFAULT_BOARDS.picSeePal)); + +export const ALL_DEFAULT_BOARDS = [...advancedCopy, ...picSeePalCopy]; export const dataURLtoFile = (dataurl, filename, checkExtension = false) => { // https://stackoverflow.com/a/38936042 From c0a07cb8bd03fda318d98bcf2812c827693e2303 Mon Sep 17 00:00:00 2001 From: tomivm Date: Tue, 11 Jun 2024 17:25:08 -0300 Subject: [PATCH 22/85] Clean All boards from the store before loginSuccess --- src/components/Account/Login/Login.actions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index cf96125bf..b8500c645 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -1,6 +1,6 @@ import API from '../../../api'; import { LOGIN_SUCCESS, LOGOUT } from './Login.constants'; -import { addBoards } from '../../Board/Board.actions'; +import { addBoards, cleanAllBoards } from '../../Board/Board.actions'; import { changeVoice, changePitch, @@ -172,7 +172,7 @@ export function login({ email, password, activatedData }, type = 'local') { }) .filter(b => b !== null) ); - + dispatch(cleanAllBoards()); dispatch(addBoards(apiBoards)); if (type === 'local') { dispatch( From ae9e5da81c9e598dacf02143d42be573e91e0822 Mon Sep 17 00:00:00 2001 From: tomivm Date: Tue, 11 Jun 2024 17:29:08 -0300 Subject: [PATCH 23/85] Add root board if is not on the communicator boards before login success --- src/components/Account/Login/Login.actions.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index b8500c645..8d69d889e 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -2,6 +2,7 @@ import API from '../../../api'; import { LOGIN_SUCCESS, LOGOUT } from './Login.constants'; import { addBoards, cleanAllBoards } from '../../Board/Board.actions'; import { + addRootBoard, changeVoice, changePitch, changeRate @@ -174,6 +175,7 @@ export function login({ email, password, activatedData }, type = 'local') { ); dispatch(cleanAllBoards()); dispatch(addBoards(apiBoards)); + dispatch(addRootBoard()); if (type === 'local') { dispatch( disableTour({ From 69f5beee7b9b98c07b213dc2527da5c822886b0c Mon Sep 17 00:00:00 2001 From: tomivm Date: Tue, 11 Jun 2024 17:32:15 -0300 Subject: [PATCH 24/85] Fix addRootBoard import --- src/components/Account/Login/Login.actions.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index 8d69d889e..979ee3de0 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -1,8 +1,11 @@ import API from '../../../api'; import { LOGIN_SUCCESS, LOGOUT } from './Login.constants'; -import { addBoards, cleanAllBoards } from '../../Board/Board.actions'; import { - addRootBoard, + addBoards, + cleanAllBoards, + addRootBoard +} from '../../Board/Board.actions'; +import { changeVoice, changePitch, changeRate From bec7283003397236bf066c458732d09d7aa48669 Mon Sep 17 00:00:00 2001 From: tomivm Date: Tue, 11 Jun 2024 17:47:38 -0300 Subject: [PATCH 25/85] refactor: Update addRootBoard import and function name to addRootBoardFromDefaultBoards --- src/components/Account/Login/Login.actions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index 979ee3de0..766a77fa1 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -3,7 +3,7 @@ import { LOGIN_SUCCESS, LOGOUT } from './Login.constants'; import { addBoards, cleanAllBoards, - addRootBoard + addRootBoardFromDefaultBoards } from '../../Board/Board.actions'; import { changeVoice, @@ -178,7 +178,7 @@ export function login({ email, password, activatedData }, type = 'local') { ); dispatch(cleanAllBoards()); dispatch(addBoards(apiBoards)); - dispatch(addRootBoard()); + dispatch(addRootBoardFromDefaultBoards()); if (type === 'local') { dispatch( disableTour({ From 408fba8bbd8f92e550265e5b7815a5bba192fb7a Mon Sep 17 00:00:00 2001 From: tomivm Date: Tue, 11 Jun 2024 22:23:55 -0300 Subject: [PATCH 26/85] refactor: Rename addRootBoard function to findAndAddRootBoardOnDefaultBoards --- src/components/Account/Login/Login.actions.js | 4 +-- src/components/Board/Board.actions.js | 30 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index 766a77fa1..829b5b9c9 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -3,7 +3,7 @@ import { LOGIN_SUCCESS, LOGOUT } from './Login.constants'; import { addBoards, cleanAllBoards, - addRootBoardFromDefaultBoards + findAndAddRootBoardOnDefaultBoards } from '../../Board/Board.actions'; import { changeVoice, @@ -178,7 +178,7 @@ export function login({ email, password, activatedData }, type = 'local') { ); dispatch(cleanAllBoards()); dispatch(addBoards(apiBoards)); - dispatch(addRootBoardFromDefaultBoards()); + dispatch(findAndAddRootBoardOnDefaultBoards()); if (type === 'local') { dispatch( disableTour({ diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index cb5c6a502..b725872e0 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -847,7 +847,7 @@ export function cleanAllBoards() { type: CLEAN_ALL_BOARDS }; } -export function addRootBoard() { +export function findAndAddRootBoardOnDefaultBoards() { return (dispatch, getState) => { try { const activeCommunicator = getActiveCommunicator(getState); @@ -856,13 +856,29 @@ export function addRootBoard() { board => board.id === rootBoard ); if (!board) { - ALL_DEFAULT_BOARDS.advanced.some(defaultBoard => { - if (defaultBoard.id === rootBoard) { - dispatch(addBoards([defaultBoard])); - return true; + const addNecessaryBoards = necessaryBoardId => { + const isRootBoardAdded = ALL_DEFAULT_BOARDS.some(defaultBoard => { + if (defaultBoard.id === necessaryBoardId) { + dispatch(addBoards([defaultBoard])); + defaultBoard.tiles.forEach(tile => { + if ( + tile.loadBoard && + !getState().board.boards.some( + board => board.id === tile.loadBoard + ) + ) { + addNecessaryBoards(tile.loadBoard); + } + }); + return true; + } + return false; + }); + if (!isRootBoardAdded) { + throw new Error('Root board not found searching on default boards'); } - return false; - }); + }; + addNecessaryBoards(rootBoard); } } catch (e) { console.error(e); From 360aa9e2f1cdab38dbec33ebe5104bede913d3e0 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 13 Jun 2024 10:32:24 -0300 Subject: [PATCH 27/85] Refactor login to add necessary default boards for homeBoards --- src/components/Account/Login/Login.actions.js | 12 ++- src/components/Board/Board.actions.js | 92 ++++++++----------- 2 files changed, 48 insertions(+), 56 deletions(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index 829b5b9c9..08f6271bc 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -3,7 +3,7 @@ import { LOGIN_SUCCESS, LOGOUT } from './Login.constants'; import { addBoards, cleanAllBoards, - findAndAddRootBoardOnDefaultBoards + addNecessaryDefaultBoardsFor } from '../../Board/Board.actions'; import { changeVoice, @@ -178,7 +178,15 @@ export function login({ email, password, activatedData }, type = 'local') { ); dispatch(cleanAllBoards()); dispatch(addBoards(apiBoards)); - dispatch(findAndAddRootBoardOnDefaultBoards()); + const userDefaultBoardsIncluded = + currentCommunicator.defaultBoardsIncluded; + if (userDefaultBoardsIncluded) { + userDefaultBoardsIncluded.forEach(({ homeBoard }) => { + dispatch(addNecessaryDefaultBoardsFor(homeBoard)); + }); + } else { + dispatch(addNecessaryDefaultBoardsFor(currentCommunicator.rootBoard)); + } if (type === 'local') { dispatch( disableTour({ diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index b725872e0..89c5222db 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -847,69 +847,53 @@ export function cleanAllBoards() { type: CLEAN_ALL_BOARDS }; } -export function findAndAddRootBoardOnDefaultBoards() { + +export function addNecessaryDefaultBoardsFor(boardIdToAdd) { return (dispatch, getState) => { - try { - const activeCommunicator = getActiveCommunicator(getState); - const rootBoard = activeCommunicator.rootBoard; + const checkedBoardsIds = []; + const addNecessaryBoards = ({ dispatch, getState, necessaryBoardId }) => { const board = getState().board.boards.find( - board => board.id === rootBoard + board => board?.id === necessaryBoardId ); - if (!board) { - const addNecessaryBoards = necessaryBoardId => { - const isRootBoardAdded = ALL_DEFAULT_BOARDS.some(defaultBoard => { - if (defaultBoard.id === necessaryBoardId) { - dispatch(addBoards([defaultBoard])); - defaultBoard.tiles.forEach(tile => { - if ( - tile.loadBoard && - !getState().board.boards.some( - board => board.id === tile.loadBoard - ) - ) { - addNecessaryBoards(tile.loadBoard); - } + const checkLoadBoards = board => { + checkedBoardsIds.push(board.id); + board.tiles.forEach(tile => { + if ( + tile.loadBoard + // !getState().board.boards.some(board => board.id === tile.loadBoard) + ) { + if (!checkedBoardsIds.includes(tile.loadBoard)) { + addNecessaryBoards({ + dispatch, + getState, + necessaryBoardId: tile.loadBoard }); - return true; } - return false; - }); - if (!isRootBoardAdded) { - throw new Error('Root board not found searching on default boards'); } - }; - addNecessaryBoards(rootBoard); + }); + }; + if (board) { + checkLoadBoards(board); + return; } + + ALL_DEFAULT_BOARDS.some(defaultBoard => { + if (defaultBoard.id === necessaryBoardId) { + dispatch(addBoards([defaultBoard])); + checkLoadBoards(defaultBoard); + return true; + } + return false; + }); + }; + try { + addNecessaryBoards({ + dispatch, + getState, + necessaryBoardId: boardIdToAdd + }); } catch (e) { console.error(e); } }; } - -export function addDefaultBoards() { - return (dispatch, getState) => { - const boardsIdsToAdd = []; - // These are all boards including the boards that are getted from the API if this is called in the finally of getApiMyBoards thunk - const allStoreBoards = getState().board.boards; - allStoreBoards.forEach(includedBoard => { - includedBoard.tiles.forEach(tile => { - if (tile.loadBoard && !boardsIdsToAdd.includes(tile.loadBoard)) - boardsIdsToAdd.push(tile.loadBoard); - }); - }); - - boardsIdsToAdd.forEach(boardId => { - const allStoreBoards = getState().board.boards; - const board = allStoreBoards.find(board => board.id === boardId); - if (!board) { - ALL_DEFAULT_BOARDS.some(defaultBoard => { - if (defaultBoard.id === boardId) { - dispatch(addBoards([defaultBoard])); - return true; - } - return false; - }); - } - }); - }; -} From 15ba033161aef802cd313dc507116989d37457c4 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 13 Jun 2024 10:35:22 -0300 Subject: [PATCH 28/85] Add necessary default boards for remote boards --- src/components/Board/Board.actions.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 89c5222db..89cf27e12 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -510,6 +510,10 @@ export function getApiMyBoards() { }) .then(res => { dispatch(getApiMyBoardsSuccess(res)); + const newBoards = res.data; + newBoards?.forEach(({ id }) => { + dispatch(addNecessaryDefaultBoardsFor(id)); + }); return res; }) .catch(err => { From 2aeeb4a8a78b407e71300b9b7bdcdb5bbaa07baf Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 13 Jun 2024 10:37:54 -0300 Subject: [PATCH 29/85] Prevent unnecessary requests to get boards for local Ids --- src/components/Account/Login/Login.actions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index 08f6271bc..631899a55 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -165,12 +165,15 @@ export function login({ email, password, activatedData }, type = 'local') { id => localBoardsIds.indexOf(id) < 0 ); + const SHORT_ID_MAX_LENGTH = 14; + const apiBoards = await Promise.all( apiBoardsIds .map(async id => { let board = null; try { - board = await API.getBoard(id); + if (!(id.length < SHORT_ID_MAX_LENGTH)) + board = await API.getBoard(id); } catch (e) {} return board; }) From 2aec38faf8f55627400a41ad3987daad50066828 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 13 Jun 2024 17:13:44 -0300 Subject: [PATCH 30/85] Refactor verifyAndUpsertCommunicator --- .../Communicator/Communicator.actions.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 79caa6e83..91914fb6b 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -183,12 +183,12 @@ export function verifyAndUpsertCommunicator( communicator, needToChangeCommunicator = true ) { - return async (dispatch, getState) => { + return (dispatch, getState) => { const { app: { userData } } = getState(); - if (!communicator) return Promise.reject('No communicator provided'); + if (!communicator) return; const updatedCommunicatorData = { ...communicator }; if ( @@ -202,7 +202,7 @@ export function verifyAndUpsertCommunicator( updatedCommunicatorData.id = shortid.generate(); updatedCommunicatorData.boards = [...communicator.boards]; - if (communicator.defaultBoardsIncluded) { + if (!!communicator.defaultBoardsIncluded) { updatedCommunicatorData.defaultBoardsIncluded = communicator.defaultBoardsIncluded.map( item => ({ ...item }) ); @@ -214,15 +214,7 @@ export function verifyAndUpsertCommunicator( if (needToChangeCommunicator) dispatch(changeCommunicator(updatedCommunicatorData.id)); - // Loggedin user? - if ('name' in userData && 'email' in userData) { - try { - await dispatch(upsertApiCommunicator(updatedCommunicatorData)); - } catch (err) { - Promise.reject(err); - } - } - return Promise.resolve(updatedCommunicatorData); + return; }; } From 1dcf25e12fc936a5cda04dcc7ed76a204925b6e2 Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 14 Jun 2024 14:37:09 -0300 Subject: [PATCH 31/85] Add necessary Default boards on changeDefaultBoard --- src/components/Board/Board.actions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 89cf27e12..381218b4b 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -165,6 +165,7 @@ export function changeDefaultBoard(selectedBoardNameOnJson) { const switchActiveBoard = homeBoardId => { if (homeBoardId) { + dispatch(addNecessaryDefaultBoardsFor(homeBoardId)); const goTo = `/board/${homeBoardId}`; dispatch(switchBoard(homeBoardId)); From 2cca7af16f12885b4c79ffa1ff29ebf82d2bf633 Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 14 Jun 2024 18:45:58 -0300 Subject: [PATCH 32/85] Enforces the possibilities to find the home board if it is requested --- src/components/Board/Board.container.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 8a01dcc98..daae00aa7 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -47,7 +47,8 @@ import { downloadImages, createApiBoard, upsertApiBoard, - changeDefaultBoard + changeDefaultBoard, + addNecessaryDefaultBoardsFor } from './Board.actions'; import { upsertCommunicator, @@ -71,6 +72,7 @@ import { IS_BROWSING_FROM_APPLE_TOUCH, IS_BROWSING_FROM_SAFARI } from '../../constants'; +import { ALL_DEFAULT_BOARDS } from '../../helpers'; //import { isAndroid } from '../../cordova-util'; const ogv = require('ogv'); @@ -221,7 +223,8 @@ export class BoardContainer extends Component { changeBoard, userData, history, - getApiObjects + getApiObjects, + addNecessaryDefaultBoardsFor //downloadImages } = this.props; @@ -274,9 +277,13 @@ export class BoardContainer extends Component { if (!boardExists) { // try the root board - boardExists = boards.find(b => b.id === communicator.rootBoard); + const homeBoard = communicator.rootBoard; + if (ALL_DEFAULT_BOARDS.map({ id }.includes(homeBoard))) + addNecessaryDefaultBoardsFor(homeBoard); + boardExists = boards.find(b => b.id === homeBoard); if (!boardExists) { - boardExists = boards.find(b => b.id !== ''); + boardExists = this.tryRemoteBoard(homeBoard); + if (!boardExists) boardExists = boards.find(b => b.id !== ''); } } const boardId = boardExists.id; @@ -1783,7 +1790,8 @@ const mapDispatchToProps = { disableTour, createApiBoard, upsertApiBoard, - changeDefaultBoard + changeDefaultBoard, + addNecessaryDefaultBoardsFor }; export default connect( From f1e3fcf5f234ca9f729c7d03ff1ae68bb48c85c0 Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 14 Jun 2024 19:30:48 -0300 Subject: [PATCH 33/85] Fix incorrect map to search ids on ALL_DEFAULT_BOARDS --- src/components/Board/Board.container.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index daae00aa7..6d232e3ce 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -278,7 +278,7 @@ export class BoardContainer extends Component { if (!boardExists) { // try the root board const homeBoard = communicator.rootBoard; - if (ALL_DEFAULT_BOARDS.map({ id }.includes(homeBoard))) + if (ALL_DEFAULT_BOARDS.map(({ id }) => id).includes(homeBoard)) addNecessaryDefaultBoardsFor(homeBoard); boardExists = boards.find(b => b.id === homeBoard); if (!boardExists) { From ee8c86c5eeecdfe6e66b1f6a99b0f052d8722bf9 Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 14 Jun 2024 19:31:31 -0300 Subject: [PATCH 34/85] Create helper function to check if id is Remote --- src/helpers.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/helpers.js b/src/helpers.js index 9327fd56f..06770683d 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -10,6 +10,12 @@ let picSeePalCopy = JSON.parse(JSON.stringify(DEFAULT_BOARDS.picSeePal)); export const ALL_DEFAULT_BOARDS = [...advancedCopy, ...picSeePalCopy]; +export const SHORT_ID_MAX_LENGTH = 14; + +export const isRemoteIdChecker = id => { + return !(id.length < SHORT_ID_MAX_LENGTH); +}; + export const dataURLtoFile = (dataurl, filename, checkExtension = false) => { // https://stackoverflow.com/a/38936042 const arr = dataurl.split(','); From 3a7b9738e2c9f0490be4d2f5d53a7c50cae99455 Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 14 Jun 2024 19:32:49 -0300 Subject: [PATCH 35/85] Add insurance to find Default Boards on a folder click --- src/components/Board/Board.container.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 6d232e3ce..121b45f5d 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -72,7 +72,7 @@ import { IS_BROWSING_FROM_APPLE_TOUCH, IS_BROWSING_FROM_SAFARI } from '../../constants'; -import { ALL_DEFAULT_BOARDS } from '../../helpers'; +import { ALL_DEFAULT_BOARDS, isRemoteIdChecker } from '../../helpers'; //import { isAndroid } from '../../cordova-util'; const ogv = require('ogv'); @@ -884,8 +884,22 @@ export class BoardContainer extends Component { }; if (tile.loadBoard) { + const loadBoardFinder = loadBoardSearched => { + const findBoardOnStore = boardId => + this.props.boards.find(b => b.id === boardId); + + const nextBoard = findBoardOnStore(loadBoardSearched); + if (nextBoard) return nextBoard; + if ( + ALL_DEFAULT_BOARDS.map(({ id }) => id).includes(loadBoardSearched) + ) { + addNecessaryDefaultBoardsFor(loadBoardSearched); + const nextBoard = findBoardOnStore(loadBoardFinder); + if (nextBoard) return nextBoard; + } + }; const nextBoard = - boards.find(b => b.id === tile.loadBoard) || + loadBoardFinder(tile.loadBoard) || // If the board id is invalid, try falling back to a board // with the right name. boards.find(b => b.name === tile.label); From 0f7c473bde0241e76e5fbc1efbce43daec74f320 Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 14 Jun 2024 19:36:57 -0300 Subject: [PATCH 36/85] use remoteIdChecker helper function --- src/components/Account/Login/Login.actions.js | 6 ++---- src/components/Board/Board.container.js | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index 631899a55..067b4b265 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -19,6 +19,7 @@ import { } from '../../App/App.actions'; import { getVoiceURI } from '../../../i18n'; import { isCordova, isElectron } from '../../../cordova-util'; +import { isRemoteIdChecker } from '../../../helpers'; export function loginSuccess(payload) { return dispatch => { @@ -165,15 +166,12 @@ export function login({ email, password, activatedData }, type = 'local') { id => localBoardsIds.indexOf(id) < 0 ); - const SHORT_ID_MAX_LENGTH = 14; - const apiBoards = await Promise.all( apiBoardsIds .map(async id => { let board = null; try { - if (!(id.length < SHORT_ID_MAX_LENGTH)) - board = await API.getBoard(id); + if (isRemoteIdChecker(id)) board = await API.getBoard(id); } catch (e) {} return board; }) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 121b45f5d..ae2188751 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -282,7 +282,8 @@ export class BoardContainer extends Component { addNecessaryDefaultBoardsFor(homeBoard); boardExists = boards.find(b => b.id === homeBoard); if (!boardExists) { - boardExists = this.tryRemoteBoard(homeBoard); + if (isRemoteIdChecker(homeBoard)) + boardExists = this.tryRemoteBoard(homeBoard); if (!boardExists) boardExists = boards.find(b => b.id !== ''); } } From cc9814b3b7cfd07e223020cce963d8bcfa92c865 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 18 Jun 2024 17:00:47 -0300 Subject: [PATCH 37/85] Use verifyAndUpsertCommunicator on changeDefaultBoard --- src/components/Board/Board.actions.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 797963d0c..634d8100e 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -51,14 +51,12 @@ import { upsertApiCommunicator, updateDefaultBoardsIncluded, addDefaultBoardIncluded, - createCommunicator, - changeCommunicator + verifyAndUpsertCommunicator } from '../Communicator/Communicator.actions'; import { isAndroid, writeCvaFile } from '../../cordova-util'; import { DEFAULT_BOARDS } from '../../helpers'; import history from './../../history'; import { improvePhraseAbortController } from '../../api/api'; -import shortid from 'shortid'; const BOARDS_PAGE_LIMIT = 100; @@ -100,18 +98,9 @@ export function changeDefaultBoard(selectedBoardNameOnJson) { if (userData.email && activeCommunicator.email !== userData?.email) { // Create a new communicator for the user if it doesn't exist - const newCommunicator = { - ...activeCommunicator, - boards: [...activeCommunicator.boards], - author: userData.name, - email: userData.email, - id: shortid.generate() - }; - dispatch(createCommunicator(newCommunicator)); - dispatch(changeCommunicator(newCommunicator.id)); - return newCommunicator; + dispatch(verifyAndUpsertCommunicator(activeCommunicator)); } - return activeCommunicator; + return getActiveCommunicator(getState); }; const activeCommunicator = checkUserCommunicator(); From 837a0543342a6566a1ffd254e5b492e98286e2d6 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 18 Jun 2024 17:33:27 -0300 Subject: [PATCH 38/85] Refactor Board container functions to use verifyAndUpsertContainer --- src/components/Board/Board.container.js | 69 +++++++++---------------- 1 file changed, 24 insertions(+), 45 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 97634d34e..00e31becc 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -50,9 +50,8 @@ import { changeDefaultBoard } from './Board.actions'; import { - upsertCommunicator, - changeCommunicator, - addBoardCommunicator + addBoardCommunicator, + verifyAndUpsertCommunicator } from '../Communicator/Communicator.actions'; import { disableTour } from '../App/App.actions'; import TileEditor from './TileEditor'; @@ -486,11 +485,10 @@ export class BoardContainer extends Component { const { userData, communicator, - upsertCommunicator, - changeCommunicator, replaceBoard, updateApiObjectsNoChild, - lang + lang, + verifyAndUpsertCommunicator } = this.props; var createBoard = false; @@ -507,19 +505,15 @@ export class BoardContainer extends Component { locale: lang }; //check if user has an own communicator - let communicatorData = { ...communicator }; if (communicator.email !== userData.email) { - //need to create a new communicator - communicatorData = { + const communicatorData = { ...communicator, - author: userData.name, - email: userData.email, - boards: boardData.id === 'root' ? ['root'] : ['root', boardData.id], - rootBoard: 'root', - id: shortid.generate() + boards: [ + boardData.id === 'root' ? ['root'] : ['root', boardData.id] + ], + rootBoard: 'root' }; - upsertCommunicator(communicatorData); - changeCommunicator(communicatorData.id); + verifyAndUpsertCommunicator(communicatorData); } //check if we have to create a copy of the board if (boardData.id.length < 14) { @@ -631,6 +625,7 @@ export class BoardContainer extends Component { }; if (tile.loadBoard && !tile.linkedBoard) { createBoard(boardData); + //TODO use verifyAndUpsertCommunicator before addBoardCommunicator addBoardCommunicator(boardData.id); } @@ -1016,8 +1011,7 @@ export class BoardContainer extends Component { communicator, board, intl, - upsertCommunicator, - changeCommunicator, + verifyAndUpsertCommunicator, updateApiObjectsNoChild, updateApiObjects, replaceBoard, @@ -1081,17 +1075,8 @@ export class BoardContainer extends Component { locale: lang }; //check if user has an own communicator - let communicatorData = { ...communicator }; if (communicator.email !== userData.email) { - //need to create a new communicator - communicatorData = { - ...communicator, - author: userData.name, - email: userData.email, - id: shortid.generate() - }; - upsertCommunicator(communicatorData); - changeCommunicator(communicatorData.id); + verifyAndUpsertCommunicator(communicator); } //check for a new own board if (tile && tile.loadBoard && !tile.linkedBoard) { @@ -1214,14 +1199,13 @@ export class BoardContainer extends Component { createBoard, switchBoard, addBoardCommunicator, - upsertCommunicator, - changeCommunicator, history, communicator, userData, updateApiObjectsNoChild, boards, - intl + intl, + verifyAndUpsertCommunicator } = this.props; //prevent shit @@ -1258,6 +1242,7 @@ export class BoardContainer extends Component { } createBoard(newBoard); if (!records) { + verifyAndUpsertCommunicator(communicator); addBoardCommunicator(newBoard.id); } @@ -1266,17 +1251,7 @@ export class BoardContainer extends Component { this.setState({ isSaving: true }); - if (communicator.email !== userData.email) { - //need to create a new communicator - const communicatorData = { - ...communicator, - author: userData.name, - email: userData.email, - id: shortid.generate() - }; - upsertCommunicator(communicatorData); - changeCommunicator(communicatorData.id); - } + try { const boardId = await updateApiObjectsNoChild(newBoard, true); newBoard = { @@ -1706,6 +1681,11 @@ const mapStateToProps = ({ const currentCommunicator = communicator.communicators.find( communicator => communicator.id === activeCommunicatorId ); + console.log( + 'vuelve a definir mapsateToProps', + activeCommunicatorId, + currentCommunicator + ); const activeBoardId = board.activeBoardId; const emptyVoiceAlert = speech.voices.length > 0 && speech.options.voiceURI !== EMPTY_VOICES @@ -1754,8 +1734,6 @@ const mapDispatchToProps = { showNotification, hideNotification, deactivateScanner, - upsertCommunicator, - changeCommunicator, addBoardCommunicator, updateApiObjects, updateApiObjectsNoChild, @@ -1764,7 +1742,8 @@ const mapDispatchToProps = { disableTour, createApiBoard, upsertApiBoard, - changeDefaultBoard + changeDefaultBoard, + verifyAndUpsertCommunicator }; export default connect( From 00f56a08ef95aaee0aec453b5925d893fa373b0d Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 18 Jun 2024 17:35:32 -0300 Subject: [PATCH 39/85] Add upserApiCommunicator un editCommunicatorTitle --- .../CommunicatorToolbar.container.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js b/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js index 6eac5a214..922f475bd 100644 --- a/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js +++ b/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js @@ -13,8 +13,6 @@ import { showNotification } from '../../Notifications/Notifications.actions'; import { importCommunicator, deleteCommunicator, - changeCommunicator, - upsertCommunicator, verifyAndUpsertCommunicator } from '../Communicator.actions'; @@ -36,16 +34,25 @@ class CommunicatorContainer extends React.Component { } editCommunicatorTitle = async name => { - const { currentCommunicator, verifyAndUpsertCommunicator } = this.props; + const { + currentCommunicator, + verifyAndUpsertCommunicator, + upsertApiCommunicator, + userData + } = this.props; const updatedCommunicatorData = { ...currentCommunicator, name }; - try { - await verifyAndUpsertCommunicator(updatedCommunicatorData); - } catch (e) { - console.error('Error updating communicator title', e); + + verifyAndUpsertCommunicator(updatedCommunicatorData); + if ('name' in userData && 'email' in userData) { + try { + await upsertApiCommunicator(updatedCommunicatorData); + } catch (err) { + console.error('Error upserting communicator', err); + } } }; @@ -103,8 +110,6 @@ const mapDispatchToProps = { importCommunicator, verifyAndUpsertCommunicator, deleteCommunicator, - changeCommunicator, - upsertCommunicator, showNotification, switchBoard, replaceBoard, From c5841041bf9ff0c86ecc090ff1a5f9621a0ee7f5 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 18 Jun 2024 17:37:08 -0300 Subject: [PATCH 40/85] Use verifyAndUpsertCommunicator on CommunicatorDialog container functions --- .../CommunicatorDialog.container.js | 80 ++++++++++--------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js index e99efa087..253214a8b 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -6,12 +6,10 @@ import { injectIntl } from 'react-intl'; import shortid from 'shortid'; import API from '../../../api'; import { - editCommunicator, - changeCommunicator, deleteBoardCommunicator, addBoardCommunicator, - upsertCommunicator, - verifyAndUpsertCommunicator + verifyAndUpsertCommunicator, + upsertApiCommunicator } from '../Communicator.actions'; import { deleteBoard, deleteApiBoard } from '../../Board/Board.actions'; import { showNotification } from '../../Notifications/Notifications.actions'; @@ -239,8 +237,7 @@ class CommunicatorDialogContainer extends React.Component { const { createBoard, addBoardCommunicator, - upsertCommunicator, - changeCommunicator, + verifyAndUpsertCommunicator, currentCommunicator, userData, updateApiObjectsNoChild, @@ -282,22 +279,12 @@ class CommunicatorDialogContainer extends React.Component { } createBoard(newBoard); if (!records) { + verifyAndUpsertCommunicator({ ...currentCommunicator }); addBoardCommunicator(newBoard.id); } // Loggedin user? if ('name' in userData && 'email' in userData) { - if (currentCommunicator.email !== userData.email) { - //need to create a new communicator - const communicatorData = { - ...currentCommunicator, - author: userData.name, - email: userData.email, - id: shortid.generate() - }; - upsertCommunicator(communicatorData); - changeCommunicator(communicatorData.id); - } try { this.setState({ loading: true @@ -425,16 +412,24 @@ class CommunicatorDialogContainer extends React.Component { } async updateCommunicatorBoards(boards) { - const { currentCommunicator, verifyAndUpsertCommunicator } = this.props; + const { + userData, + currentCommunicator, + verifyAndUpsertCommunicator, + upsertApiCommunicator + } = this.props; const updatedCommunicatorData = { ...currentCommunicator, boards: boards.map(cb => cb.id) }; - try { - await verifyAndUpsertCommunicator(updatedCommunicatorData); - } catch (err) { - console.error(err.message); + verifyAndUpsertCommunicator(updatedCommunicatorData); + if ('name' in userData && 'email' in userData) { + try { + await upsertApiCommunicator(updatedCommunicatorData); + } catch (err) { + console.error('Error upserting communicator', err); + } } } @@ -474,16 +469,24 @@ class CommunicatorDialogContainer extends React.Component { } async setRootBoard(board) { - const { currentCommunicator, verifyAndUpsertCommunicator } = this.props; + const { + userData, + currentCommunicator, + verifyAndUpsertCommunicator, + upsertApiCommunicator + } = this.props; const updatedCommunicatorData = { ...currentCommunicator, rootBoard: board.id }; + verifyAndUpsertCommunicator(updatedCommunicatorData); try { - await verifyAndUpsertCommunicator(updatedCommunicatorData); + if ('name' in userData && 'email' in userData) { + await upsertApiCommunicator(updatedCommunicatorData); + } } catch (err) { - console.log(err.message); + console.error('Error upserting communicator', err); } } @@ -499,7 +502,8 @@ class CommunicatorDialogContainer extends React.Component { verifyAndUpsertCommunicator, deleteApiBoard, userData, - intl + intl, + upsertApiCommunicator } = this.props; deleteBoard(board.id); @@ -515,14 +519,16 @@ class CommunicatorDialogContainer extends React.Component { ...comm, boards: comm.boards.filter(b => b !== board.id) }; - try { - const changeCommunicator = false; - await verifyAndUpsertCommunicator( - filteredCommunicator, - changeCommunicator - ); - } catch (err) { - console.log(err.message); + + const changeCommunicator = false; + verifyAndUpsertCommunicator(filteredCommunicator, changeCommunicator); + + if ('name' in userData && 'email' in userData) { + try { + await upsertApiCommunicator(filteredCommunicator); + } catch (err) { + console.error('Error upserting communicator', err); + } } } } @@ -617,8 +623,6 @@ const mapStateToProps = ({ board, communicator, language, app }, ownProps) => { }; const mapDispatchToProps = { - editCommunicator, - changeCommunicator, addBoards, replaceBoard, showNotification, @@ -628,11 +632,11 @@ const mapDispatchToProps = { createBoard, updateBoard, addBoardCommunicator, - upsertCommunicator, updateApiObjectsNoChild, updateApiBoard, disableTour, - verifyAndUpsertCommunicator + verifyAndUpsertCommunicator, + upsertApiCommunicator }; export default connect( From 4e0d235ed6648b2abcc5aa25a36b40b99450f9e8 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 18 Jun 2024 17:38:04 -0300 Subject: [PATCH 41/85] Use verifyAndUpsertCommunicator on addBoardsToCommunicator on import container --- .../Settings/Import/Import.container.js | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/Settings/Import/Import.container.js b/src/components/Settings/Import/Import.container.js index ebbc189d1..4c4414f08 100644 --- a/src/components/Settings/Import/Import.container.js +++ b/src/components/Settings/Import/Import.container.js @@ -6,8 +6,7 @@ import shortid from 'shortid'; import { addBoards, changeBoard } from '../../Board/Board.actions'; import { - upsertCommunicator, - changeCommunicator, + upsertApiCommunicator, verifyAndUpsertCommunicator } from '../../Communicator/Communicator.actions'; import { switchBoard } from '../../Board/Board.actions'; @@ -122,7 +121,12 @@ export class ImportContainer extends PureComponent { } async addBoardsToCommunicator(boards) { - const { currentCommunicator, verifyAndUpsertCommunicator } = this.props; + const { + currentCommunicator, + verifyAndUpsertCommunicator, + userData, + upsertApiCommunicator + } = this.props; const communicatorBoards = new Set( currentCommunicator.boards.concat(boards.map(b => b.id)) @@ -132,10 +136,14 @@ export class ImportContainer extends PureComponent { boards: Array.from(communicatorBoards) }; - try { - await verifyAndUpsertCommunicator(communicatorModified); - } catch (e) { - console.error('Error upserting communicator', e); + verifyAndUpsertCommunicator(communicatorModified); + + if ('name' in userData && 'email' in userData) { + try { + await upsertApiCommunicator(communicatorModified); + } catch (err) { + console.error('Error upserting communicator', err); + } } } @@ -225,10 +233,9 @@ const mapDispatchToProps = { addBoards, changeBoard, switchBoard, - upsertCommunicator, - changeCommunicator, showNotification, - verifyAndUpsertCommunicator + verifyAndUpsertCommunicator, + upsertApiCommunicator }; export default connect( From be5f6997cd62b557b648d607a699cd0d2d482f0a Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 18 Jun 2024 17:44:15 -0300 Subject: [PATCH 42/85] Remove log --- src/components/Board/Board.container.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 00e31becc..d4ef6ef6e 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -1681,11 +1681,6 @@ const mapStateToProps = ({ const currentCommunicator = communicator.communicators.find( communicator => communicator.id === activeCommunicatorId ); - console.log( - 'vuelve a definir mapsateToProps', - activeCommunicatorId, - currentCommunicator - ); const activeBoardId = board.activeBoardId; const emptyVoiceAlert = speech.voices.length > 0 && speech.options.voiceURI !== EMPTY_VOICES From f8f0d9d2749b28d351dd923e9da5fa50a9c99ed2 Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 19 Jun 2024 09:09:30 +0200 Subject: [PATCH 43/85] Avoid create API boards if unnecessary default Boards aren't removed --- src/components/Board/Board.reducer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index ceaf7ab86..179a7f93e 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -326,7 +326,8 @@ function boardReducer(state = initialState, action) { } const shouldCreateBoard = - creadBoards[i].id.length < REMOTE_BOARD_ID_LENGTH; + creadBoards[i].id.length < REMOTE_BOARD_ID_LENGTH && + state.boards.unnecessaryDefaultBoardsRemoved; if (shouldCreateBoard) { creadBoards[i].shouldCreateBoard = true; } From 952d81a6ecea64d4a8a6987f512ce601b71d8cf3 Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 19 Jun 2024 09:22:00 +0200 Subject: [PATCH 44/85] mark unnecesaryDefaultBoardsRemoved as true on cleanAllBoards --- src/components/Board/Board.reducer.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index 4e595138d..e7113b11f 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -51,7 +51,8 @@ const initialState = { images: [], isFixed: false, isLiveMode: false, - improvedPhrase: '' + improvedPhrase: '', + unnecesaryDefaultBoardsRemoved: false }; function reconcileBoards(localBoard, remoteBoard) { @@ -253,7 +254,8 @@ function boardReducer(state = initialState, action) { case CLEAN_ALL_BOARDS: return { ...state, - boards: [] + boards: [], + unnecesaryDefaultBoardsRemoved: true }; case CREATE_TILE: return { From 6d48087366581feccb849ca8328c20362c0fb54c Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 19 Jun 2024 09:29:36 +0200 Subject: [PATCH 45/85] Fix var name check length of ids to know if it is local --- src/components/Board/Board.actions.js | 4 ++-- src/components/Board/Board.constants.js | 2 +- src/components/Board/Board.reducer.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 385da6f11..1bc5062f2 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -40,7 +40,7 @@ import { DOWNLOAD_IMAGE_SUCCESS, DOWNLOAD_IMAGE_FAILURE, UNMARK_SHOULD_CREATE_API_BOARD, - REMOTE_BOARD_ID_LENGTH + SHORT_ID_MAX_LENGTH } from './Board.constants'; import API from '../../api'; @@ -762,7 +762,7 @@ export function updateApiMarkedBoards() { throw new Error(e.message); } } - if (board.id.length < REMOTE_BOARD_ID_LENGTH && board.shouldCreateBoard) { + if (board.id.length < SHORT_ID_MAX_LENGTH && board.shouldCreateBoard) { const state = getState(); // TODO - translate name using intl in a redux action diff --git a/src/components/Board/Board.constants.js b/src/components/Board/Board.constants.js index 0dcc20cad..79aae6ef3 100644 --- a/src/components/Board/Board.constants.js +++ b/src/components/Board/Board.constants.js @@ -43,4 +43,4 @@ export const DOWNLOAD_IMAGE_SUCCESS = 'cboard/Board/DOWNLOAD_IMAGE_SUCCESS'; export const DOWNLOAD_IMAGE_FAILURE = 'cboard/Board/DOWNLOAD_IMAGE_FAILURE'; export const DEFAULT_ROWS_NUMBER = 5; export const DEFAULT_COLUMNS_NUMBER = 5; -export const REMOTE_BOARD_ID_LENGTH = 14; +export const SHORT_ID_MAX_LENGTH = 14; diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index 179a7f93e..dc955865a 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -38,7 +38,7 @@ import { DOWNLOAD_IMAGE_SUCCESS, DOWNLOAD_IMAGE_FAILURE, UNMARK_SHOULD_CREATE_API_BOARD, - REMOTE_BOARD_ID_LENGTH + SHORT_ID_MAX_LENGTH } from './Board.constants'; import { LOGOUT, LOGIN_SUCCESS } from '../Account/Login/Login.constants'; @@ -326,7 +326,7 @@ function boardReducer(state = initialState, action) { } const shouldCreateBoard = - creadBoards[i].id.length < REMOTE_BOARD_ID_LENGTH && + creadBoards[i].id.length < SHORT_ID_MAX_LENGTH && state.boards.unnecessaryDefaultBoardsRemoved; if (shouldCreateBoard) { creadBoards[i].shouldCreateBoard = true; From 4319fdabdb8940f6915b81838e1fb46abed94803 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 19 Jun 2024 20:02:55 -0300 Subject: [PATCH 46/85] Fix board data prop on communicator --- src/components/Board/Board.container.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index d4ef6ef6e..1ea4ef4fb 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -508,9 +508,7 @@ export class BoardContainer extends Component { if (communicator.email !== userData.email) { const communicatorData = { ...communicator, - boards: [ - boardData.id === 'root' ? ['root'] : ['root', boardData.id] - ], + boards: boardData.id === 'root' ? ['root'] : ['root', boardData.id], rootBoard: 'root' }; verifyAndUpsertCommunicator(communicatorData); From 5137b06e8974a6e5cc61b6ee2158155241ecb5e3 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 19 Jun 2024 20:05:29 -0300 Subject: [PATCH 47/85] Add fallback value and return on verifyAndUpsertCommunicator --- src/components/Communicator/Communicator.actions.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 91914fb6b..13b12f766 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -188,8 +188,15 @@ export function verifyAndUpsertCommunicator( app: { userData } } = getState(); - if (!communicator) return; - const updatedCommunicatorData = { ...communicator }; + const getActiveCommunicator = getState => { + getState().communicator.communicators.find( + c => c.id === getState().communicator.activeCommunicatorId + ); + }; + + const updatedCommunicatorData = communicator.hasOwnProperty('id') + ? { ...communicator } + : { ...getActiveCommunicator(getState) }; if ( 'name' in userData && @@ -214,7 +221,7 @@ export function verifyAndUpsertCommunicator( if (needToChangeCommunicator) dispatch(changeCommunicator(updatedCommunicatorData.id)); - return; + return updatedCommunicatorData; }; } From 85ec54dd308dea00da32578233db33f270c79436 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 19 Jun 2024 20:09:25 -0300 Subject: [PATCH 48/85] Use returned value to make Api Communicator upsert --- .../CommunicatorDialog.container.js | 21 ++++++++++++------- .../CommunicatorToolbar.container.js | 7 +++++-- .../Settings/Import/Import.container.js | 6 ++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js index 253214a8b..5f7612769 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -423,10 +423,14 @@ class CommunicatorDialogContainer extends React.Component { ...currentCommunicator, boards: boards.map(cb => cb.id) }; - verifyAndUpsertCommunicator(updatedCommunicatorData); + + const upsertedCommunicator = verifyAndUpsertCommunicator( + updatedCommunicatorData + ); + if ('name' in userData && 'email' in userData) { try { - await upsertApiCommunicator(updatedCommunicatorData); + await upsertApiCommunicator(upsertedCommunicator); } catch (err) { console.error('Error upserting communicator', err); } @@ -480,10 +484,12 @@ class CommunicatorDialogContainer extends React.Component { ...currentCommunicator, rootBoard: board.id }; - verifyAndUpsertCommunicator(updatedCommunicatorData); + const upsertedCommunicator = verifyAndUpsertCommunicator( + updatedCommunicatorData + ); try { if ('name' in userData && 'email' in userData) { - await upsertApiCommunicator(updatedCommunicatorData); + await upsertApiCommunicator(upsertedCommunicator); } } catch (err) { console.error('Error upserting communicator', err); @@ -520,12 +526,13 @@ class CommunicatorDialogContainer extends React.Component { boards: comm.boards.filter(b => b !== board.id) }; - const changeCommunicator = false; - verifyAndUpsertCommunicator(filteredCommunicator, changeCommunicator); + const upsertedCommunicator = verifyAndUpsertCommunicator( + filteredCommunicator + ); if ('name' in userData && 'email' in userData) { try { - await upsertApiCommunicator(filteredCommunicator); + await upsertApiCommunicator(upsertedCommunicator); } catch (err) { console.error('Error upserting communicator', err); } diff --git a/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js b/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js index 922f475bd..364672b22 100644 --- a/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js +++ b/src/components/Communicator/CommunicatorToolbar/CommunicatorToolbar.container.js @@ -46,10 +46,13 @@ class CommunicatorContainer extends React.Component { name }; - verifyAndUpsertCommunicator(updatedCommunicatorData); + const upsertedCommunicator = verifyAndUpsertCommunicator( + updatedCommunicatorData + ); + if ('name' in userData && 'email' in userData) { try { - await upsertApiCommunicator(updatedCommunicatorData); + await upsertApiCommunicator(upsertedCommunicator); } catch (err) { console.error('Error upserting communicator', err); } diff --git a/src/components/Settings/Import/Import.container.js b/src/components/Settings/Import/Import.container.js index 4c4414f08..e3b213b1b 100644 --- a/src/components/Settings/Import/Import.container.js +++ b/src/components/Settings/Import/Import.container.js @@ -136,11 +136,13 @@ export class ImportContainer extends PureComponent { boards: Array.from(communicatorBoards) }; - verifyAndUpsertCommunicator(communicatorModified); + const upsertedCommunicator = verifyAndUpsertCommunicator( + communicatorModified + ); if ('name' in userData && 'email' in userData) { try { - await upsertApiCommunicator(communicatorModified); + await upsertApiCommunicator(upsertedCommunicator); } catch (err) { console.error('Error upserting communicator', err); } From 66a9eb25930342ce1b6511a50bafea346961a1fc Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 20 Jun 2024 16:32:06 +0200 Subject: [PATCH 49/85] Increase BOARDS_PAGE_LIMIT from 100 to 1000 --- src/components/Board/Board.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index f06d8db12..307d8cdd4 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -62,7 +62,7 @@ import history from './../../history'; import { improvePhraseAbortController } from '../../api/api'; import shortid from 'shortid'; -const BOARDS_PAGE_LIMIT = 100; +const BOARDS_PAGE_LIMIT = 1000; export function importBoards(boards) { return { From 2b9a33dcef1c6c14be4bcb175ae2d4b0bfc37ad8 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 21 Jun 2024 10:42:56 -0300 Subject: [PATCH 50/85] Replace foreach loop by for of to correctl await the async funtions --- src/components/Board/Board.container.js | 8 ++++---- .../CommunicatorDialog/CommunicatorDialog.container.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 8a01dcc98..f0e024516 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -1327,22 +1327,22 @@ export class BoardContainer extends Component { } //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); } } } } - }); + } } updateBoardReferences(board, newBoard, records) { diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js index e0a91a520..2751e1a0d 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -333,11 +333,11 @@ class CommunicatorDialogContainer extends React.Component { } //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 @@ -345,12 +345,12 @@ class CommunicatorDialogContainer extends React.Component { b => b.id === tile.loadBoard ); if (localBoard) { - this.createBoardsRecursively(localBoard, records); + await this.createBoardsRecursively(localBoard, records); } } } } - }); + } } updateBoardReferences(board, newBoard, records) { From b714ffcdfd15cb29fb94538f07c7f0096f07301d Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 21 Jun 2024 10:45:37 -0300 Subject: [PATCH 51/85] Refactor handleCopyRemoteBoard function to update boards reference before save api changes --- src/components/Board/Board.container.js | 49 ++++++++++++++----------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index f0e024516..13469bc26 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -1212,9 +1212,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) { + 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); @@ -1225,11 +1239,9 @@ export class BoardContainer extends Component { async createBoardsRecursively(board, records) { const { createBoard, - switchBoard, addBoardCommunicator, upsertCommunicator, changeCommunicator, - history, communicator, userData, updateApiObjectsNoChild, @@ -1239,13 +1251,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; } } @@ -1274,6 +1286,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({ @@ -1306,24 +1325,9 @@ 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 @@ -1343,6 +1347,7 @@ export class BoardContainer extends Component { } } } + return newBoard; } updateBoardReferences(board, newBoard, records) { From f1cd3b4ee94da318f1b3a18c9b6d1be6742c2b76 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 21 Jun 2024 10:46:33 -0300 Subject: [PATCH 52/85] Refactor createBoardsRecursively to update boards references before api updates --- .../CommunicatorDialog.container.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js index 2751e1a0d..729951833 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -285,6 +285,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) { let createCommunicator = false; @@ -321,12 +328,6 @@ 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; From 71acfb542f86cb599f026d4c1ecccbd09ba3bb2f Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 21 Jun 2024 15:22:24 -0300 Subject: [PATCH 53/85] Comprobe if copiedBoard has id prop --- src/components/Board/Board.container.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 13469bc26..aa88be5a0 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -1217,7 +1217,7 @@ export class BoardContainer extends Component { const copiedBoard = await this.createBoardsRecursively( this.state.copyPublicBoard ); - if (!!copiedBoard) { + if (!copiedBoard?.id) { throw new Error('Board not copied correctly'); } switchBoard(copiedBoard.id); From 74ee5db028b5c2f47bc4a49c84fbeb71ad6bbca9 Mon Sep 17 00:00:00 2001 From: tomivm Date: Tue, 25 Jun 2024 14:09:49 +0200 Subject: [PATCH 54/85] Fix board reducer test --- src/components/Board/__tests__/Board.reducer.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Board/__tests__/Board.reducer.test.js b/src/components/Board/__tests__/Board.reducer.test.js index ebd19708c..ebec1f4be 100644 --- a/src/components/Board/__tests__/Board.reducer.test.js +++ b/src/components/Board/__tests__/Board.reducer.test.js @@ -53,7 +53,8 @@ const initialState = { isFixed: false, images: [], isLiveMode: false, - improvedPhrase: '' + improvedPhrase: '', + unnecesaryDefaultBoardsRemoved: false }; describe('reducer', () => { From 4bcd5488e7e911940da52890af63c142e631cb8d Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 26 Jun 2024 17:04:24 +0200 Subject: [PATCH 55/85] fix getActiveComunnicator function --- src/components/Communicator/Communicator.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 13b12f766..221d30c6d 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -189,7 +189,7 @@ export function verifyAndUpsertCommunicator( } = getState(); const getActiveCommunicator = getState => { - getState().communicator.communicators.find( + return getState().communicator.communicators.find( c => c.id === getState().communicator.activeCommunicatorId ); }; From 150d7b620d791ad4cebbc6545ad03bd3703df03c Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 26 Jun 2024 17:06:12 +0200 Subject: [PATCH 56/85] Concat default boards Ids in a blacklist on create API board --- src/components/Board/Board.actions.js | 10 ++++-- .../Communicator/Communicator.actions.js | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 292485659..0089c8849 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -52,10 +52,15 @@ import { upsertApiCommunicator, updateDefaultBoardsIncluded, addDefaultBoardIncluded, - verifyAndUpsertCommunicator + verifyAndUpsertCommunicator, + concatDefaultBoardIdToBlacklist } from '../Communicator/Communicator.actions'; import { isAndroid, writeCvaFile } from '../../cordova-util'; -import { ALL_DEFAULT_BOARDS, DEFAULT_BOARDS } from '../../helpers'; +import { + ALL_DEFAULT_BOARDS, + DEFAULT_BOARDS, + isRemoteIdChecker +} from '../../helpers'; import history from './../../history'; import { improvePhraseAbortController } from '../../api/api'; @@ -522,6 +527,7 @@ export function createApiBoard(boardData, boardId) { }; return API.createBoard(boardData) .then(res => { + dispatch(concatDefaultBoardIdToBlacklist(boardId)); dispatch(createApiBoardSuccess(res, boardId)); return res; }) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 221d30c6d..e42490e73 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -291,3 +291,34 @@ export function updateDefaultBoardsIncluded(boardAlreadyIncludedData) { defaultBoardsIncluded: boardAlreadyIncludedData }; } + +export function concatDefaultBoardIdToBlacklist(boardId) { + const getActiveCommunicator = getState => { + return getState().communicator.communicators.find( + c => c.id === getState().communicator.activeCommunicatorId + ); + }; + return (dispatch, getState) => { + const updatedCommunicatorData = { ...getActiveCommunicator(getState) }; + console.log(updatedCommunicatorData); + + const concatBoardIdIfNecessary = () => { + if (!updatedCommunicatorData?.defaultBoardBlackList.includes(boardId)) + return updatedCommunicatorData?.defaultBoardBlackList.concat(boardId); + return updatedCommunicatorData?.defaultBoardBlackList; + }; + + updatedCommunicatorData.defaultBoardBlackList = updatedCommunicatorData?.defaultBoardBlackList + ? concatBoardIdIfNecessary() + : [boardId]; + + dispatch(verifyAndUpsertCommunicator(updatedCommunicatorData)); + return dispatch(upsertApiCommunicator(updatedCommunicatorData)) + .then(() => { + return updatedCommunicatorData?.defaultBoardBlackList; + }) + .catch(e => { + console.error(e.message); + }); + }; +} From aa38a14f1da4a4a5d8186796d145817fc28bf31a Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 26 Jun 2024 17:07:12 +0200 Subject: [PATCH 57/85] remove unnecessary import --- src/components/Board/Board.actions.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 0089c8849..47700b7f2 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -56,11 +56,7 @@ import { concatDefaultBoardIdToBlacklist } from '../Communicator/Communicator.actions'; import { isAndroid, writeCvaFile } from '../../cordova-util'; -import { - ALL_DEFAULT_BOARDS, - DEFAULT_BOARDS, - isRemoteIdChecker -} from '../../helpers'; +import { ALL_DEFAULT_BOARDS, DEFAULT_BOARDS } from '../../helpers'; import history from './../../history'; import { improvePhraseAbortController } from '../../api/api'; From 54aa14d8b52710519e49b4a9d86fe8a43d68ba01 Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 26 Jun 2024 18:25:52 +0200 Subject: [PATCH 58/85] await for concatDefaultBoardIdToBlacklist --- src/components/Board/Board.actions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 47700b7f2..b1aea19d2 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -522,8 +522,8 @@ export function createApiBoard(boardData, boardId) { isPublic: false }; return API.createBoard(boardData) - .then(res => { - dispatch(concatDefaultBoardIdToBlacklist(boardId)); + .then(async res => { + await dispatch(concatDefaultBoardIdToBlacklist(boardId)); dispatch(createApiBoardSuccess(res, boardId)); return res; }) From b18c8a2f5ce0f78826373bf40a3558206af40ebf Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 26 Jun 2024 19:04:53 +0200 Subject: [PATCH 59/85] Remove Boards from the blacklist on update API objects --- src/components/Board/Board.actions.js | 10 +++++++++- src/components/Board/Board.constants.js | 1 + src/components/Board/Board.reducer.js | 10 +++++++++- src/components/Communicator/Communicator.actions.js | 10 +++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index b1aea19d2..6e467c89d 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -39,7 +39,8 @@ import { DOWNLOAD_IMAGES_STARTED, DOWNLOAD_IMAGE_SUCCESS, DOWNLOAD_IMAGE_FAILURE, - CLEAN_ALL_BOARDS + CLEAN_ALL_BOARDS, + REMOVE_BOARDS_FROM_LIST } from './Board.constants'; import API from '../../api'; @@ -885,3 +886,10 @@ export function addNecessaryDefaultBoardsFor(boardIdToAdd) { } }; } + +export function removeBoardsFromList(blacklist = []) { + return { + type: REMOVE_BOARDS_FROM_LIST, + blacklist + }; +} diff --git a/src/components/Board/Board.constants.js b/src/components/Board/Board.constants.js index 297649f99..d361764d4 100644 --- a/src/components/Board/Board.constants.js +++ b/src/components/Board/Board.constants.js @@ -3,6 +3,7 @@ export const ADD_BOARDS = 'cboard/Board/ADD_BOARDS'; export const CREATE_BOARD = 'cboard/Board/CREATE_BOARD'; export const UPDATE_BOARD = 'cboard/Board/UPDATE_BOARD'; export const DELETE_BOARD = 'cboard/Board/DELETE_BOARD'; +export const REMOVE_BOARDS_FROM_LIST = 'cboard/Board/REMOVE_BOARDS_FROM_LIST'; export const CHANGE_BOARD = 'cboard/Board/CHANGE_BOARD'; export const REPLACE_BOARD = 'cboard/Board/REPLACE_BOARD'; export const SWITCH_BOARD = 'cboard/Board/SWITCH_BOARD'; diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index e7113b11f..7426342b1 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -37,7 +37,8 @@ import { DOWNLOAD_IMAGES_STARTED, DOWNLOAD_IMAGE_SUCCESS, DOWNLOAD_IMAGE_FAILURE, - CLEAN_ALL_BOARDS + CLEAN_ALL_BOARDS, + REMOVE_BOARDS_FROM_LIST } from './Board.constants'; import { LOGOUT, LOGIN_SUCCESS } from '../Account/Login/Login.constants'; @@ -251,6 +252,13 @@ function boardReducer(state = initialState, action) { board => action.boardId.indexOf(board.id) === -1 ) }; + case REMOVE_BOARDS_FROM_LIST: + return { + ...state, + boards: state.boards.filter( + board => !action.blacklist?.includes(board.id) + ) + }; case CLEAN_ALL_BOARDS: return { ...state, diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index e42490e73..01a732e92 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -22,6 +22,7 @@ import { import { defaultCommunicatorID } from './Communicator.reducer'; import API from '../../api'; import shortid from 'shortid'; +import { removeBoardsFromList } from '../Board/Board.actions'; export function importCommunicator(communicator) { return { @@ -230,10 +231,17 @@ export function verifyAndUpsertCommunicator( */ export function getApiMyCommunicators() { - return dispatch => { + return (dispatch, getState) => { dispatch(getApiMyCommunicatorsStarted()); return API.getCommunicators() .then(res => { + const activeCommunicator = + res.data.find( + communicator => + communicator.id === getState().communicator.activeCommunicator + ) ?? res.data[0]; + const defaultBoardBlackList = activeCommunicator?.defaultBoardBlackList; + dispatch(removeBoardsFromList(defaultBoardBlackList)); dispatch(getApiMyCommunicatorsSuccess(res)); return res; }) From ed5ec3867404907b2e637ba29068777950839bcb Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 26 Jun 2024 17:45:02 -0300 Subject: [PATCH 60/85] Add return statement to getActiveCommunicator --- src/components/Communicator/Communicator.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 13b12f766..221d30c6d 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -189,7 +189,7 @@ export function verifyAndUpsertCommunicator( } = getState(); const getActiveCommunicator = getState => { - getState().communicator.communicators.find( + return getState().communicator.communicators.find( c => c.id === getState().communicator.activeCommunicatorId ); }; From 26d968968a2561c1f9ec3403e0873bf47dde524c Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 27 Jun 2024 13:19:32 +0200 Subject: [PATCH 61/85] Remove staff to clean all boards on login --- src/components/Account/Login/Login.actions.js | 16 +--------------- src/components/Board/Board.actions.js | 10 ---------- src/components/Board/Board.constants.js | 1 - src/components/Board/Board.reducer.js | 10 +--------- .../Board/__tests__/Board.reducer.test.js | 3 +-- 5 files changed, 3 insertions(+), 37 deletions(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index 067b4b265..a0d6bd9a8 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -1,10 +1,6 @@ import API from '../../../api'; import { LOGIN_SUCCESS, LOGOUT } from './Login.constants'; -import { - addBoards, - cleanAllBoards, - addNecessaryDefaultBoardsFor -} from '../../Board/Board.actions'; +import { addBoards } from '../../Board/Board.actions'; import { changeVoice, changePitch, @@ -177,17 +173,7 @@ export function login({ email, password, activatedData }, type = 'local') { }) .filter(b => b !== null) ); - dispatch(cleanAllBoards()); dispatch(addBoards(apiBoards)); - const userDefaultBoardsIncluded = - currentCommunicator.defaultBoardsIncluded; - if (userDefaultBoardsIncluded) { - userDefaultBoardsIncluded.forEach(({ homeBoard }) => { - dispatch(addNecessaryDefaultBoardsFor(homeBoard)); - }); - } else { - dispatch(addNecessaryDefaultBoardsFor(currentCommunicator.rootBoard)); - } if (type === 'local') { dispatch( disableTour({ diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 315194ccd..c336267b7 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -502,10 +502,6 @@ export function getApiMyBoards() { }) .then(res => { dispatch(getApiMyBoardsSuccess(res)); - const newBoards = res.data; - newBoards?.forEach(({ id }) => { - dispatch(addNecessaryDefaultBoardsFor(id)); - }); return res; }) .catch(err => { @@ -831,12 +827,6 @@ export function updateApiObjects( }; } -export function cleanAllBoards() { - return { - type: CLEAN_ALL_BOARDS - }; -} - export function addNecessaryDefaultBoardsFor(boardIdToAdd) { return (dispatch, getState) => { const checkedBoardsIds = []; diff --git a/src/components/Board/Board.constants.js b/src/components/Board/Board.constants.js index d361764d4..4365c968e 100644 --- a/src/components/Board/Board.constants.js +++ b/src/components/Board/Board.constants.js @@ -20,7 +20,6 @@ export const CHANGE_IMPROVED_PHRASE = 'cboard/Board/CHANGE_IMPROVED_PHRASE'; export const CHANGE_LIVE_MODE = 'cboard/Board/CHANGE_LIVE_MODE'; export const HISTORY_REMOVE_BOARD = 'cboard/Board/HISTORY_REMOVE_BOARD'; export const UNMARK_BOARD = 'cboard/Board/UNMARK_BOARD'; -export const CLEAN_ALL_BOARDS = 'cboard/Board/CLEAN_ALL_BOARDS'; export const CREATE_API_BOARD_SUCCESS = 'cboard/Board/CREATE_API_BOARD_SUCCESS'; export const CREATE_API_BOARD_FAILURE = 'cboard/Board/CREATE_API_BOARD_FAILURE'; export const CREATE_API_BOARD_STARTED = 'cboard/Board/CREATE_API_BOARD_STARTED'; diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index 7426342b1..d1f669d3d 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -37,7 +37,6 @@ import { DOWNLOAD_IMAGES_STARTED, DOWNLOAD_IMAGE_SUCCESS, DOWNLOAD_IMAGE_FAILURE, - CLEAN_ALL_BOARDS, REMOVE_BOARDS_FROM_LIST } from './Board.constants'; import { LOGOUT, LOGIN_SUCCESS } from '../Account/Login/Login.constants'; @@ -52,8 +51,7 @@ const initialState = { images: [], isFixed: false, isLiveMode: false, - improvedPhrase: '', - unnecesaryDefaultBoardsRemoved: false + improvedPhrase: '' }; function reconcileBoards(localBoard, remoteBoard) { @@ -259,12 +257,6 @@ function boardReducer(state = initialState, action) { board => !action.blacklist?.includes(board.id) ) }; - case CLEAN_ALL_BOARDS: - return { - ...state, - boards: [], - unnecesaryDefaultBoardsRemoved: true - }; case CREATE_TILE: return { ...state, diff --git a/src/components/Board/__tests__/Board.reducer.test.js b/src/components/Board/__tests__/Board.reducer.test.js index ebec1f4be..ebd19708c 100644 --- a/src/components/Board/__tests__/Board.reducer.test.js +++ b/src/components/Board/__tests__/Board.reducer.test.js @@ -53,8 +53,7 @@ const initialState = { isFixed: false, images: [], isLiveMode: false, - improvedPhrase: '', - unnecesaryDefaultBoardsRemoved: false + improvedPhrase: '' }; describe('reducer', () => { From 9d4659cb0f4580a7568e0f3653b762b119cb64d2 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 27 Jun 2024 13:56:30 +0200 Subject: [PATCH 62/85] remove unnecessary stuff to addNecessaryDefaultBoardsFor --- src/components/Board/Board.actions.js | 57 ++----------------------- src/components/Board/Board.container.js | 29 ++++++++----- 2 files changed, 23 insertions(+), 63 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index c336267b7..dce3a2875 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -39,7 +39,6 @@ import { DOWNLOAD_IMAGES_STARTED, DOWNLOAD_IMAGE_SUCCESS, DOWNLOAD_IMAGE_FAILURE, - CLEAN_ALL_BOARDS, REMOVE_BOARDS_FROM_LIST } from './Board.constants'; @@ -57,7 +56,7 @@ import { concatDefaultBoardIdToBlacklist } from '../Communicator/Communicator.actions'; import { isAndroid, writeCvaFile } from '../../cordova-util'; -import { ALL_DEFAULT_BOARDS, DEFAULT_BOARDS } from '../../helpers'; +import { DEFAULT_BOARDS } from '../../helpers'; import history from './../../history'; import { improvePhraseAbortController } from '../../api/api'; @@ -154,7 +153,9 @@ export function changeDefaultBoard(selectedBoardNameOnJson) { const switchActiveBoard = homeBoardId => { if (homeBoardId) { - dispatch(addNecessaryDefaultBoardsFor(homeBoardId)); + const storeBoards = getState().board.boards; + const board = storeBoards.find(board => board.id === homeBoardId); + if (!board) addBoards([board]); const goTo = `/board/${homeBoardId}`; dispatch(switchBoard(homeBoardId)); @@ -827,56 +828,6 @@ export function updateApiObjects( }; } -export function addNecessaryDefaultBoardsFor(boardIdToAdd) { - return (dispatch, getState) => { - const checkedBoardsIds = []; - const addNecessaryBoards = ({ dispatch, getState, necessaryBoardId }) => { - const board = getState().board.boards.find( - board => board?.id === necessaryBoardId - ); - const checkLoadBoards = board => { - checkedBoardsIds.push(board.id); - board.tiles.forEach(tile => { - if ( - tile.loadBoard - // !getState().board.boards.some(board => board.id === tile.loadBoard) - ) { - if (!checkedBoardsIds.includes(tile.loadBoard)) { - addNecessaryBoards({ - dispatch, - getState, - necessaryBoardId: tile.loadBoard - }); - } - } - }); - }; - if (board) { - checkLoadBoards(board); - return; - } - - ALL_DEFAULT_BOARDS.some(defaultBoard => { - if (defaultBoard.id === necessaryBoardId) { - dispatch(addBoards([defaultBoard])); - checkLoadBoards(defaultBoard); - return true; - } - return false; - }); - }; - try { - addNecessaryBoards({ - dispatch, - getState, - necessaryBoardId: boardIdToAdd - }); - } catch (e) { - console.error(e); - } - }; -} - export function removeBoardsFromList(blacklist = []) { return { type: REMOVE_BOARDS_FROM_LIST, diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 765b43a37..162b8e4de 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -47,8 +47,7 @@ import { downloadImages, createApiBoard, upsertApiBoard, - changeDefaultBoard, - addNecessaryDefaultBoardsFor + changeDefaultBoard } from './Board.actions'; import { addBoardCommunicator, @@ -222,8 +221,7 @@ export class BoardContainer extends Component { changeBoard, userData, history, - getApiObjects, - addNecessaryDefaultBoardsFor + getApiObjects //downloadImages } = this.props; @@ -277,12 +275,12 @@ export class BoardContainer extends Component { if (!boardExists) { // try the root board const homeBoard = communicator.rootBoard; - if (ALL_DEFAULT_BOARDS.map(({ id }) => id).includes(homeBoard)) - addNecessaryDefaultBoardsFor(homeBoard); boardExists = boards.find(b => b.id === homeBoard); if (!boardExists) { if (isRemoteIdChecker(homeBoard)) boardExists = this.tryRemoteBoard(homeBoard); + if (!boardExists) + boardExists = this.addDefaultBoardIfnecessary(homeBoard); if (!boardExists) boardExists = boards.find(b => b.id !== ''); } } @@ -885,8 +883,8 @@ export class BoardContainer extends Component { if ( ALL_DEFAULT_BOARDS.map(({ id }) => id).includes(loadBoardSearched) ) { - addNecessaryDefaultBoardsFor(loadBoardSearched); - const nextBoard = findBoardOnStore(loadBoardFinder); + this.addDefaultBoardIfnecessary(loadBoardSearched); + const nextBoard = findBoardOnStore(loadBoardSearched); if (nextBoard) return nextBoard; } }; @@ -1528,6 +1526,18 @@ export class BoardContainer extends Component { : []; }; + addDefaultBoardIfnecessary = boardId => { + const { boards, addBoards } = this.props; + if (!boards.find(b => b.id === boardId)) { + const board = ALL_DEFAULT_BOARDS.find(({ id }) => id === boardId); + if (board) { + addBoards([board]); + return board; + } + return; + } + }; + render() { const { navHistory, @@ -1758,8 +1768,7 @@ const mapDispatchToProps = { createApiBoard, upsertApiBoard, changeDefaultBoard, - verifyAndUpsertCommunicator, - addNecessaryDefaultBoardsFor + verifyAndUpsertCommunicator }; export default connect( From 2bf7bd11e1f6c7a1745832e5bac398da55b4c587 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 27 Jun 2024 14:27:22 +0200 Subject: [PATCH 63/85] edite the 'check createApiBoard' test to work with new actions --- src/components/Board/__tests__/Board.actions.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Board/__tests__/Board.actions.test.js b/src/components/Board/__tests__/Board.actions.test.js index c9743e001..3027b06db 100644 --- a/src/components/Board/__tests__/Board.actions.test.js +++ b/src/components/Board/__tests__/Board.actions.test.js @@ -318,7 +318,7 @@ describe('actions', () => { boardId: '12345678901234567', type: 'cboard/Board/CREATE_API_BOARD_SUCCESS' }; - expect(actions[1]).toEqual(dataResp); + expect(actions[5]).toEqual(dataResp); expect(data).toEqual(mockBoard); }) .catch(e => { From 01a16680a5e94448bf538531ccc709dcf5df157b Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 27 Jun 2024 14:39:16 +0200 Subject: [PATCH 64/85] Add prevention to only include default board ids to the blacklist --- src/components/Communicator/Communicator.actions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 01a732e92..a54d9421d 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -23,6 +23,7 @@ import { defaultCommunicatorID } from './Communicator.reducer'; import API from '../../api'; import shortid from 'shortid'; import { removeBoardsFromList } from '../Board/Board.actions'; +import { ALL_DEFAULT_BOARDS } from '../../helpers'; export function importCommunicator(communicator) { return { @@ -307,8 +308,8 @@ export function concatDefaultBoardIdToBlacklist(boardId) { ); }; return (dispatch, getState) => { + if (!ALL_DEFAULT_BOARDS.includes(boardId)) return; const updatedCommunicatorData = { ...getActiveCommunicator(getState) }; - console.log(updatedCommunicatorData); const concatBoardIdIfNecessary = () => { if (!updatedCommunicatorData?.defaultBoardBlackList.includes(boardId)) From a1f9f4e9c20d46f6e4623af6535100992ecc9181 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 27 Jun 2024 14:44:38 +0200 Subject: [PATCH 65/85] improve CREATE_API_BOARD_SUCCESS test to find action --- src/components/Board/__tests__/Board.actions.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Board/__tests__/Board.actions.test.js b/src/components/Board/__tests__/Board.actions.test.js index 3027b06db..68f44024e 100644 --- a/src/components/Board/__tests__/Board.actions.test.js +++ b/src/components/Board/__tests__/Board.actions.test.js @@ -318,7 +318,10 @@ describe('actions', () => { boardId: '12345678901234567', type: 'cboard/Board/CREATE_API_BOARD_SUCCESS' }; - expect(actions[5]).toEqual(dataResp); + const successAction = actions.find( + action => action.type === types.CREATE_API_BOARD_SUCCESS + ); + expect(successAction).toEqual(dataResp); expect(data).toEqual(mockBoard); }) .catch(e => { From 2a745364b0104c4df82a4ec0f5275b571d33b7f9 Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 28 Jun 2024 11:46:28 +0200 Subject: [PATCH 66/85] Avoid the use of a state to prevent create Boards --- src/components/Board/Board.reducer.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index dc955865a..4f36098ba 100644 --- a/src/components/Board/Board.reducer.js +++ b/src/components/Board/Board.reducer.js @@ -326,8 +326,7 @@ function boardReducer(state = initialState, action) { } const shouldCreateBoard = - creadBoards[i].id.length < SHORT_ID_MAX_LENGTH && - state.boards.unnecessaryDefaultBoardsRemoved; + creadBoards[i].id.length < SHORT_ID_MAX_LENGTH; if (shouldCreateBoard) { creadBoards[i].shouldCreateBoard = true; } From 1d8256c735d493fc6b70436f230a517310995009 Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 28 Jun 2024 15:18:13 +0200 Subject: [PATCH 67/85] use Last communicator if active communicator is not finded --- src/components/Communicator/Communicator.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index a54d9421d..2c37fc49e 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -240,7 +240,7 @@ export function getApiMyCommunicators() { res.data.find( communicator => communicator.id === getState().communicator.activeCommunicator - ) ?? res.data[0]; + ) ?? res.data[res.data.length - 1]; const defaultBoardBlackList = activeCommunicator?.defaultBoardBlackList; dispatch(removeBoardsFromList(defaultBoardBlackList)); dispatch(getApiMyCommunicatorsSuccess(res)); From 27ca47e7a8cb8843a6a613e4b9c1f00c64ef9edd Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 28 Jun 2024 15:33:07 +0200 Subject: [PATCH 68/85] fix action to include only default board ids in the blacklist --- src/components/Communicator/Communicator.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 2c37fc49e..e8bad1684 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -308,7 +308,7 @@ export function concatDefaultBoardIdToBlacklist(boardId) { ); }; return (dispatch, getState) => { - if (!ALL_DEFAULT_BOARDS.includes(boardId)) return; + if (!ALL_DEFAULT_BOARDS.map(({ id }) => id).includes(boardId)) return; const updatedCommunicatorData = { ...getActiveCommunicator(getState) }; const concatBoardIdIfNecessary = () => { From ef123c47af8e2362a3bd0575651f0253fc2a41fb Mon Sep 17 00:00:00 2001 From: tomivm Date: Fri, 28 Jun 2024 17:41:05 +0200 Subject: [PATCH 69/85] fix breaking changes caused by change at main over update Api action --- src/components/Board/Board.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 385fbd4f2..6925b23e8 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -772,7 +772,7 @@ export function updateApiMarkedBoards() { dispatch(updateBoard(boardData)); try { const boardId = await dispatch( - updateApiObjectsNoChild(boardData, false, true) + updateApiObjectsNoChild(boardData, true) ); dispatch( replaceBoard({ ...boardData }, { ...boardData, id: boardId }) From c49a4a7afefcb05db171746cc015646358b9bcd6 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Sun, 30 Jun 2024 20:34:29 -0300 Subject: [PATCH 70/85] Add lastEdited prop on communicator modifications --- .../Communicator/Communicator.reducer.js | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/Communicator/Communicator.reducer.js b/src/components/Communicator/Communicator.reducer.js index cadca19ef..0b5eefb84 100644 --- a/src/components/Communicator/Communicator.reducer.js +++ b/src/components/Communicator/Communicator.reducer.js @@ -19,9 +19,11 @@ import { UPDATE_API_COMMUNICATOR_STARTED, GET_API_MY_COMMUNICATORS_SUCCESS, GET_API_MY_COMMUNICATORS_FAILURE, + GET_API_MY_COMMUNICATORS_STARTED, GET_API_MY_COMMUNICATORS_STARTED } from './Communicator.constants'; import { LOGIN_SUCCESS, LOGOUT } from '../Account/Login/Login.constants'; +import moment from 'moment'; export const defaultCommunicatorID = 'cboard_default'; const initialState = { @@ -55,9 +57,13 @@ function communicatorReducer(state = initialState, action) { }; case CREATE_COMMUNICATOR: + const newCommunicator = { + ...action.payload, + lastEdited: moment().format() + }; return { ...state, - communicators: state.communicators.concat(action.payload) + communicators: state.communicators.concat(newCommunicator) }; case EDIT_COMMUNICATOR: @@ -67,7 +73,11 @@ function communicatorReducer(state = initialState, action) { let newState = { ...state }; if (communicatorIndex >= 0) { - newState.communicators[communicatorIndex] = action.payload; + const updatedCommunicator = { + ...action.payload, + lastEdited: moment().format() + }; + newState.communicators[communicatorIndex] = updatedCommunicator; } return newState; @@ -96,6 +106,7 @@ function communicatorReducer(state = initialState, action) { if (index !== -1) { const updatedCommunicators = [...state.communicators]; updatedCommunicators[index].boards.push(action.boardId); + updatedCommunicators.lastEdited = moment().format(); return { ...state, communicators: updatedCommunicators @@ -112,6 +123,7 @@ function communicatorReducer(state = initialState, action) { const bindex = activeCommunicator.boards.indexOf(action.boardId); if (bindex !== -1) { dupdatedCommunicators[index].boards.splice(bindex, 1); + dupdatedCommunicators[index].lastEdited = moment().format(); return { ...state, communicators: dupdatedCommunicators @@ -135,6 +147,7 @@ function communicatorReducer(state = initialState, action) { 1, action.nextBoardId ); + updatedCommunicators[index].lastEdited = moment().format(); return { ...state, communicators: updatedCommunicators @@ -163,6 +176,7 @@ function communicatorReducer(state = initialState, action) { updatedCommunicators[ index ].defaultBoardsIncluded = defaultBoardsIncluded; + updatedCommunicators[index].lastEdited = moment().format(); return { ...state, @@ -179,6 +193,7 @@ function communicatorReducer(state = initialState, action) { const updatedCommunicators = [...state.communicators]; updatedCommunicators[index].defaultBoardsIncluded = action.defaultBoardsIncluded; + updatedCommunicators[index].lastEdited = moment().format(); return { ...state, @@ -201,7 +216,8 @@ function communicatorReducer(state = initialState, action) { communicator.id === action.communicatorId ? { ...communicator, id: action.communicator.id } : communicator - ) + ), + lastEdited: action.communicator.lastEdited }; case CREATE_API_COMMUNICATOR_FAILURE: return { @@ -216,7 +232,8 @@ function communicatorReducer(state = initialState, action) { case UPDATE_API_COMMUNICATOR_SUCCESS: return { ...state, - isFetching: false + isFetching: false, + lastEdited: action.communicator.lastEdited }; case UPDATE_API_COMMUNICATOR_FAILURE: return { From 4048b6b24ce30234153fc5fdda76d1cfd48f6334 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Sun, 30 Jun 2024 20:35:35 -0300 Subject: [PATCH 71/85] Refactor GET_API_MY_COMMUNICATORS_SUCCESS reducer --- .../Communicator/Communicator.reducer.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/components/Communicator/Communicator.reducer.js b/src/components/Communicator/Communicator.reducer.js index 0b5eefb84..83b18d3a1 100644 --- a/src/components/Communicator/Communicator.reducer.js +++ b/src/components/Communicator/Communicator.reducer.js @@ -246,25 +246,9 @@ function communicatorReducer(state = initialState, action) { isFetching: true }; case GET_API_MY_COMMUNICATORS_SUCCESS: - let flag = false; - const myCommunicators = [...state.communicators]; - for (let i = 0; i < action.communicators.data.length; i++) { - for (let j = 0; j < myCommunicators.length; j++) { - if (myCommunicators[j].id === action.communicators.data[i].id) { - myCommunicators[j].boards = action.communicators.data[i].boards; - flag = true; - break; - } - } - if (!flag) { - myCommunicators.push(action.communicators.data[i]); - flag = false; - } - } return { ...state, - isFetching: false, - communicators: myCommunicators + isFetching: false }; case GET_API_MY_COMMUNICATORS_FAILURE: return { From 4d30a8aed5443d919ddc57b3a03461779e306697 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Sun, 30 Jun 2024 20:37:18 -0300 Subject: [PATCH 72/85] Add sync communicactor action and reducer --- .../Communicator/Communicator.actions.js | 70 ++++++++++++++++++- .../Communicator/Communicator.constants.js | 1 + .../Communicator/Communicator.reducer.js | 9 ++- 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 221d30c6d..6748486e0 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -17,11 +17,13 @@ import { UPDATE_API_COMMUNICATOR_STARTED, GET_API_MY_COMMUNICATORS_SUCCESS, GET_API_MY_COMMUNICATORS_FAILURE, - GET_API_MY_COMMUNICATORS_STARTED + GET_API_MY_COMMUNICATORS_STARTED, + SYNC_COMMUNICATORS } from './Communicator.constants'; import { defaultCommunicatorID } from './Communicator.reducer'; import API from '../../api'; import shortid from 'shortid'; +import moment from 'moment'; export function importCommunicator(communicator) { return { @@ -230,12 +232,15 @@ export function verifyAndUpsertCommunicator( */ export function getApiMyCommunicators() { - return dispatch => { + return async dispatch => { dispatch(getApiMyCommunicatorsStarted()); return API.getCommunicators() .then(res => { dispatch(getApiMyCommunicatorsSuccess(res)); - return res; + + return dispatch(syncCommunicators(res.data)).catch(e => { + console.error(e); + }); }) .catch(err => { dispatch(getApiMyCommunicatorsFailure(err.message)); @@ -291,3 +296,62 @@ export function updateDefaultBoardsIncluded(boardAlreadyIncludedData) { defaultBoardsIncluded: boardAlreadyIncludedData }; } + +export function syncCommunicators(remoteCommunicators) { + const reconcileCommunicators = (local, remote) => { + if (local.lastEdited && remote.lastEdited) { + if (moment(local.lastEdited).isAfter(remote.lastEdited)) { + console.log('comm local is after remote', local); + return local; + } + if (moment(local.lastEdited).isBefore(remote.lastEdited)) { + console.log('Comm local is before remote', remote); + return remote; + } + if (moment(local.lastEdited).isSame(remote.lastEdited)) { + console.log('Comm sync isSame', local); + return remote; + } + } + console.log('no entro'); + return remote; + }; + + return async (dispatch, getState) => { + const localCommunicators = getState().communicator.communicators; + + for (const remote of remoteCommunicators) { + const localIndex = localCommunicators.findIndex( + local => local.id === remote.id + ); + + if (localIndex !== -1) { + // If the communicator exists locally, reconcile the two + const reconciled = reconcileCommunicators( + localCommunicators[localIndex], + remote + ); + if (reconciled === localCommunicators[localIndex]) { + // Local is more recent, update the server + try { + const res = await dispatch( + updateApiCommunicator(localCommunicators[localIndex]) + ); + localCommunicators[localIndex] = res; + } catch (e) { + console.error(e); + } + } else { + localCommunicators[localIndex] = reconciled; + } + } else { + // If the communicator does not exist locally, add it + localCommunicators.push(remote); + } + } + dispatch({ + type: SYNC_COMMUNICATORS, + communicators: localCommunicators + }); + }; +} diff --git a/src/components/Communicator/Communicator.constants.js b/src/components/Communicator/Communicator.constants.js index 3caa635b6..6b681e9a2 100644 --- a/src/components/Communicator/Communicator.constants.js +++ b/src/components/Communicator/Communicator.constants.js @@ -31,3 +31,4 @@ export const GET_API_MY_COMMUNICATORS_FAILURE = 'cboard/Communicator/GET_API_MY_COMMUNICATORS_FAILURE'; export const GET_API_MY_COMMUNICATORS_STARTED = 'cboard/Communicator/GET_API_MY_COMMUNICATORS_STARTED'; +export const SYNC_COMMUNICATORS = 'Communicator/SYNC_COMMUNICATORS'; diff --git a/src/components/Communicator/Communicator.reducer.js b/src/components/Communicator/Communicator.reducer.js index 83b18d3a1..8f6158cde 100644 --- a/src/components/Communicator/Communicator.reducer.js +++ b/src/components/Communicator/Communicator.reducer.js @@ -20,7 +20,7 @@ import { GET_API_MY_COMMUNICATORS_SUCCESS, GET_API_MY_COMMUNICATORS_FAILURE, GET_API_MY_COMMUNICATORS_STARTED, - GET_API_MY_COMMUNICATORS_STARTED + SYNC_COMMUNICATORS } from './Communicator.constants'; import { LOGIN_SUCCESS, LOGOUT } from '../Account/Login/Login.constants'; import moment from 'moment'; @@ -260,6 +260,13 @@ function communicatorReducer(state = initialState, action) { ...state, isFetching: true }; + case SYNC_COMMUNICATORS: + return { + ...state, + communicators: action.communicators, + activeCommunicatorId: + action.communicators[action.communicators.length - 1].id + }; default: return state; } From 63a01e8bf9020695d4a1696e4c5254d4dfe4a7a2 Mon Sep 17 00:00:00 2001 From: tomivm Date: Mon, 1 Jul 2024 17:27:34 +0200 Subject: [PATCH 73/85] Avoid unnecessary call to API --- src/components/Communicator/Communicator.actions.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index e8bad1684..b06a79751 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -321,13 +321,6 @@ export function concatDefaultBoardIdToBlacklist(boardId) { ? concatBoardIdIfNecessary() : [boardId]; - dispatch(verifyAndUpsertCommunicator(updatedCommunicatorData)); - return dispatch(upsertApiCommunicator(updatedCommunicatorData)) - .then(() => { - return updatedCommunicatorData?.defaultBoardBlackList; - }) - .catch(e => { - console.error(e.message); - }); + return dispatch(verifyAndUpsertCommunicator(updatedCommunicatorData)); }; } From 37d235681e85f0eef326fdd76e4e0a80b627fc89 Mon Sep 17 00:00:00 2001 From: tomivm Date: Mon, 1 Jul 2024 17:57:28 +0200 Subject: [PATCH 74/85] Add a default state for defaultBoardBlackList --- src/api/communicators.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/communicators.json b/src/api/communicators.json index d092ea107..c76acc5ed 100644 --- a/src/api/communicators.json +++ b/src/api/communicators.json @@ -6,6 +6,7 @@ "author": "Cboard Team", "email": "support@cboard.io", "rootBoard": "root", - "boards": ["root"] + "boards": ["root"], + "defaultBoardBlackList": [] } ] From 333239448676914b5f087fd3d08d0599944fb999 Mon Sep 17 00:00:00 2001 From: tomivm Date: Mon, 1 Jul 2024 20:50:26 +0200 Subject: [PATCH 75/85] move to root board if user is on the crated board in another device --- src/components/Board/Board.actions.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index dce3a2875..79f484ed7 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -272,8 +272,15 @@ export function previousBoard() { } export function toRootBoard() { - return { - type: TO_ROOT_BOARD + return (dispatch, getState) => { + const rootBoard = getState().communicator.communicators.find( + communicator => + communicator.id === getState().communicator.activeCommunicatorId + ).rootBoard; + history.replace(rootBoard); + return dispatch({ + type: TO_ROOT_BOARD + }); }; } @@ -829,8 +836,14 @@ export function updateApiObjects( } export function removeBoardsFromList(blacklist = []) { - return { - type: REMOVE_BOARDS_FROM_LIST, - blacklist + return (dispatch, getState) => { + const actualBoardId = getState().board.activeBoardId; + if (blacklist.includes(actualBoardId)) { + dispatch(toRootBoard()); + } + dispatch({ + type: REMOVE_BOARDS_FROM_LIST, + blacklist + }); }; } From 93b8e1bf6ced3ebb082bdcb84836b3f1393c83cc Mon Sep 17 00:00:00 2001 From: tomivm Date: Mon, 1 Jul 2024 23:28:11 +0200 Subject: [PATCH 76/85] Prevent navigation to a deletedBoard --- src/components/Board/Board.actions.js | 19 ++++++++++++------- .../Communicator/Communicator.actions.js | 7 ++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index 79f484ed7..f0292e843 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -273,11 +273,14 @@ export function previousBoard() { export function toRootBoard() { return (dispatch, getState) => { - const rootBoard = getState().communicator.communicators.find( - communicator => - communicator.id === getState().communicator.activeCommunicatorId - ).rootBoard; - history.replace(rootBoard); + const navHistory = getState().board.navHistory; + const firstBoardOnHistory = navHistory[0]; + const allBoardsIds = getState().board.boards.map(board => board.id); + + if (!firstBoardOnHistory || !allBoardsIds.includes(firstBoardOnHistory)) { + return null; + } + history.replace(firstBoardOnHistory); return dispatch({ type: TO_ROOT_BOARD }); @@ -835,11 +838,13 @@ export function updateApiObjects( }; } -export function removeBoardsFromList(blacklist = []) { +export function removeBoardsFromList(blacklist = [], rootBoard) { return (dispatch, getState) => { const actualBoardId = getState().board.activeBoardId; if (blacklist.includes(actualBoardId)) { - dispatch(toRootBoard()); + history.replace(rootBoard); + dispatch(switchBoard(rootBoard)); + return dispatch(toRootBoard()); } dispatch({ type: REMOVE_BOARDS_FROM_LIST, diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index b06a79751..8ae72c349 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -242,7 +242,12 @@ export function getApiMyCommunicators() { communicator.id === getState().communicator.activeCommunicator ) ?? res.data[res.data.length - 1]; const defaultBoardBlackList = activeCommunicator?.defaultBoardBlackList; - dispatch(removeBoardsFromList(defaultBoardBlackList)); + dispatch( + removeBoardsFromList( + defaultBoardBlackList, + activeCommunicator.rootBoard + ) + ); dispatch(getApiMyCommunicatorsSuccess(res)); return res; }) From 0bebfd82113922eb3a3387b08922be558453f580 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 1 Jul 2024 21:45:07 -0300 Subject: [PATCH 77/85] Fix lastEdit update --- .../Communicator/Communicator.reducer.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/Communicator/Communicator.reducer.js b/src/components/Communicator/Communicator.reducer.js index 8f6158cde..e36f4575e 100644 --- a/src/components/Communicator/Communicator.reducer.js +++ b/src/components/Communicator/Communicator.reducer.js @@ -106,7 +106,7 @@ function communicatorReducer(state = initialState, action) { if (index !== -1) { const updatedCommunicators = [...state.communicators]; updatedCommunicators[index].boards.push(action.boardId); - updatedCommunicators.lastEdited = moment().format(); + updatedCommunicators[index].lastEdited = moment().format(); return { ...state, communicators: updatedCommunicators @@ -214,10 +214,13 @@ function communicatorReducer(state = initialState, action) { : state.activeCommunicatorId, communicators: state.communicators.map(communicator => communicator.id === action.communicatorId - ? { ...communicator, id: action.communicator.id } + ? { + ...communicator, + id: action.communicator.id, + lastEdited: action.communicator.lastEdited + } : communicator - ), - lastEdited: action.communicator.lastEdited + ) }; case CREATE_API_COMMUNICATOR_FAILURE: return { @@ -233,7 +236,14 @@ function communicatorReducer(state = initialState, action) { return { ...state, isFetching: false, - lastEdited: action.communicator.lastEdited + communicators: state.communicators.map(communicator => + communicator.id === action.communicator.id + ? { + ...communicator, + lastEdited: action.communicator.lastEdited + } + : communicator + ) }; case UPDATE_API_COMMUNICATOR_FAILURE: return { From 00e2c15a8066ceaea7e8fd04dc5c4e5ebb2909d1 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 1 Jul 2024 21:46:47 -0300 Subject: [PATCH 78/85] Set last saved communicator and change board if it is necessary --- .../Communicator/Communicator.actions.js | 40 +++++++++++++++---- .../Communicator/Communicator.reducer.js | 3 +- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 6748486e0..de4f4c4ab 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -24,6 +24,8 @@ import { defaultCommunicatorID } from './Communicator.reducer'; import API from '../../api'; import shortid from 'shortid'; import moment from 'moment'; +import { switchBoard } from '../Board/Board.actions'; +import history from './../../history'; export function importCommunicator(communicator) { return { @@ -301,24 +303,26 @@ export function syncCommunicators(remoteCommunicators) { const reconcileCommunicators = (local, remote) => { if (local.lastEdited && remote.lastEdited) { if (moment(local.lastEdited).isAfter(remote.lastEdited)) { - console.log('comm local is after remote', local); return local; } if (moment(local.lastEdited).isBefore(remote.lastEdited)) { - console.log('Comm local is before remote', remote); return remote; } if (moment(local.lastEdited).isSame(remote.lastEdited)) { - console.log('Comm sync isSame', local); return remote; } } - console.log('no entro'); return remote; }; + const getActiveCommunicator = getState => { + return getState().communicator.communicators.find( + c => c.id === getState().communicator.activeCommunicatorId + ); + }; return async (dispatch, getState) => { const localCommunicators = getState().communicator.communicators; + const updatedCommunicators = [...localCommunicators]; for (const remote of remoteCommunicators) { const localIndex = localCommunicators.findIndex( @@ -337,21 +341,41 @@ export function syncCommunicators(remoteCommunicators) { const res = await dispatch( updateApiCommunicator(localCommunicators[localIndex]) ); - localCommunicators[localIndex] = res; + updatedCommunicators[localIndex] = res; } catch (e) { console.error(e); } } else { - localCommunicators[localIndex] = reconciled; + updatedCommunicators[localIndex] = reconciled; } } else { // If the communicator does not exist locally, add it - localCommunicators.push(remote); + updatedCommunicators.push(remote); } } + + const activeCommunicatorId = getActiveCommunicator(getState).id ?? null; + const lastRemoteSavedCommunicatorId = remoteCommunicators[0].id ?? null; //The last communicator saved on the server + const needToChangeActiveCommunicator = + activeCommunicatorId !== lastRemoteSavedCommunicatorId && + updatedCommunicators.length && + updatedCommunicators.findIndex( + communicator => communicator.id === lastRemoteSavedCommunicatorId + ) !== -1; + dispatch({ type: SYNC_COMMUNICATORS, - communicators: localCommunicators + communicators: updatedCommunicators, + activeCommunicatorId: needToChangeActiveCommunicator + ? remoteCommunicators[0].id + : activeCommunicatorId }); + + if (needToChangeActiveCommunicator) { + const newActiveCommunicator = getActiveCommunicator(getState); + const rootBoard = newActiveCommunicator.rootBoard; + dispatch(switchBoard(rootBoard)); + history.replace(rootBoard); + } }; } diff --git a/src/components/Communicator/Communicator.reducer.js b/src/components/Communicator/Communicator.reducer.js index e36f4575e..5b19818b2 100644 --- a/src/components/Communicator/Communicator.reducer.js +++ b/src/components/Communicator/Communicator.reducer.js @@ -274,8 +274,7 @@ function communicatorReducer(state = initialState, action) { return { ...state, communicators: action.communicators, - activeCommunicatorId: - action.communicators[action.communicators.length - 1].id + activeCommunicatorId: action.activeCommunicatorId }; default: return state; From a17f59852dc5eafebd5a726206266ef7a15c1431 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 1 Jul 2024 21:49:14 -0300 Subject: [PATCH 79/85] Fix currentCommunicator on login action --- src/components/Account/Login/Login.actions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index cf96125bf..1c19a48bf 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -147,7 +147,8 @@ export function login({ email, password, activatedData }, type = 'local') { ); if (loginData.communicators && loginData.communicators.length) { - currentCommunicator = loginData.communicators[0]; + currentCommunicator = + loginData.communicators[loginData.communicators.length - 1]; //use the latest communicator } const localBoardsIds = []; From 0241e1d2ac305d17c7d1ce500c034e4aad494e52 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 3 Jul 2024 11:23:21 -0300 Subject: [PATCH 80/85] Add lastRemoteSavedCommunicatorIndex constant to avoid magic number --- src/components/Account/Login/Login.actions.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index 1c19a48bf..31022cc73 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -147,8 +147,10 @@ export function login({ email, password, activatedData }, type = 'local') { ); if (loginData.communicators && loginData.communicators.length) { + const lastRemoteSavedCommunicatorIndex = + loginData.communicators.length - 1; currentCommunicator = - loginData.communicators[loginData.communicators.length - 1]; //use the latest communicator + loginData.communicators[lastRemoteSavedCommunicatorIndex]; //use the latest communicator } const localBoardsIds = []; From 3ee64a8d69458edca56b255ecf2fc1a9cd9ccb1d Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 3 Jul 2024 11:25:55 -0300 Subject: [PATCH 81/85] Comprobe if lastRemoteSavedCommunicatorId is not null and use it on sync communicator action --- src/components/Communicator/Communicator.actions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index de4f4c4ab..625dd26e9 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -359,6 +359,7 @@ export function syncCommunicators(remoteCommunicators) { const needToChangeActiveCommunicator = activeCommunicatorId !== lastRemoteSavedCommunicatorId && updatedCommunicators.length && + lastRemoteSavedCommunicatorId && updatedCommunicators.findIndex( communicator => communicator.id === lastRemoteSavedCommunicatorId ) !== -1; @@ -367,7 +368,7 @@ export function syncCommunicators(remoteCommunicators) { type: SYNC_COMMUNICATORS, communicators: updatedCommunicators, activeCommunicatorId: needToChangeActiveCommunicator - ? remoteCommunicators[0].id + ? lastRemoteSavedCommunicatorId : activeCommunicatorId }); From 0bf1006db1605c874ebfb43ac4143613b118a3f1 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 3 Jul 2024 12:31:46 -0300 Subject: [PATCH 82/85] Add lastEdited prop to initialState Communcator reducer test --- .../Communicator/__tests__/Communicator.reducer.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Communicator/__tests__/Communicator.reducer.test.js b/src/components/Communicator/__tests__/Communicator.reducer.test.js index 1b6703f41..1cee3ea57 100644 --- a/src/components/Communicator/__tests__/Communicator.reducer.test.js +++ b/src/components/Communicator/__tests__/Communicator.reducer.test.js @@ -21,6 +21,7 @@ import { GET_API_MY_COMMUNICATORS_STARTED } from '../Communicator.constants'; import { LOGIN_SUCCESS, LOGOUT } from '../../Account/Login/Login.constants'; +import moment from 'moment'; let mockComm, defaultCommunicatorID, initialState; describe('reducer', () => { @@ -32,7 +33,8 @@ describe('reducer', () => { email: 'anything@cboard.io', id: '123', name: "Cboard's Communicator", - rootBoard: '1' + rootBoard: '1', + lastEdited: moment().format() }; defaultCommunicatorID = 'cboard_default'; initialState = { @@ -124,7 +126,8 @@ describe('reducer', () => { }); it('should handle updateApiCommunicatorSuccess', () => { const updateApiCommunicatorSuccess = { - type: UPDATE_API_COMMUNICATOR_SUCCESS + type: UPDATE_API_COMMUNICATOR_SUCCESS, + communicator: initialState }; expect( communicatorReducer(initialState, updateApiCommunicatorSuccess) From 9de64fe4d4cb813bfebfaf03a7076318679c76ae Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 3 Jul 2024 19:07:04 +0200 Subject: [PATCH 83/85] Refactor toRootBoard test --- .../Board/__tests__/Board.actions.test.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/Board/__tests__/Board.actions.test.js b/src/components/Board/__tests__/Board.actions.test.js index 68f44024e..bda1fc74f 100644 --- a/src/components/Board/__tests__/Board.actions.test.js +++ b/src/components/Board/__tests__/Board.actions.test.js @@ -132,11 +132,21 @@ describe('actions', () => { expect(actions.previousBoard()).toEqual(expectedAction); }); - it('should create an action to REPLACE_ME', () => { + it('should create an action to REPLACE_ME', async () => { const expectedAction = { type: types.TO_ROOT_BOARD }; - expect(actions.toRootBoard()).toEqual(expectedAction); + const store = mockStore({ + ...initialState, + board: { + ...initialState.board, + navHistory: ['12345678901234567'], + boards: [{ ...mockBoard, id: '12345678901234567' }] + } + }); + await store.dispatch(actions.toRootBoard()); + const toRootBoardAction = store.getActions()[0]; + expect(toRootBoardAction).toEqual(expectedAction); }); it('should create an action to REPLACE_ME', () => { From 023bc5d318760efb700b97fa3024a497ee36dc56 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 3 Jul 2024 14:13:09 -0300 Subject: [PATCH 84/85] Refactor getApiCommunicator to use try catch block --- .../Communicator/Communicator.actions.js | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 625dd26e9..54f5d1b3f 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -236,18 +236,22 @@ export function verifyAndUpsertCommunicator( export function getApiMyCommunicators() { return async dispatch => { dispatch(getApiMyCommunicatorsStarted()); - return API.getCommunicators() - .then(res => { - dispatch(getApiMyCommunicatorsSuccess(res)); - - return dispatch(syncCommunicators(res.data)).catch(e => { + try { + const res = await API.getCommunicators(); + dispatch(getApiMyCommunicatorsSuccess(res)); + if (res?.data && res.data.length) { + try { + await dispatch(syncCommunicators(res.data)); + } catch (e) { console.error(e); - }); - }) - .catch(err => { - dispatch(getApiMyCommunicatorsFailure(err.message)); - throw new Error(err.message); - }); + } + } + + return res; + } catch (err) { + dispatch(getApiMyCommunicatorsFailure(err.message)); + throw new Error(err.message); + } }; } From 0674579f2b5b2dcddc6b66471aed6c1c93a0f817 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 4 Jul 2024 01:47:44 +0200 Subject: [PATCH 85/85] reduce the possibilities of delete active board --- src/components/Board/Board.actions.js | 13 +++++++------ src/components/Board/Board.container.js | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index f0292e843..6ed39922d 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -155,11 +155,12 @@ export function changeDefaultBoard(selectedBoardNameOnJson) { if (homeBoardId) { const storeBoards = getState().board.boards; const board = storeBoards.find(board => board.id === homeBoardId); - if (!board) addBoards([board]); + if (!board) return null; const goTo = `/board/${homeBoardId}`; dispatch(switchBoard(homeBoardId)); history.replace(goTo); + return true; } }; @@ -203,9 +204,7 @@ export function changeDefaultBoard(selectedBoardNameOnJson) { homeBoardId }); - switchActiveBoard(homeBoardId); - - replaceHomeBoard(homeBoardId); + if (switchActiveBoard(homeBoardId)) replaceHomeBoard(homeBoardId); }; } @@ -281,9 +280,10 @@ export function toRootBoard() { return null; } history.replace(firstBoardOnHistory); - return dispatch({ + dispatch({ type: TO_ROOT_BOARD }); + return firstBoardOnHistory; }; } @@ -844,7 +844,8 @@ export function removeBoardsFromList(blacklist = [], rootBoard) { if (blacklist.includes(actualBoardId)) { history.replace(rootBoard); dispatch(switchBoard(rootBoard)); - return dispatch(toRootBoard()); + const rootBoardFinded = dispatch(toRootBoard()); + if (!rootBoardFinded || blacklist.includes(rootBoard)) return; } dispatch({ type: REMOVE_BOARDS_FROM_LIST, diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index b9612ddec..25175a079 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -883,8 +883,7 @@ export class BoardContainer extends Component { if ( ALL_DEFAULT_BOARDS.map(({ id }) => id).includes(loadBoardSearched) ) { - this.addDefaultBoardIfnecessary(loadBoardSearched); - const nextBoard = findBoardOnStore(loadBoardSearched); + const nextBoard = this.addDefaultBoardIfnecessary(loadBoardSearched); if (nextBoard) return nextBoard; } };