diff --git a/client/src/actions/lists.js b/client/src/actions/lists.js index 59f944f..d48bbcf 100644 --- a/client/src/actions/lists.js +++ b/client/src/actions/lists.js @@ -89,6 +89,35 @@ const handleListDelete = (list) => ({ }, }); +const sortList = (id) => ({ + type: ActionTypes.LIST_SORT, + payload: { + id, + }, +}); + +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 +125,6 @@ export default { handleListUpdate, deleteList, handleListDelete, + sortList, + handleListSort, }; diff --git a/client/src/components/Card/Card.jsx b/client/src/components/Card/Card.jsx index 37521a0..88d87a0 100755 --- a/client/src/components/Card/Card.jsx +++ b/client/src/components/Card/Card.jsx @@ -248,6 +248,8 @@ Card.propTypes = { onLabelUpdate: PropTypes.func.isRequired, onLabelMove: PropTypes.func.isRequired, onLabelDelete: PropTypes.func.isRequired, + // onSortTitleAsc: PropTypes.func.isRequired, + // onSortTitleDesc: PropTypes.func.isRequired, }; Card.defaultProps = { diff --git a/client/src/components/List/ActionsStep.jsx b/client/src/components/List/ActionsStep.jsx index 1e94d5a..b894339 100755 --- a/client/src/components/List/ActionsStep.jsx +++ b/client/src/components/List/ActionsStep.jsx @@ -6,78 +6,108 @@ import { Popup } from '../../lib/custom-ui'; import { useSteps } from '../../hooks'; import DeleteStep from '../DeleteStep'; +import SortStep from '../SortStep'; import styles from './ActionsStep.module.scss'; const StepTypes = { DELETE: 'DELETE', + SORT: 'SORT', }; -const ActionsStep = React.memo(({ onNameEdit, onCardAdd, onDelete, onClose }) => { - const [t] = useTranslation(); - const [step, openStep, handleBack] = useSteps(); +const ActionsStep = React.memo( + ({ onNameEdit, onCardAdd, onDelete, onClose, onSort, selectedOption, setSelectedOption }) => { + const [t] = useTranslation(); + const [step, openStep, handleBack] = useSteps(); - const handleEditNameClick = useCallback(() => { - onNameEdit(); - onClose(); - }, [onNameEdit, onClose]); + const handleEditNameClick = useCallback(() => { + onNameEdit(); + onClose(); + }, [onNameEdit, onClose]); - const handleAddCardClick = useCallback(() => { - onCardAdd(); - onClose(); - }, [onCardAdd, onClose]); + const handleAddCardClick = useCallback(() => { + onCardAdd(); + onClose(); + }, [onCardAdd, onClose]); - const handleDeleteClick = useCallback(() => { - openStep(StepTypes.DELETE); - }, [openStep]); + const handleDeleteClick = useCallback(() => { + openStep(StepTypes.DELETE); + }, [openStep]); + + const handleSortClick = useCallback(() => { + openStep(StepTypes.SORT); + }, [openStep]); + + if (step && step.type === StepTypes.DELETE) { + return ( + + ); + } + + if (step && step.type === StepTypes.SORT) { + return ( + + ); + } - if (step && step.type === StepTypes.DELETE) { return ( - + <> + + {t('common.listActions', { + context: 'title', + })} + + + + + {t('action.editTitle', { + context: 'title', + })} + + + {t('action.addCard', { + context: 'title', + })} + + + {t('action.deleteList', { + context: 'title', + })} + + + {t('action.sortList', { + context: 'title', + })} + + + + ); - } - - return ( - <> - - {t('common.listActions', { - context: 'title', - })} - - - - - {t('action.editTitle', { - context: 'title', - })} - - - {t('action.addCard', { - context: 'title', - })} - - - {t('action.deleteList', { - context: 'title', - })} - - - - - ); -}); + }, +); ActionsStep.propTypes = { onNameEdit: PropTypes.func.isRequired, onCardAdd: PropTypes.func.isRequired, onDelete: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, + onSort: PropTypes.func.isRequired, + selectedOption: PropTypes.string.isRequired, + setSelectedOption: PropTypes.func.isRequired, }; export default ActionsStep; diff --git a/client/src/components/List/List.jsx b/client/src/components/List/List.jsx index f09116c..dd140fb 100755 --- a/client/src/components/List/List.jsx +++ b/client/src/components/List/List.jsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import { Draggable, Droppable } from 'react-beautiful-dnd'; import { Button, Icon } from 'semantic-ui-react'; -import { usePopup } from '../../lib/popup'; +import { usePopup, closePopup } from '../../lib/popup'; import DroppableTypes from '../../constants/DroppableTypes'; import CardContainer from '../../containers/CardContainer'; @@ -19,6 +19,7 @@ const List = React.memo( ({ id, index, name, isPersisted, cardIds, canEdit, onUpdate, onDelete, onCardCreate }) => { const [t] = useTranslation(); const [isAddCardOpened, setIsAddCardOpened] = useState(false); + const [selectedOption, setSelectedOption] = useState('name'); const nameEdit = useRef(null); const listWrapper = useRef(null); @@ -40,11 +41,11 @@ const List = React.memo( const handleAddCardClick = useCallback(() => { setIsAddCardOpened(true); - }, []); + }, [setIsAddCardOpened]); const handleAddCardClose = useCallback(() => { setIsAddCardOpened(false); - }, []); + }, [setIsAddCardOpened]); const handleNameEdit = useCallback(() => { nameEdit.current.open(); @@ -52,7 +53,12 @@ const List = React.memo( const handleCardAdd = useCallback(() => { setIsAddCardOpened(true); - }, []); + }, [setIsAddCardOpened]); + + const onSort = useCallback(() => { + onUpdate({ selectedOption: document.querySelector('input[name="sort"]:checked').value }); + closePopup(); + }, [onUpdate]); useEffect(() => { if (isAddCardOpened) { @@ -114,6 +120,9 @@ const List = React.memo( onNameEdit={handleNameEdit} onCardAdd={handleCardAdd} onDelete={onDelete} + onSort={onSort} + selectedOption={selectedOption} + setSelectedOption={setSelectedOption} >