From 1f62f2035049c50ce2d9506373b961d8c5540d21 Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 16 Apr 2024 15:19:48 +0200 Subject: [PATCH] feat: client implementation of list sorting --- client/src/actions/lists.js | 32 ++++++++++ client/src/api/lists.js | 3 + client/src/components/List/ActionsStep.jsx | 46 +++++++++++---- client/src/components/List/List.jsx | 4 +- client/src/components/SortStep/SortStep.jsx | 59 +++++++++++++++++++ .../components/SortStep/SortStep.module.scss | 0 client/src/components/SortStep/index.js | 3 + client/src/constants/ActionTypes.js | 4 ++ client/src/constants/EntryActionTypes.js | 2 + client/src/containers/ListContainer.js | 1 + client/src/entry-actions/lists.js | 19 ++++++ client/src/models/List.js | 3 + client/src/sagas/core/services/lists.js | 20 +++++++ client/src/sagas/core/watchers/lists.js | 6 ++ 14 files changed, 190 insertions(+), 12 deletions(-) create mode 100644 client/src/components/SortStep/SortStep.jsx create mode 100644 client/src/components/SortStep/SortStep.module.scss create mode 100644 client/src/components/SortStep/index.js diff --git a/client/src/actions/lists.js b/client/src/actions/lists.js index 59f944f..a7d409d 100644 --- a/client/src/actions/lists.js +++ b/client/src/actions/lists.js @@ -89,6 +89,36 @@ const handleListDelete = (list) => ({ }, }); +const sortList = (id, data) => ({ + type: ActionTypes.LIST_SORT, + payload: { + id, + data, + }, +}); + +sortList.success = (list) => ({ + type: ActionTypes.LIST_SORT__SUCCESS, + payload: { + list, + }, +}); + +sortList.failure = (id, error) => ({ + type: ActionTypes.LIST_SORT__FAILURE, + payload: { + id, + error, + }, +}); + +const handleListSort = (list) => ({ + type: ActionTypes.LIST_SORT_HANDLE, + payload: { + list, + }, +}); + export default { createList, handleListCreate, @@ -96,4 +126,6 @@ export default { handleListUpdate, deleteList, handleListDelete, + sortList, + handleListSort }; diff --git a/client/src/api/lists.js b/client/src/api/lists.js index 6c1ee6a..aa36f0a 100755 --- a/client/src/api/lists.js +++ b/client/src/api/lists.js @@ -7,10 +7,13 @@ const createList = (boardId, data, headers) => const updateList = (id, data, headers) => socket.patch(`/lists/${id}`, data, headers); +const sortList = (id, data, headers) => socket.post(`/lists/${id}/sort`, data, headers); + const deleteList = (id, headers) => socket.delete(`/lists/${id}`, undefined, headers); export default { createList, updateList, + sortList, deleteList, }; diff --git a/client/src/components/List/ActionsStep.jsx b/client/src/components/List/ActionsStep.jsx index 1e94d5a..3bbc28d 100755 --- a/client/src/components/List/ActionsStep.jsx +++ b/client/src/components/List/ActionsStep.jsx @@ -8,12 +8,14 @@ import { useSteps } from '../../hooks'; import DeleteStep from '../DeleteStep'; import styles from './ActionsStep.module.scss'; +import SortStep from "../SortStep"; const StepTypes = { DELETE: 'DELETE', + SORT: 'SORT', }; -const ActionsStep = React.memo(({ onNameEdit, onCardAdd, onDelete, onClose }) => { +const ActionsStep = React.memo(({ onNameEdit, onCardAdd, onDelete, onSort, onClose }) => { const [t] = useTranslation(); const [step, openStep, handleBack] = useSteps(); @@ -31,16 +33,32 @@ const ActionsStep = React.memo(({ onNameEdit, onCardAdd, onDelete, onClose }) => openStep(StepTypes.DELETE); }, [openStep]); - if (step && step.type === StepTypes.DELETE) { - return ( - - ); + const handleSortClick = useCallback(() => { + openStep(StepTypes.SORT); + }, [openStep]); + + if (step && step.type) { + switch (step.type){ + case StepTypes.DELETE: + return ( + + ); + case StepTypes.SORT: + return ( + + ); + default: + } } return ( @@ -52,6 +70,11 @@ const ActionsStep = React.memo(({ onNameEdit, onCardAdd, onDelete, onClose }) => + + {t('action.sort', { + context: 'title', + })} + {t('action.editTitle', { context: 'title', @@ -77,6 +100,7 @@ ActionsStep.propTypes = { onNameEdit: PropTypes.func.isRequired, onCardAdd: PropTypes.func.isRequired, onDelete: PropTypes.func.isRequired, + onSort: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, }; diff --git a/client/src/components/List/List.jsx b/client/src/components/List/List.jsx index f09116c..98d6941 100755 --- a/client/src/components/List/List.jsx +++ b/client/src/components/List/List.jsx @@ -16,7 +16,7 @@ import { ReactComponent as PlusMathIcon } from '../../assets/images/plus-math-ic import styles from './List.module.scss'; const List = React.memo( - ({ id, index, name, isPersisted, cardIds, canEdit, onUpdate, onDelete, onCardCreate }) => { + ({ id, index, name, isPersisted, cardIds, canEdit, onUpdate, onDelete, onSort, onCardCreate }) => { const [t] = useTranslation(); const [isAddCardOpened, setIsAddCardOpened] = useState(false); @@ -114,6 +114,7 @@ const List = React.memo( onNameEdit={handleNameEdit} onCardAdd={handleCardAdd} onDelete={onDelete} + onSort={onSort} >