Signed-off-by: Ky <virginie.ky@gmail.com>
This commit is contained in:
Ky 2020-02-22 12:01:07 +01:00
parent 783b3f1a36
commit 65c8968b84
6 changed files with 42 additions and 43 deletions

View File

@ -18,7 +18,6 @@ const colors = {
lightGrey: '#fafafa',
grey: '#9ea7b8',
greyDark: '#292b2c',
greyLightest: '#e3e9f3',
content: {
background: '#fafafb',

View File

@ -20,15 +20,15 @@ const SortButton = styled.button`
${({ isActive, theme }) =>
isActive
? `
background-color: ${theme.main.colors.filters.button.active.background};
border: 1px solid ${theme.main.colors.filters.button.active.border};
color: ${theme.main.colors.filters.button.active.color};
`
background-color: ${theme.main.colors.filters.button.active.background};
border: 1px solid ${theme.main.colors.filters.button.active.border};
color: ${theme.main.colors.filters.button.active.color};
`
: `
&:hover {
background-color: ${theme.main.colors.filters.button.hover.background};
}
`}
&:hover {
background-color: ${theme.main.colors.filters.button.hover.background};
}
`}
`;
SortButton.defaultProps = {
@ -36,8 +36,8 @@ SortButton.defaultProps = {
};
SortButton.propTypes = {
...themePropTypes,
isActive: PropTypes.bool,
...themePropTypes,
};
export default SortButton;

View File

@ -1,4 +1,5 @@
import styled from 'styled-components';
import PropTypes from 'prop-types';
import { themePropTypes } from 'strapi-helper-plugin';
const SortList = styled.ul`
@ -18,7 +19,12 @@ const SortList = styled.ul`
${({ isOpen }) => isOpen && 'display: block;'}
`;
SortList.defaultProps = {
isOpen: false,
};
SortList.propTypes = {
isOpen: PropTypes.bool,
...themePropTypes,
};

View File

@ -1,4 +1,5 @@
import styled from 'styled-components';
import PropTypes from 'prop-types';
import { themePropTypes } from 'strapi-helper-plugin';
const SortListItem = styled.li`
@ -17,7 +18,12 @@ const SortListItem = styled.li`
`}
`;
SortListItem.defaultProps = {
isActive: false,
};
SortListItem.propTypes = {
isActive: PropTypes.bool,
...themePropTypes,
};

View File

@ -12,15 +12,6 @@ import SortListItem from './SortListItem';
const SortPicker = ({ onChange, value }) => {
const [isOpen, setIsOpen] = useState(false);
const toggle = () => {
setIsOpen(!isOpen);
};
const handleChange = value => {
onChange({ target: { value } });
toggle();
};
const orders = {
created_at_asc: 'created_at:ASC',
created_at_desc: 'created_at:DESC',
@ -30,9 +21,19 @@ const SortPicker = ({ onChange, value }) => {
updated_at_desc: 'updated_at:DESC',
};
const handleChange = value => {
onChange({ target: { value } });
hangleToggle();
};
const hangleToggle = () => {
setIsOpen(!isOpen);
};
return (
<Wrapper>
<SortButton onClick={toggle} isActive={isOpen}>
<SortButton onClick={hangleToggle} isActive={isOpen}>
<FormattedMessage id={getTrad('sort.label')} />
</SortButton>
<SortList isOpen={isOpen}>

View File

@ -30,10 +30,6 @@ const HomePage = () => {
const { data, dataToDelete, _sort, _q } = reducerState.toJS();
const pluginName = formatMessage({ id: getTrad('plugin.name') });
useEffect(() => {
// TODO - Get data
}, []);
useEffect(() => {
const searchParams = getSearchParams();
@ -63,39 +59,30 @@ const HomePage = () => {
};
};
const handleChangeParams = ({ target: { name, value } }) => {
const updatedSearch = getUpdatedSearchParams({ [name]: value });
const handleChangeParams = ({ key, value }) => {
const updatedSearch = getUpdatedSearchParams({ [key]: value });
const newSearch = generateSearchFromFilters(updatedSearch);
push({ search: newSearch });
};
const handleChangeSearch = ({ target: { value } }) => {
dispatch({
type: 'ON_QUERY_CHANGE',
key: '_q',
value,
});
handleChangeParams({
target: {
name: '_q',
value,
},
});
handleChangeQuery({ key: '_q', value });
};
const handleChangeSort = ({ target: { value } }) => {
handleChangeQuery({ key: '_sort', value });
};
const handleChangeQuery = ({ key, value }) => {
dispatch({
type: 'ON_QUERY_CHANGE',
key: '_sort',
key,
value,
});
handleChangeParams({
target: {
name: '_sort',
value,
},
key,
value,
});
};