Skip to content

Commit

Permalink
Revert "Merge pull request cboard-org#1711 from tomivm/feature/add-on…
Browse files Browse the repository at this point in the history
…ly-necessary-default-boards-on-login"

This reverts commit 8592f43, reversing
changes made to 42c1242.
  • Loading branch information
RodriSanchez1 committed Jul 23, 2024
1 parent 3bbb425 commit 78f1d91
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 139 deletions.
1 change: 0 additions & 1 deletion src/api/communicators.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"email": "support@cboard.io",
"rootBoard": "root",
"boards": ["root"],
"defaultBoardBlackList": [],
"defaultBoardsIncluded": [
{ "nameOnJSON": "advanced", "homeBoard": "root" },
{ "nameOnJSON": "picSeePal", "homeBoard": "jjmlUcQs19" }
Expand Down
4 changes: 2 additions & 2 deletions src/components/Account/Login/Login.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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(
Expand Down
31 changes: 5 additions & 26 deletions src/components/Board/Board.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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;
}
};

Expand Down Expand Up @@ -209,7 +203,9 @@ export function changeDefaultBoard(selectedBoardNameOnJson) {
homeBoardId
});

if (switchActiveBoard(homeBoardId)) replaceHomeBoard(homeBoardId);
switchActiveBoard(homeBoardId);

replaceHomeBoard(homeBoardId);
};
}

Expand Down Expand Up @@ -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;
})
Expand Down Expand Up @@ -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
});
};
}
1 change: 0 additions & 1 deletion src/components/Board/Board.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
39 changes: 3 additions & 36 deletions src/components/Board/Board.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 1 addition & 8 deletions src/components/Board/Board.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 3 additions & 16 deletions src/components/Board/__tests__/Board.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 => {
Expand Down
41 changes: 2 additions & 39 deletions src/components/Communicator/Communicator.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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));
};
}
10 changes: 0 additions & 10 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 78f1d91

Please sign in to comment.