From 78f1d91e310d3390ddbc5b1701401a2f529408b4 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 23 Jul 2024 13:40:18 -0300 Subject: [PATCH 1/2] Revert "Merge pull request #1711 from tomivm/feature/add-only-necessary-default-boards-on-login" This reverts commit 8592f4314cfa48964ab6d2bafaf0567d1119a2bc, reversing changes made to 42c1242db8c01c9f31f745c59e56ccae8b61b474. --- src/api/communicators.json | 1 - src/components/Account/Login/Login.actions.js | 4 +- src/components/Board/Board.actions.js | 31 +++----------- src/components/Board/Board.constants.js | 1 - src/components/Board/Board.container.js | 39 ++---------------- src/components/Board/Board.reducer.js | 9 +--- .../Board/__tests__/Board.actions.test.js | 19 ++------- .../Communicator/Communicator.actions.js | 41 +------------------ src/helpers.js | 10 ----- 9 files changed, 16 insertions(+), 139 deletions(-) diff --git a/src/api/communicators.json b/src/api/communicators.json index 840795576..54dafa5c0 100644 --- a/src/api/communicators.json +++ b/src/api/communicators.json @@ -7,7 +7,6 @@ "email": "support@cboard.io", "rootBoard": "root", "boards": ["root"], - "defaultBoardBlackList": [], "defaultBoardsIncluded": [ { "nameOnJSON": "advanced", "homeBoard": "root" }, { "nameOnJSON": "picSeePal", "homeBoard": "jjmlUcQs19" } diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index be0290a34..31022cc73 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -15,7 +15,6 @@ 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 => { @@ -170,12 +169,13 @@ export function login({ email, password, activatedData }, type = 'local') { .map(async id => { let board = null; try { - if (isRemoteIdChecker(id)) board = await API.getBoard(id); + board = await API.getBoard(id); } catch (e) {} return board; }) .filter(b => b !== null) ); + dispatch(addBoards(apiBoards)); if (type === 'local') { dispatch( diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index a84764f1e..f14920c3a 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, - REMOVE_BOARDS_FROM_LIST, UNMARK_SHOULD_CREATE_API_BOARD, SHORT_ID_MAX_LENGTH } from './Board.constants'; @@ -54,8 +53,7 @@ import { upsertApiCommunicator, updateDefaultBoardsIncluded, addDefaultBoardIncluded, - verifyAndUpsertCommunicator, - concatDefaultBoardIdToBlacklist + verifyAndUpsertCommunicator } from '../Communicator/Communicator.actions'; import { isAndroid, writeCvaFile } from '../../cordova-util'; import { DEFAULT_BOARDS } from '../../helpers'; @@ -158,14 +156,10 @@ export function changeDefaultBoard(selectedBoardNameOnJson) { const switchActiveBoard = homeBoardId => { if (homeBoardId) { - const storeBoards = getState().board.boards; - const board = storeBoards.find(board => board.id === homeBoardId); - if (!board) return null; const goTo = `/board/${homeBoardId}`; dispatch(switchBoard(homeBoardId)); history.replace(goTo); - return true; } }; @@ -209,7 +203,9 @@ export function changeDefaultBoard(selectedBoardNameOnJson) { homeBoardId }); - if (switchActiveBoard(homeBoardId)) replaceHomeBoard(homeBoardId); + switchActiveBoard(homeBoardId); + + replaceHomeBoard(homeBoardId); }; } @@ -535,8 +531,7 @@ export function createApiBoard(boardData, boardId) { isPublic: false }; return API.createBoard(boardData) - .then(async res => { - await dispatch(concatDefaultBoardIdToBlacklist(boardId)); + .then(res => { dispatch(createApiBoardSuccess(res, boardId)); return res; }) @@ -883,19 +878,3 @@ export function updateApiObjects( }); }; } - -export function removeBoardsFromList(blacklist = [], rootBoard) { - return (dispatch, getState) => { - const actualBoardId = getState().board.activeBoardId; - if (blacklist.includes(actualBoardId)) { - history.replace(`/board/${rootBoard}`); - dispatch(switchBoard(rootBoard)); - const rootBoardFinded = dispatch(toRootBoard()); - if (!rootBoardFinded || blacklist.includes(rootBoard)) return; - } - dispatch({ - type: REMOVE_BOARDS_FROM_LIST, - blacklist - }); - }; -} diff --git a/src/components/Board/Board.constants.js b/src/components/Board/Board.constants.js index 9b3937e79..79aae6ef3 100644 --- a/src/components/Board/Board.constants.js +++ b/src/components/Board/Board.constants.js @@ -3,7 +3,6 @@ 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.container.js b/src/components/Board/Board.container.js index 90c7f5fa7..1ed954ec0 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -70,7 +70,6 @@ import { IS_BROWSING_FROM_APPLE_TOUCH, IS_BROWSING_FROM_SAFARI } from '../../constants'; -import { ALL_DEFAULT_BOARDS, isRemoteIdChecker } from '../../helpers'; //import { isAndroid } from '../../cordova-util'; const ogv = require('ogv'); @@ -274,16 +273,9 @@ export class BoardContainer extends Component { if (!boardExists) { // try the root board - const homeBoard = communicator.rootBoard; - boardExists = boards.find(b => b.id === homeBoard); + boardExists = boards.find(b => b.id === communicator.rootBoard); if (!boardExists) { - try { - if (isRemoteIdChecker(homeBoard)) - boardExists = await this.tryRemoteBoard(homeBoard); - } catch (err) {} - if (!boardExists) - boardExists = this.addDefaultBoardIfnecessary(homeBoard); - if (!boardExists) boardExists = boards.find(b => b.id !== ''); + boardExists = boards.find(b => b.id !== ''); } } const boardId = boardExists.id; @@ -875,21 +867,8 @@ 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) - ) { - const nextBoard = this.addDefaultBoardIfnecessary(loadBoardSearched); - if (nextBoard) return nextBoard; - } - }; const nextBoard = - loadBoardFinder(tile.loadBoard) || + boards.find(b => b.id === 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); @@ -1531,18 +1510,6 @@ 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, diff --git a/src/components/Board/Board.reducer.js b/src/components/Board/Board.reducer.js index 659c31196..89f14cb64 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, - REMOVE_BOARDS_FROM_LIST, UNMARK_SHOULD_CREATE_API_BOARD, SHORT_ID_MAX_LENGTH } from './Board.constants'; @@ -252,13 +251,7 @@ 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 CREATE_TILE: return { ...state, diff --git a/src/components/Board/__tests__/Board.actions.test.js b/src/components/Board/__tests__/Board.actions.test.js index bda1fc74f..c9743e001 100644 --- a/src/components/Board/__tests__/Board.actions.test.js +++ b/src/components/Board/__tests__/Board.actions.test.js @@ -132,21 +132,11 @@ describe('actions', () => { expect(actions.previousBoard()).toEqual(expectedAction); }); - it('should create an action to REPLACE_ME', async () => { + it('should create an action to REPLACE_ME', () => { const expectedAction = { type: types.TO_ROOT_BOARD }; - 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); + expect(actions.toRootBoard()).toEqual(expectedAction); }); it('should create an action to REPLACE_ME', () => { @@ -328,10 +318,7 @@ describe('actions', () => { boardId: '12345678901234567', type: 'cboard/Board/CREATE_API_BOARD_SUCCESS' }; - const successAction = actions.find( - action => action.type === types.CREATE_API_BOARD_SUCCESS - ); - expect(successAction).toEqual(dataResp); + expect(actions[1]).toEqual(dataResp); expect(data).toEqual(mockBoard); }) .catch(e => { diff --git a/src/components/Communicator/Communicator.actions.js b/src/components/Communicator/Communicator.actions.js index 2a27f2259..b05da82c0 100644 --- a/src/components/Communicator/Communicator.actions.js +++ b/src/components/Communicator/Communicator.actions.js @@ -23,9 +23,8 @@ import { import { defaultCommunicatorID } from './Communicator.reducer'; import API from '../../api'; import shortid from 'shortid'; -import { removeBoardsFromList, switchBoard } from '../Board/Board.actions'; -import { ALL_DEFAULT_BOARDS } from '../../helpers'; import moment from 'moment'; +import { switchBoard } from '../Board/Board.actions'; import history from './../../history'; export function importCommunicator(communicator) { @@ -238,7 +237,7 @@ export function verifyAndUpsertCommunicator( */ export function getApiMyCommunicators() { - return async (dispatch, getState) => { + return async dispatch => { dispatch(getApiMyCommunicatorsStarted()); try { const res = await API.getCommunicators(); @@ -249,18 +248,6 @@ export function getApiMyCommunicators() { } catch (e) { console.error(e); } - const activeCommunicator = - res.data.find( - communicator => - communicator.id === getState().communicator.activeCommunicator - ) ?? res.data[res.data.length - 1]; - const defaultBoardBlackList = activeCommunicator?.defaultBoardBlackList; - dispatch( - removeBoardsFromList( - defaultBoardBlackList, - activeCommunicator.rootBoard - ) - ); } return res; @@ -405,27 +392,3 @@ export function syncCommunicators(remoteCommunicators) { } }; } - -export function concatDefaultBoardIdToBlacklist(boardId) { - const getActiveCommunicator = getState => { - return getState().communicator.communicators.find( - c => c.id === getState().communicator.activeCommunicatorId - ); - }; - return (dispatch, getState) => { - if (!ALL_DEFAULT_BOARDS.map(({ id }) => id).includes(boardId)) return; - const updatedCommunicatorData = { ...getActiveCommunicator(getState) }; - - const concatBoardIdIfNecessary = () => { - if (!updatedCommunicatorData?.defaultBoardBlackList.includes(boardId)) - return updatedCommunicatorData?.defaultBoardBlackList.concat(boardId); - return updatedCommunicatorData?.defaultBoardBlackList; - }; - - updatedCommunicatorData.defaultBoardBlackList = updatedCommunicatorData?.defaultBoardBlackList - ? concatBoardIdIfNecessary() - : [boardId]; - - return dispatch(verifyAndUpsertCommunicator(updatedCommunicatorData)); - }; -} diff --git a/src/helpers.js b/src/helpers.js index 06770683d..6ac74ee2f 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -5,16 +5,6 @@ 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 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 From bd01d09d5cf08cc01c421650fc4ebe560834e1e7 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 23 Jul 2024 13:56:47 -0300 Subject: [PATCH 2/2] Revert changes on toRootBoard function --- src/components/Board/Board.actions.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/components/Board/Board.actions.js b/src/components/Board/Board.actions.js index f14920c3a..4f483c5ec 100644 --- a/src/components/Board/Board.actions.js +++ b/src/components/Board/Board.actions.js @@ -272,19 +272,8 @@ export function previousBoard() { } export function toRootBoard() { - return (dispatch, getState) => { - 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(`/board/${firstBoardOnHistory}`); - dispatch({ - type: TO_ROOT_BOARD - }); - return firstBoardOnHistory; + return { + type: TO_ROOT_BOARD }; }