2021-11-30 16:00:58 +02:00
|
|
|
import React, { useState, useEffect } from 'react'
|
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
|
|
import Outstaffing from '../Outstaffing/Outstaffing'
|
|
|
|
import Description from '../Description/Description'
|
|
|
|
import { fetchGet } from '../../server/server'
|
|
|
|
import { profiles, tags, auth } from '../../redux/outstaffingSlice'
|
|
|
|
import { getRole } from '../../redux/roleSlice'
|
|
|
|
import { Footer } from '../Footer/Footer'
|
|
|
|
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-11-30 16:00:58 +02:00
|
|
|
const [isLoadingMore, setIsLoadingMore] = useState(false)
|
|
|
|
const [index, setIndex] = useState(4)
|
2021-06-03 17:15:22 +03:00
|
|
|
|
2021-11-30 16:00:58 +02: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-11-30 16:00:58 +02:00
|
|
|
setIsLoadingMore(true)
|
|
|
|
fetchGet({
|
|
|
|
link: `${process.env.REACT_APP_API_URL}/api/profile?limit=`,
|
|
|
|
params: index,
|
|
|
|
history,
|
|
|
|
role,
|
|
|
|
logout: () => dispatch(auth(false))
|
|
|
|
}).then((profileArr) => {
|
|
|
|
dispatch(profiles(profileArr))
|
|
|
|
setIsLoadingMore(false)
|
|
|
|
})
|
2021-06-30 17:21:55 +03:00
|
|
|
|
2021-11-30 16:00:58 +02:00
|
|
|
fetchGet({
|
|
|
|
link: `${process.env.REACT_APP_API_URL}/api/skills/skills-on-main-page`,
|
|
|
|
history,
|
|
|
|
role,
|
|
|
|
logout: () => dispatch(auth(false))
|
|
|
|
}).then((skills) => {
|
|
|
|
if (!skills) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
const keys = Object.keys(skills)
|
|
|
|
const values = Object.values(skills)
|
2021-06-30 17:21:55 +03:00
|
|
|
|
|
|
|
const tempTags = values.map((value, index) =>
|
|
|
|
value.map((val) => {
|
2021-11-30 16:00:58 +02:00
|
|
|
return { id: val.id, value: val.tags, name: keys[index] }
|
2021-06-30 17:21:55 +03:00
|
|
|
})
|
2021-11-30 16:00:58 +02:00
|
|
|
)
|
|
|
|
dispatch(tags(tempTags))
|
|
|
|
})
|
|
|
|
}, [dispatch, index])
|
2021-06-28 17:57:28 +03:00
|
|
|
|
2021-06-29 17:58:15 +03:00
|
|
|
const loadMore = (count) => {
|
2021-11-30 16:00:58 +02:00
|
|
|
setIndex((prev) => prev + count)
|
|
|
|
}
|
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-11-30 16:00:58 +02:00
|
|
|
)
|
|
|
|
}
|
2021-05-26 13:35:57 +03:00
|
|
|
|
2021-11-30 16:00:58 +02:00
|
|
|
export default Home
|