53 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-06-07 17:48:07 +03:00
import React, { useState, useEffect } from 'react';
2021-08-20 17:33:29 +03:00
import { useDispatch, useSelector } from 'react-redux';
2021-06-01 15:25:01 +03:00
import Outstaffing from '../Outstaffing/Outstaffing';
import Description from '../Description/Description';
2021-07-02 16:02:47 +03:00
import { fetchProfile, fetchSkills } from '../../server/server';
2021-07-05 12:33:24 +03:00
import { profiles, tags } from '../../redux/outstaffingSlice';
2021-08-20 17:33:29 +03:00
import { getRole } from '../../redux/roleSlice';
2021-08-18 18:16:57 +03:00
import { Footer } from '../Footer/Footer';
2021-08-20 17:33:29 +03:00
import { useHistory } from 'react-router-dom';
2021-06-07 17:48:07 +03:00
2021-07-02 16:02:47 +03:00
const Home = () => {
2021-08-20 17:33:29 +03:00
const history = useHistory()
2021-08-18 16:18:11 +03:00
const [isLoadingMore, setIsLoadingMore] = useState(false);
2021-07-12 17:30:36 +03:00
const [index, setIndex] = useState(4);
2021-06-03 17:15:22 +03:00
2021-06-30 17:21:55 +03:00
const dispatch = useDispatch();
2021-08-20 17:33:29 +03:00
const role = useSelector(getRole)
2021-06-28 17:57:28 +03:00
2021-06-30 17:21:55 +03:00
useEffect(() => {
2021-08-18 16:18:11 +03:00
setIsLoadingMore(true);
2021-08-20 17:33:29 +03:00
fetchProfile({ link:`${process.env.REACT_APP_API_URL}/api/profile?limit=`, index, history, role}).then((profileArr) => {
2021-08-18 16:18:11 +03:00
dispatch(profiles(profileArr));
setIsLoadingMore(false);
});
2021-06-30 17:21:55 +03:00
2021-08-20 17:33:29 +03:00
fetchSkills({ link: `${process.env.REACT_APP_API_URL}/api/skills/skills-on-main-page`, history, role}).then((skills) => {
2021-06-30 17:21:55 +03:00
const keys = Object.keys(skills);
const values = Object.values(skills);
const tempTags = values.map((value, index) =>
value.map((val) => {
return { id: val.id, value: val.tags, name: keys[index] };
})
);
dispatch(tags(tempTags));
});
2021-07-02 16:02:47 +03:00
}, [dispatch, index]);
2021-06-28 17:57:28 +03:00
2021-06-29 17:58:15 +03:00
const loadMore = (count) => {
2021-07-02 16:02:47 +03:00
setIndex((prev) => prev + count);
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-07-01 14:25:17 +03:00
<Outstaffing />
2021-08-18 16:18:11 +03:00
<Description onLoadMore={loadMore} isLoadingMore={isLoadingMore} />
2021-08-18 18:16:57 +03:00
<Footer />
2021-05-26 15:59:00 +03:00
</>
2021-05-26 13:35:57 +03:00
);
};
export default Home;