Submit TagsChoosePopUp search handler
This commit is contained in:
parent
2c4c89ef80
commit
203d2f8cd0
@ -6,13 +6,16 @@ import theme from '../../../../utils/theme';
|
|||||||
import Button from '../../../../components/generic/Button';
|
import Button from '../../../../components/generic/Button';
|
||||||
import TagsChoosePopUpStyle from './TagsChoosePopUpStyle';
|
import TagsChoosePopUpStyle from './TagsChoosePopUpStyle';
|
||||||
import renderTagItems from './functions/renderTagItems';
|
import renderTagItems from './functions/renderTagItems';
|
||||||
|
import tagsSearchQueryHandler from './functions/tagsSearchQueryHandler';
|
||||||
|
|
||||||
const TagsChoosePopUp = (props) => {
|
const TagsChoosePopUp = (props) => {
|
||||||
const [tagsChoosed, setTagsChoosed] = React.useState([]);
|
const [tagsChoosed, setTagsChoosed] = React.useState([]);
|
||||||
|
const [tagsInit, setTagsInit] = React.useState([]);
|
||||||
const [tags, setTags] = React.useState([]);
|
const [tags, setTags] = React.useState([]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setTags(props.tags.slice());
|
setTags(props.tags.slice());
|
||||||
|
setTagsInit(props.tags.slice());
|
||||||
setTagsChoosed(props.submissionTags.slice());
|
setTagsChoosed(props.submissionTags.slice());
|
||||||
}, [props.tags, props.submissionTags]);
|
}, [props.tags, props.submissionTags]);
|
||||||
|
|
||||||
@ -41,7 +44,11 @@ const TagsChoosePopUp = (props) => {
|
|||||||
closeHandler={() => props.setTagsPopUp(false)}
|
closeHandler={() => props.setTagsPopUp(false)}
|
||||||
>
|
>
|
||||||
<TagsChoosePopUpStyle>
|
<TagsChoosePopUpStyle>
|
||||||
<Search />
|
<Search
|
||||||
|
searchQueryHandler={(e) =>
|
||||||
|
tagsSearchQueryHandler(e, tagsInit, tagsChoosed, setTags)
|
||||||
|
}
|
||||||
|
/>
|
||||||
<FlexColumn as="ul" className="TagsChoosePopUpStyle__tags-list">
|
<FlexColumn as="ul" className="TagsChoosePopUpStyle__tags-list">
|
||||||
{renderTagItems(
|
{renderTagItems(
|
||||||
tagsChoosed,
|
tagsChoosed,
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
const tagsSearchQueryHandler = (event, tagsInit, tagsChoosed, setTags) => {
|
||||||
|
let tagsToSearch = tagsInit;
|
||||||
|
for (let tagChoosen of tagsChoosed)
|
||||||
|
tagsToSearch = tagsToSearch.filter((tag) => tag.name !== tagChoosen.name);
|
||||||
|
const searchQuery = event.target.value;
|
||||||
|
let tagsToRender = [];
|
||||||
|
if (searchQuery === '') {
|
||||||
|
setTags(tagsToSearch);
|
||||||
|
} else {
|
||||||
|
for (let tag of tagsToSearch) {
|
||||||
|
if (tag.name.toLowerCase().includes(searchQuery.toLowerCase()))
|
||||||
|
tagsToRender.push(tag);
|
||||||
|
}
|
||||||
|
setTags(tagsToRender);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default tagsSearchQueryHandler;
|
Loading…
Reference in New Issue
Block a user