From 54269bef03216bddd1660f3d58ced21fff6f9725 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Mon, 5 Jul 2021 14:33:35 +0300 Subject: [PATCH] added opportunity to reload domains which depending of those roles --- src/pages/HomePage/HomePage.jsx | 26 ++++++++++++++------------ src/redux/reducers/domains.js | 25 ------------------------- 2 files changed, 14 insertions(+), 37 deletions(-) diff --git a/src/pages/HomePage/HomePage.jsx b/src/pages/HomePage/HomePage.jsx index 7eea060..b3a27ba 100644 --- a/src/pages/HomePage/HomePage.jsx +++ b/src/pages/HomePage/HomePage.jsx @@ -27,31 +27,33 @@ const HomePage = ({ const dispatch = useDispatch(); const [techParams, setTechParams] = useState(isTech); + const [previousTechParams, setPreviousTechParams] = useState(isTech); const onSelectTech = (value) => { setIsLoading(true); + setPreviousTechParams(isTech); setTechParams(value); dispatch(setSortByRoles(value)); }; useEffect(() => { if (domains.length === 0) { - if (isTech === 'init') { - (async () => { - await fetchDomains(0, false, isTech); - setIsLoading(false); - })(); - } else { - (async () => { - await fetchDomains(0, false, isTech); - setIsLoading(false); - })(); - } - } else { + (async () => { + await fetchDomains(0, false, isTech); + setIsLoading(false); + })();} + else if (previousTechParams !== isTech) { + (async () => { + await fetchDomains(0, false, isTech); + setIsLoading(false); + })();} + else { setIsLoading(false); } }, [fetchDomains, isTech]); + console.log(totalDomains); + if (isLoading) return ; return ( diff --git a/src/redux/reducers/domains.js b/src/redux/reducers/domains.js index 804dbbc..0c08367 100644 --- a/src/redux/reducers/domains.js +++ b/src/redux/reducers/domains.js @@ -143,30 +143,6 @@ const failDomainUnlock = (payload) => ({ type: UNLOCK_DOMAIN_FAILURE, }); -// const fetchRawDomainList = async (isTech) => { -// let offset = 0; -// let domains = []; -// let count = 0; - -// let res = await api.fetchDomains(null, offset, false, isTech); -// domains = domains.concat(res.data.domains); -// count = res.data.count; -// if (offset < count) { -// offset += 200; -// } else { -// return domains; -// } - -// while (offset < count) { -// res = api.fetchDomains(null, offset, false); -// domains = domains.concat(res.data.domains); -// if (offset < count) { -// offset += 200; -// } -// } -// return domains; -// }; - const fetchDomain = (uuid) => (dispatch) => { dispatch(requestDomain()); return api @@ -368,5 +344,4 @@ export { lockDomain, parseDomain, unlockDomain, - // fetchRawDomainList, };