Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature/add only necessary default boards on login #1711

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
05568ae
Add actions to clean all boards and add the necessary default boards
tomivm Jun 11, 2024
c0a07cb
Clean All boards from the store before loginSuccess
tomivm Jun 11, 2024
ae9e5da
Add root board if is not on the communicator boards before login success
tomivm Jun 11, 2024
69f5bee
Fix addRootBoard import
tomivm Jun 11, 2024
bec7283
refactor: Update addRootBoard import and function name to addRootBoar…
tomivm Jun 11, 2024
408fba8
refactor: Rename addRootBoard function to findAndAddRootBoardOnDefaul…
tomivm Jun 12, 2024
360aa9e
Refactor login to add necessary default boards for homeBoards
tomivm Jun 13, 2024
15ba033
Add necessary default boards for remote boards
tomivm Jun 13, 2024
2aeeb4a
Prevent unnecessary requests to get boards for local Ids
tomivm Jun 13, 2024
1dcf25e
Add necessary Default boards on changeDefaultBoard
tomivm Jun 14, 2024
2cca7af
Enforces the possibilities to find the home board if it is requested
tomivm Jun 14, 2024
f1e3fcf
Fix incorrect map to search ids on ALL_DEFAULT_BOARDS
tomivm Jun 14, 2024
ee8c86c
Create helper function to check if id is Remote
tomivm Jun 14, 2024
3a7b973
Add insurance to find Default Boards on a folder click
tomivm Jun 14, 2024
0f7c473
use remoteIdChecker helper function
tomivm Jun 14, 2024
952d81a
mark unnecesaryDefaultBoardsRemoved as true on cleanAllBoards
tomivm Jun 19, 2024
74ee5db
Fix board reducer test
tomivm Jun 25, 2024
82debb1
Merge branch 'refactor/implementUpsertApiCommunicator' into feature/d…
tomivm Jun 26, 2024
4bcd548
fix getActiveComunnicator function
tomivm Jun 26, 2024
150d7b6
Concat default boards Ids in a blacklist on create API board
tomivm Jun 26, 2024
aa38a14
remove unnecessary import
tomivm Jun 26, 2024
54aa14d
await for concatDefaultBoardIdToBlacklist
tomivm Jun 26, 2024
b18c8a2
Remove Boards from the blacklist on update API objects
tomivm Jun 26, 2024
3d7fff1
Merge branch 'master' into pr/tomivm/1711
RodriSanchez1 Jun 26, 2024
8f369d9
Merge branch 'feature/add-only-necessary-default-boards-on-login' of …
RodriSanchez1 Jun 26, 2024
154ab2d
Add 'defaultBoards-blacklist' feature
tomivm Jun 27, 2024
26d9689
Remove staff to clean all boards on login
tomivm Jun 27, 2024
9d4659c
remove unnecessary stuff to addNecessaryDefaultBoardsFor
tomivm Jun 27, 2024
2bf7bd1
edite the 'check createApiBoard' test to work with new actions
tomivm Jun 27, 2024
01a1668
Add prevention to only include default board ids to the blacklist
tomivm Jun 27, 2024
a1f9f4e
improve CREATE_API_BOARD_SUCCESS test to find action
tomivm Jun 27, 2024
1d8256c
use Last communicator if active communicator is not finded
tomivm Jun 28, 2024
27ca47e
fix action to include only default board ids in the blacklist
tomivm Jun 28, 2024
63a01e8
Avoid unnecessary call to API
tomivm Jul 1, 2024
37d2356
Add a default state for defaultBoardBlackList
tomivm Jul 1, 2024
3332394
move to root board if user is on the crated board in another device
tomivm Jul 1, 2024
93b8e1b
Prevent navigation to a deletedBoard
tomivm Jul 1, 2024
9de64fe
Refactor toRootBoard test
tomivm Jul 3, 2024
7e22997
Merge remote-tracking branch 'cboard-org/master' into feature/add-onl…
tomivm Jul 3, 2024
0674579
reduce the possibilities of delete active board
tomivm Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/components/Account/Login/Login.actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import API from '../../../api';
import { LOGIN_SUCCESS, LOGOUT } from './Login.constants';
import { addBoards } from '../../Board/Board.actions';
import {
addBoards,
cleanAllBoards,
addNecessaryDefaultBoardsFor
} from '../../Board/Board.actions';
import {
changeVoice,
changePitch,
Expand All @@ -15,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 => {
Expand Down Expand Up @@ -166,14 +171,23 @@ export function login({ email, password, activatedData }, type = 'local') {
.map(async id => {
let board = null;
try {
board = await API.getBoard(id);
if (isRemoteIdChecker(id)) board = await API.getBoard(id);
} catch (e) {}
return board;
})
.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({
Expand Down
66 changes: 64 additions & 2 deletions src/components/Board/Board.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -54,7 +55,7 @@ import {
verifyAndUpsertCommunicator
} 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';

Expand Down Expand Up @@ -151,6 +152,7 @@ export function changeDefaultBoard(selectedBoardNameOnJson) {

const switchActiveBoard = homeBoardId => {
if (homeBoardId) {
dispatch(addNecessaryDefaultBoardsFor(homeBoardId));
const goTo = `/board/${homeBoardId}`;

dispatch(switchBoard(homeBoardId));
Expand Down Expand Up @@ -498,6 +500,10 @@ export function getApiMyBoards() {
})
.then(res => {
dispatch(getApiMyBoardsSuccess(res));
const newBoards = res.data;
newBoards?.forEach(({ id }) => {
dispatch(addNecessaryDefaultBoardsFor(id));
});
return res;
})
.catch(err => {
Expand Down Expand Up @@ -821,3 +827,59 @@ export function updateApiObjects(
});
};
}

export function cleanAllBoards() {
return {
type: CLEAN_ALL_BOARDS
};
}

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);
}
};
}
1 change: 1 addition & 0 deletions src/components/Board/Board.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
35 changes: 29 additions & 6 deletions src/components/Board/Board.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import {
downloadImages,
createApiBoard,
upsertApiBoard,
changeDefaultBoard
changeDefaultBoard,
addNecessaryDefaultBoardsFor
} from './Board.actions';
import {
addBoardCommunicator,
Expand All @@ -70,6 +71,7 @@ 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 @@ -220,7 +222,8 @@ export class BoardContainer extends Component {
changeBoard,
userData,
history,
getApiObjects
getApiObjects,
addNecessaryDefaultBoardsFor
//downloadImages
} = this.props;

Expand Down Expand Up @@ -273,9 +276,14 @@ 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 }) => id).includes(homeBoard))
addNecessaryDefaultBoardsFor(homeBoard);
boardExists = boards.find(b => b.id === homeBoard);
if (!boardExists) {
boardExists = boards.find(b => b.id !== '');
if (isRemoteIdChecker(homeBoard))
boardExists = this.tryRemoteBoard(homeBoard);
if (!boardExists) boardExists = boards.find(b => b.id !== '');
}
}
const boardId = boardExists.id;
Expand Down Expand Up @@ -868,8 +876,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);
tomivm marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down Expand Up @@ -1736,7 +1758,8 @@ const mapDispatchToProps = {
createApiBoard,
upsertApiBoard,
changeDefaultBoard,
verifyAndUpsertCommunicator
verifyAndUpsertCommunicator,
addNecessaryDefaultBoardsFor
};

export default connect(
Expand Down
13 changes: 10 additions & 3 deletions src/components/Board/Board.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -50,7 +51,8 @@ const initialState = {
images: [],
isFixed: false,
isLiveMode: false,
improvedPhrase: ''
improvedPhrase: '',
unnecesaryDefaultBoardsRemoved: false
};

function reconcileBoards(localBoard, remoteBoard) {
Expand Down Expand Up @@ -249,7 +251,12 @@ function boardReducer(state = initialState, action) {
board => action.boardId.indexOf(board.id) === -1
)
};

case CLEAN_ALL_BOARDS:
return {
...state,
boards: [],
unnecesaryDefaultBoardsRemoved: true
};
case CREATE_TILE:
return {
...state,
Expand Down
3 changes: 2 additions & 1 deletion src/components/Board/__tests__/Board.reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const initialState = {
isFixed: false,
images: [],
isLiveMode: false,
improvedPhrase: ''
improvedPhrase: '',
unnecesaryDefaultBoardsRemoved: false
};

describe('reducer', () => {
Expand Down
10 changes: 10 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ 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
Loading