116 lines
3.1 KiB
JavaScript
Raw Normal View History

2021-06-07 17:48:07 +03:00
import React, { useState, useEffect } from 'react';
2021-06-01 15:25:01 +03:00
import Outstaffing from '../Outstaffing/Outstaffing';
import Description from '../Description/Description';
2021-06-02 18:25:25 +03:00
import front from '../../images/front_end.png';
import back from '../../images/back_end.png';
import design from '../../images/design.png';
2021-06-29 17:58:15 +03:00
import { fetchProfile, fetchSkills } from '../../server/server';
2021-05-26 13:35:57 +03:00
2021-06-07 17:48:07 +03:00
const tabsList = [
{
name: 'Frontend',
img: front,
text: '# Популярный стек',
header: 'Фронтенд',
},
{
name: 'Backend',
img: back,
text: '# Популярный стек',
header: 'Бэкенд',
},
{
name: 'Design',
img: design,
text: '# Популярный стек',
header: 'Дизайн',
},
];
2021-06-29 17:58:15 +03:00
const Home = ({ getCandidate }) => {
2021-06-03 17:15:22 +03:00
const [tabs, setTabs] = useState([]);
2021-06-15 17:08:06 +03:00
const [tags, setTags] = useState([]);
2021-06-29 17:58:15 +03:00
const [profiles, setProfiles] = useState([]);
2021-06-07 17:48:07 +03:00
const [selectedTab, setSelectedTab] = useState('');
2021-06-29 17:58:15 +03:00
const [countArr, setCountArr] = useState(0);
const [candidatesArray, setCandidatesArray] = useState([]);
2021-06-03 17:15:22 +03:00
2021-06-29 17:58:15 +03:00
useEffect(() => {
setTabs(tabsList);
2021-06-28 17:57:28 +03:00
2021-06-29 17:58:15 +03:00
fetchProfile('https://guild.craft-group.xyz/api/profile')
.then((profileArr) => setProfiles(profileArr))
.catch((e) => console.log(e));
}, []);
2021-06-28 17:57:28 +03:00
2021-06-07 17:48:07 +03:00
useEffect(() => {
2021-06-29 17:58:15 +03:00
if (profiles.length) {
setCandidatesArray(
profiles.map((profile) => {
let skillsName = '';
let img;
2021-06-14 17:47:37 +03:00
2021-06-29 17:58:15 +03:00
if (Number(profile.position_id) === 1) {
skillsName = 'Frontend';
img = front;
} else if (Number(profile.position_id) === 2) {
skillsName = 'Backend';
img = back;
} else if (Number(profile.position_id) === 3) {
skillsName = 'Marketer';
img = design;
}
2021-06-22 18:00:52 +03:00
2021-06-29 17:58:15 +03:00
return {
id: profile.id,
profileId: profile.position_id,
name: profile.fio,
skills: profile.skillValues,
skillsName: skillsName,
img: img,
};
})
);
}
}, [profiles]);
2021-06-15 17:08:06 +03:00
2021-06-29 17:58:15 +03:00
useEffect(() => {
fetchSkills('https://guild.craft-group.xyz/api/skills/skills-on-main-page').then((skills) => {
const keys = Object.keys(skills);
const values = Object.values(skills);
2021-06-15 17:08:06 +03:00
2021-06-29 17:58:15 +03:00
const tempTags = values.map((value, index) =>
value.map((val) => {
return { id: val.id, value: val.tags, name: keys[index] };
})
);
setTags(tempTags);
});
2021-06-07 17:48:07 +03:00
}, []);
2021-06-03 17:15:22 +03:00
2021-06-29 17:58:15 +03:00
const shorthandArray = candidatesArray.slice(countArr, 2);
const loadMore = (count) => {
setCountArr((prev) => prev + count);
};
2021-06-07 17:48:07 +03:00
const handleBlockClick = (name) => {
setSelectedTab(name);
2021-06-03 17:15:22 +03:00
};
2021-06-07 17:48:07 +03:00
2021-05-26 13:35:57 +03:00
return (
2021-05-26 15:59:00 +03:00
<>
2021-06-15 17:08:06 +03:00
<Outstaffing onhandleTabBar={(name) => handleBlockClick(name)} selected={selectedTab} tabs={tabs} tags={tags} />
2021-06-07 17:48:07 +03:00
<Description
2021-06-29 17:58:15 +03:00
candidatesListArr={
selectedTab ? candidatesArray.filter((item) => item.skillsName === selectedTab) : shorthandArray
}
getCandidate={getCandidate}
onLoadMore={loadMore}
2021-06-07 17:48:07 +03:00
/>
2021-05-26 15:59:00 +03:00
</>
2021-05-26 13:35:57 +03:00
);
};
export default Home;