Update saved teams
This commit is contained in:
parent
45aa8c38ab
commit
55a292529f
1 changed files with 26 additions and 10 deletions
|
|
@ -22,7 +22,8 @@ import type { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import type { PaginationObject } from '~types'
|
import type { PaginationObject } from '~types'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
teams?: { count: number; total_pages: number; results: Party[] }
|
teams?: Party[]
|
||||||
|
meta: PaginationObject
|
||||||
raids: Raid[]
|
raids: Raid[]
|
||||||
sortedRaids: Raid[][]
|
sortedRaids: Raid[][]
|
||||||
}
|
}
|
||||||
|
|
@ -95,9 +96,9 @@ const SavedRoute: React.FC<Props> = (props: Props) => {
|
||||||
// Set the initial parties from props
|
// Set the initial parties from props
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.teams) {
|
if (props.teams) {
|
||||||
setTotalPages(props.teams.total_pages)
|
setTotalPages(props.meta.totalPages)
|
||||||
setRecordCount(props.teams.count)
|
setRecordCount(props.meta.count)
|
||||||
replaceResults(props.teams.count, props.teams.results)
|
replaceResults(props.meta.count, props.teams)
|
||||||
}
|
}
|
||||||
setCurrentPage(1)
|
setCurrentPage(1)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
@ -131,12 +132,14 @@ const SavedRoute: React.FC<Props> = (props: Props) => {
|
||||||
api
|
api
|
||||||
.savedTeams({ ...filters, ...{ headers: headers } })
|
.savedTeams({ ...filters, ...{ headers: headers } })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setTotalPages(response.data.meta.total_pages)
|
const results = response.data.results
|
||||||
setRecordCount(response.data.meta.count)
|
const meta = response.data.meta
|
||||||
|
|
||||||
if (replace)
|
setTotalPages(meta.total_pages)
|
||||||
replaceResults(response.data.meta.count, response.data.results)
|
setRecordCount(meta.count)
|
||||||
else appendResults(response.data.results)
|
|
||||||
|
if (replace) replaceResults(meta.count, results)
|
||||||
|
else appendResults(results)
|
||||||
})
|
})
|
||||||
.catch((error) => handleError(error))
|
.catch((error) => handleError(error))
|
||||||
},
|
},
|
||||||
|
|
@ -377,6 +380,13 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
||||||
if (teamElement && teamElement.id > -1) filters.element = teamElement.id
|
if (teamElement && teamElement.id > -1) filters.element = teamElement.id
|
||||||
if (raid) filters.raid = raid.id
|
if (raid) filters.raid = raid.id
|
||||||
|
|
||||||
|
let teams: Party[] | null = null
|
||||||
|
let meta: PaginationObject = {
|
||||||
|
count: 0,
|
||||||
|
totalPages: 0,
|
||||||
|
perPage: 15,
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch initial set of parties here
|
// Fetch initial set of parties here
|
||||||
const response = await api.savedTeams({
|
const response = await api.savedTeams({
|
||||||
params: {
|
params: {
|
||||||
|
|
@ -384,10 +394,16 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
||||||
},
|
},
|
||||||
...headers
|
...headers
|
||||||
})
|
})
|
||||||
|
|
||||||
|
teams = response.data.results
|
||||||
|
meta.count = response.data.meta.count
|
||||||
|
meta.totalPages = response.data.meta.total_pages
|
||||||
|
meta.perPage = response.data.meta.per_page
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
teams: response.data,
|
teams: teams,
|
||||||
|
meta: meta,
|
||||||
raids: raids,
|
raids: raids,
|
||||||
sortedRaids: sortedRaids,
|
sortedRaids: sortedRaids,
|
||||||
...(await serverSideTranslations(locale, ["common"])),
|
...(await serverSideTranslations(locale, ["common"])),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue