Update all teams
This commit is contained in:
parent
adc987201e
commit
45aa8c38ab
4 changed files with 30 additions and 13 deletions
|
|
@ -164,7 +164,7 @@ const GridRep = (props: Props) => {
|
||||||
!props.user) ? (
|
!props.user) ? (
|
||||||
<Button
|
<Button
|
||||||
className="Save"
|
className="Save"
|
||||||
accessoryIcon={<SaveIcon class="stroke" />}
|
accessoryIcon={<SaveIcon className="stroke" />}
|
||||||
active={props.favorited}
|
active={props.favorited}
|
||||||
contained={true}
|
contained={true}
|
||||||
buttonSize="small"
|
buttonSize="small"
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import GridRepCollection from '~components/GridRepCollection'
|
||||||
import FilterBar from '~components/FilterBar'
|
import FilterBar from '~components/FilterBar'
|
||||||
|
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { PaginationObject } from '~types'
|
import type { PaginationObject } from '~types'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
user?: User
|
user?: User
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import GridRepCollection from '~components/GridRepCollection'
|
||||||
import FilterBar from '~components/FilterBar'
|
import FilterBar from '~components/FilterBar'
|
||||||
|
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||||
|
import type { PaginationObject } from '~types'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
teams?: { count: number; total_pages: number; results: Party[] }
|
teams?: { count: number; total_pages: number; results: Party[] }
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,11 @@ import GridRepCollection from '~components/GridRepCollection'
|
||||||
import FilterBar from '~components/FilterBar'
|
import FilterBar from '~components/FilterBar'
|
||||||
|
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||||
|
import type { PaginationObject } from '~types'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
teams?: { count: number; total_pages: number; results: Party[] }
|
teams?: Party[]
|
||||||
raids: Raid[]
|
meta: PaginationObject
|
||||||
sortedRaids: Raid[][]
|
sortedRaids: Raid[][]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,9 +95,9 @@ const TeamsRoute: 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)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
@ -130,12 +131,14 @@ const TeamsRoute: React.FC<Props> = (props: Props) => {
|
||||||
api.endpoints.parties
|
api.endpoints.parties
|
||||||
.getAll({ ...filters, ...{ headers: headers } })
|
.getAll({ ...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))
|
||||||
},
|
},
|
||||||
|
|
@ -384,6 +387,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.endpoints.parties.getAll({
|
const response = await api.endpoints.parties.getAll({
|
||||||
params: {
|
params: {
|
||||||
|
|
@ -392,9 +402,15 @@ 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