Update profile and filter bar
This commit is contained in:
parent
caf2bca38f
commit
adc987201e
8 changed files with 50 additions and 31 deletions
|
|
@ -69,7 +69,7 @@ const FilterBar = (props: Props) => {
|
||||||
<div className={classes}>
|
<div className={classes}>
|
||||||
{props.children}
|
{props.children}
|
||||||
<Select
|
<Select
|
||||||
defaultValue={-1}
|
defaultValue="-1"
|
||||||
trigger={'All elements'}
|
trigger={'All elements'}
|
||||||
open={elementOpen}
|
open={elementOpen}
|
||||||
onChange={elementSelectChanged}
|
onChange={elementSelectChanged}
|
||||||
|
|
@ -110,7 +110,7 @@ const FilterBar = (props: Props) => {
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
defaultValue={-1}
|
defaultValue="-1"
|
||||||
trigger={'All time'}
|
trigger={'All time'}
|
||||||
open={recencyOpen}
|
open={recencyOpen}
|
||||||
onChange={recencySelectChanged}
|
onChange={recencySelectChanged}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ const GridRep = (props: Props) => {
|
||||||
let url = ''
|
let url = ''
|
||||||
|
|
||||||
if (mainhand) {
|
if (mainhand) {
|
||||||
if (mainhand.element == 0 && props.grid[0].element) {
|
if (mainhand.element == 0 && props.grid[0] && props.grid[0].element) {
|
||||||
url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-main/${mainhand.granblue_id}_${props.grid[0].element}.jpg`
|
url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-main/${mainhand.granblue_id}_${props.grid[0].element}.jpg`
|
||||||
} else {
|
} else {
|
||||||
url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-main/${mainhand.granblue_id}.jpg`
|
url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-main/${mainhand.granblue_id}.jpg`
|
||||||
|
|
|
||||||
|
|
@ -85,8 +85,8 @@ const SearchModal = (props: Props) => {
|
||||||
page: currentPage,
|
page: currentPage,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setTotalPages(response.data.total_pages)
|
setTotalPages(response.data.meta.total_pages)
|
||||||
setRecordCount(response.data.count)
|
setRecordCount(response.data.meta.count)
|
||||||
|
|
||||||
if (replace) {
|
if (replace) {
|
||||||
replaceResults(response.data.count, response.data.results)
|
replaceResults(response.data.count, response.data.results)
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,12 @@ 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'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
user?: User
|
user?: User
|
||||||
teams?: { count: number; total_pages: number; results: Party[] }
|
teams?: Party[]
|
||||||
|
meta: PaginationObject
|
||||||
raids: Raid[]
|
raids: Raid[]
|
||||||
sortedRaids: Raid[][]
|
sortedRaids: Raid[][]
|
||||||
}
|
}
|
||||||
|
|
@ -95,9 +97,9 @@ const ProfileRoute: 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)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
@ -113,6 +115,7 @@ const ProfileRoute: React.FC<Props> = (props: Props) => {
|
||||||
if (error.response != null) {
|
if (error.response != null) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: Put an alert here
|
||||||
console.error('There was an error.')
|
console.error('There was an error.')
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
@ -135,15 +138,14 @@ const ProfileRoute: React.FC<Props> = (props: Props) => {
|
||||||
params: { ...filters, ...{ headers: headers } },
|
params: { ...filters, ...{ headers: headers } },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setTotalPages(response.data.parties.total_pages)
|
const results = response.data.profile.parties
|
||||||
setRecordCount(response.data.parties.count)
|
const meta = response.data.meta
|
||||||
|
|
||||||
if (replace)
|
setTotalPages(meta.total_pages)
|
||||||
replaceResults(
|
setRecordCount(meta.count)
|
||||||
response.data.parties.count,
|
|
||||||
response.data.parties.results
|
if (replace) replaceResults(meta.count, results)
|
||||||
)
|
else appendResults(results)
|
||||||
else appendResults(response.data.parties.results)
|
|
||||||
})
|
})
|
||||||
.catch((error) => handleError(error))
|
.catch((error) => handleError(error))
|
||||||
}
|
}
|
||||||
|
|
@ -282,11 +284,11 @@ const ProfileRoute: React.FC<Props> = (props: Props) => {
|
||||||
>
|
>
|
||||||
<div className="UserInfo">
|
<div className="UserInfo">
|
||||||
<img
|
<img
|
||||||
alt={props.user?.picture.picture}
|
alt={props.user?.avatar.picture}
|
||||||
className={`profile ${props.user?.picture.element}`}
|
className={`profile ${props.user?.avatar.element}`}
|
||||||
srcSet={`/profile/${props.user?.picture.picture}.png,
|
srcSet={`/profile/${props.user?.avatar.picture}.png,
|
||||||
/profile/${props.user?.picture.picture}@2x.png 2x`}
|
/profile/${props.user?.avatar.picture}@2x.png 2x`}
|
||||||
src={`/profile/${props.user?.picture.picture}.png`}
|
src={`/profile/${props.user?.avatar.picture}.png`}
|
||||||
/>
|
/>
|
||||||
<h1>{props.user?.username}</h1>
|
<h1>{props.user?.username}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -374,6 +376,12 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
||||||
// Fetch initial set of parties here
|
// Fetch initial set of parties here
|
||||||
let user: User | null = null
|
let user: User | null = null
|
||||||
let teams: Party[] | null = null
|
let teams: Party[] | null = null
|
||||||
|
let meta: PaginationObject = {
|
||||||
|
count: 0,
|
||||||
|
totalPages: 0,
|
||||||
|
perPage: 15
|
||||||
|
}
|
||||||
|
|
||||||
if (query.username) {
|
if (query.username) {
|
||||||
const response = await api.endpoints.users.getOne({
|
const response = await api.endpoints.users.getOne({
|
||||||
id: query.username,
|
id: query.username,
|
||||||
|
|
@ -383,14 +391,19 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
||||||
...headers,
|
...headers,
|
||||||
})
|
})
|
||||||
|
|
||||||
user = response.data.user
|
user = response.data.profile
|
||||||
teams = response.data.parties
|
teams = response.data.profile.parties
|
||||||
|
|
||||||
|
meta.count = response.data.meta.count
|
||||||
|
meta.totalPages = response.data.meta.total_pages
|
||||||
|
meta.perPage = response.data.meta.per_page
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
user: user,
|
user: user,
|
||||||
teams: teams,
|
teams: teams,
|
||||||
|
meta: meta,
|
||||||
raids: raids,
|
raids: raids,
|
||||||
sortedRaids: sortedRaids,
|
sortedRaids: sortedRaids,
|
||||||
...(await serverSideTranslations(locale, ["common"])),
|
...(await serverSideTranslations(locale, ["common"])),
|
||||||
|
|
|
||||||
|
|
@ -130,11 +130,11 @@ const SavedRoute: React.FC<Props> = (props: Props) => {
|
||||||
api
|
api
|
||||||
.savedTeams({ ...filters, ...{ headers: headers } })
|
.savedTeams({ ...filters, ...{ headers: headers } })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setTotalPages(response.data.total_pages)
|
setTotalPages(response.data.meta.total_pages)
|
||||||
setRecordCount(response.data.count)
|
setRecordCount(response.data.meta.count)
|
||||||
|
|
||||||
if (replace)
|
if (replace)
|
||||||
replaceResults(response.data.count, response.data.results)
|
replaceResults(response.data.meta.count, response.data.results)
|
||||||
else appendResults(response.data.results)
|
else appendResults(response.data.results)
|
||||||
})
|
})
|
||||||
.catch((error) => handleError(error))
|
.catch((error) => handleError(error))
|
||||||
|
|
|
||||||
|
|
@ -130,11 +130,11 @@ 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.total_pages)
|
setTotalPages(response.data.meta.total_pages)
|
||||||
setRecordCount(response.data.count)
|
setRecordCount(response.data.meta.count)
|
||||||
|
|
||||||
if (replace)
|
if (replace)
|
||||||
replaceResults(response.data.count, response.data.results)
|
replaceResults(response.data.meta.count, response.data.results)
|
||||||
else appendResults(response.data.results)
|
else appendResults(response.data.results)
|
||||||
})
|
})
|
||||||
.catch((error) => handleError(error))
|
.catch((error) => handleError(error))
|
||||||
|
|
|
||||||
2
types/User.d.ts
vendored
2
types/User.d.ts
vendored
|
|
@ -2,7 +2,7 @@ interface User {
|
||||||
id: string
|
id: string
|
||||||
username: string
|
username: string
|
||||||
granblueId: number
|
granblueId: number
|
||||||
picture: {
|
avatar: {
|
||||||
picture: string
|
picture: string
|
||||||
element: string
|
element: string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
types/index.d.ts
vendored
6
types/index.d.ts
vendored
|
|
@ -7,3 +7,9 @@ export type JobSkillObject = {
|
||||||
2: JobSkill | undefined
|
2: JobSkill | undefined
|
||||||
3: JobSkill | undefined
|
3: JobSkill | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PaginationObject = {
|
||||||
|
count: number
|
||||||
|
totalPages: number
|
||||||
|
perPage: number
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue