fixed code

This commit is contained in:
Hope87 2021-06-02 14:04:26 +03:00
parent 0c3d99f039
commit 778a4f6937
3 changed files with 46 additions and 23 deletions

View File

@ -11,17 +11,34 @@ const Outstaffing = () => {
const [selectedItems, setSelectedItems] = useState([]);
useEffect(() => {
const tempData = ['Ruby on Rails', 'Nginx', 'Docker', 'PostgreSQL', 'Vue.js', 'Typescript', 'ReactJS'];
setData(tempData);
const tags = [
{
name: 'front',
img: '../../images/front_end.png',
tags: ['Vue.js', 'ReactJS', 'Angular', 'JavaScript', 'Html', 'Css'],
},
{
name: 'back',
img: '../../images/back_end.png',
tags: ['Ruby on Rails', 'Node.js', 'Express', 'Php', 'Python', 'Wordpress'],
},
{
name: 'design',
img: '../../images/design.png',
tags: ['Figma', 'Avocode', 'PhotoShop', 'Xara', 'Pinegrow', 'Macaw'],
},
];
setData(tags);
}, []);
const handleBlockClick = (index) => {
if (selectedItems.find((item) => item.value === data[index])) {
return;
// setSelectedItems(selectedItems.filter((item) => item.value !== data[index]));
} else {
setSelectedItems([...selectedItems, { value: data[index], label: data[index] }]);
const handleBlockClick = (item) => {
if (!selectedItems.find((el) => item === el.value)) {
setSelectedItems([...selectedItems, { value: item, label: item }]);
}
// else {
// setSelectedItems(selectedItems.filter((el) => item !== el.value));
// }
};
const handleSubmit = () => {
@ -50,25 +67,25 @@ const Outstaffing = () => {
<div className="col-4">
<OutstaffingBlock
image={front}
data={data}
header={'# Популярный стек'}
onClick={(index) => handleBlockClick(index)}
data={data.find((item) => item.name === 'front')}
header={'# Популярный стек'}
onClick={(item) => handleBlockClick(item)}
/>
</div>
<div className="col-4">
<OutstaffingBlock
image={back}
data={data}
data={data.find((item) => item.name === 'back')}
header={'# Популярный стек'}
onClick={(index) => handleBlockClick(index)}
onClick={(item) => handleBlockClick(item)}
/>
</div>
<div className="col-4">
<OutstaffingBlock
image={design}
data={data}
data={data.find((item) => item.name === 'design')}
header={'# Популярный стек'}
onClick={(index) => handleBlockClick(index)}
onClick={(item) => handleBlockClick(item)}
/>
</div>
</div>

View File

@ -1,3 +1,4 @@
import React from 'react';
import style from './Outstaffing.module.css';
const OutstaffingBlock = ({ text, image, data, onClick }) => {
@ -6,11 +7,14 @@ const OutstaffingBlock = ({ text, image, data, onClick }) => {
<img src={image} alt="img" />
<p>{text}</p>
<ul className={style.items}>
{data.map((item, index) => (
<li key={index.toString()} onClick={() => onClick(index)}>
{index} {item}
</li>
))}
{data &&
data.tags &&
data.tags.length &&
data.tags.map((item) => (
<li key={item} onClick={() => onClick(item)}>
{item}
</li>
))}
</ul>
</div>
);

View File

@ -18,9 +18,11 @@ const TagSelect = ({ selectedItems, tagSubmit, options, setSelectedItems }) => {
name="tags"
className={style.select}
classNamePrefix={style.select}
options={options.map((item) => {
return { value: item, label: item };
})}
options={options
.flatMap((el) => el.tags)
.map((item) => {
return { value: item, label: item };
})}
/>
<button onClick={tagSubmit} type="submit">
Submit