Move to use useDidMountEffect
This commit is contained in:
parent
8ff8212469
commit
86656e1bff
1 changed files with 22 additions and 18 deletions
|
|
@ -106,20 +106,6 @@ const ProfileRoute: React.FC<Props> = (props: Props) => {
|
||||||
return () => window.removeEventListener("scroll", handleScroll)
|
return () => window.removeEventListener("scroll", handleScroll)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// When the element, raid or recency filter changes,
|
|
||||||
// fetch all teams again.
|
|
||||||
useDidMountEffect(() => {
|
|
||||||
setCurrentPage(1)
|
|
||||||
fetchProfile({ replace: true })
|
|
||||||
}, [element, raid, recency])
|
|
||||||
|
|
||||||
// When the page changes, fetch all teams again.
|
|
||||||
useDidMountEffect(() => {
|
|
||||||
// Current page changed
|
|
||||||
if (currentPage > 1) fetchProfile({ replace: false })
|
|
||||||
else if (currentPage == 1) fetchProfile({ replace: true })
|
|
||||||
}, [currentPage])
|
|
||||||
|
|
||||||
// Handle errors
|
// Handle errors
|
||||||
const handleError = useCallback((error: any) => {
|
const handleError = useCallback((error: any) => {
|
||||||
if (error.response != null) {
|
if (error.response != null) {
|
||||||
|
|
@ -140,7 +126,7 @@ const ProfileRoute: React.FC<Props> = (props: Props) => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username && !Array.isArray(username))
|
if (username && !Array.isArray(username)) {
|
||||||
api.endpoints.users
|
api.endpoints.users
|
||||||
.getOne({
|
.getOne({
|
||||||
id: username,
|
id: username,
|
||||||
|
|
@ -157,8 +143,8 @@ const ProfileRoute: React.FC<Props> = (props: Props) => {
|
||||||
)
|
)
|
||||||
else appendResults(response.data.parties.results)
|
else appendResults(response.data.parties.results)
|
||||||
})
|
})
|
||||||
.then(() => {})
|
|
||||||
.catch((error) => handleError(error))
|
.catch((error) => handleError(error))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[currentPage, parties, element, raid, recency]
|
[currentPage, parties, element, raid, recency]
|
||||||
)
|
)
|
||||||
|
|
@ -190,6 +176,20 @@ const ProfileRoute: React.FC<Props> = (props: Props) => {
|
||||||
})
|
})
|
||||||
}, [setRaids])
|
}, [setRaids])
|
||||||
|
|
||||||
|
// When the element, raid or recency filter changes,
|
||||||
|
// fetch all teams again.
|
||||||
|
useDidMountEffect(() => {
|
||||||
|
setCurrentPage(1)
|
||||||
|
fetchProfile({ replace: true })
|
||||||
|
}, [element, raid, recency])
|
||||||
|
|
||||||
|
// When the page changes, fetch all teams again.
|
||||||
|
useDidMountEffect(() => {
|
||||||
|
// Current page changed
|
||||||
|
if (currentPage > 1) fetchProfile({ replace: false })
|
||||||
|
else if (currentPage == 1) fetchProfile({ replace: true })
|
||||||
|
}, [currentPage])
|
||||||
|
|
||||||
// Receive filters from the filter bar
|
// Receive filters from the filter bar
|
||||||
function receiveFilters({
|
function receiveFilters({
|
||||||
element,
|
element,
|
||||||
|
|
@ -304,6 +304,7 @@ const ProfileRoute: React.FC<Props> = (props: Props) => {
|
||||||
>
|
>
|
||||||
<GridRepCollection>{renderParties()}</GridRepCollection>
|
<GridRepCollection>{renderParties()}</GridRepCollection>
|
||||||
</InfiniteScroll>
|
</InfiniteScroll>
|
||||||
|
|
||||||
{parties.length == 0 ? (
|
{parties.length == 0 ? (
|
||||||
<div id="NotFound">
|
<div id="NotFound">
|
||||||
<h2>{t("teams.not_found")}</h2>
|
<h2>{t("teams.not_found")}</h2>
|
||||||
|
|
@ -373,9 +374,12 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
||||||
let user: User | null = null
|
let user: User | null = null
|
||||||
let teams: Party[] | null = null
|
let teams: Party[] | null = null
|
||||||
if (query.username) {
|
if (query.username) {
|
||||||
let response = await api.endpoints.users.getOne({
|
const response = await api.endpoints.users.getOne({
|
||||||
id: query.username,
|
id: query.username,
|
||||||
params: { params: { ...filters, ...{ headers: headers } } },
|
params: {
|
||||||
|
params: filters,
|
||||||
|
...headers
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
user = response.data.user
|
user = response.data.user
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue