Skip to content

Commit

Permalink
Add 'defaultBoards-blacklist' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivm committed Jun 27, 2024
2 parents 8f369d9 + b18c8a2 commit 154ab2d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/components/Board/Board.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -52,7 +53,8 @@ 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';
Expand Down Expand Up @@ -521,7 +523,8 @@ export function createApiBoard(boardData, boardId) {
isPublic: false
};
return API.createBoard(boardData)
.then(res => {
.then(async res => {
await dispatch(concatDefaultBoardIdToBlacklist(boardId));
dispatch(createApiBoardSuccess(res, boardId));
return res;
})
Expand Down Expand Up @@ -883,3 +886,10 @@ export function addNecessaryDefaultBoardsFor(boardIdToAdd) {
}
};
}

export function removeBoardsFromList(blacklist = []) {
return {
type: REMOVE_BOARDS_FROM_LIST,
blacklist
};
}
1 change: 1 addition & 0 deletions src/components/Board/Board.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 9 additions & 1 deletion src/components/Board/Board.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down
41 changes: 40 additions & 1 deletion src/components/Communicator/Communicator.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
})
Expand Down Expand Up @@ -291,3 +299,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);
});
};
}

0 comments on commit 154ab2d

Please sign in to comment.