Add api call for raidGroups and update pages
Pages fetch raids and store them in the app state. We needed to update this to pull raid groups instead
This commit is contained in:
parent
2eea7a84e7
commit
c9014913db
8 changed files with 36 additions and 64 deletions
|
|
@ -9,7 +9,6 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
|||
import api from '~utils/api'
|
||||
import extractFilters from '~utils/extractFilters'
|
||||
import fetchLatestVersion from '~utils/fetchLatestVersion'
|
||||
import organizeRaids from '~utils/organizeRaids'
|
||||
import { setHeaders } from '~utils/userToken'
|
||||
import useDidMountEffect from '~utils/useDidMountEffect'
|
||||
import { appState } from '~utils/appState'
|
||||
|
|
@ -356,12 +355,12 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
|
||||
try {
|
||||
// Fetch and organize raids
|
||||
let { raids, sortedRaids } = await api.endpoints.raids
|
||||
.getAll()
|
||||
.then((response) => organizeRaids(response.data))
|
||||
let raidGroups: RaidGroup[] = await api
|
||||
.raidGroups()
|
||||
.then((response) => response.data)
|
||||
|
||||
// Create filter object
|
||||
const filters: FilterObject = extractFilters(query, raids)
|
||||
const filters: FilterObject = extractFilters(query, raidGroups)
|
||||
const params = {
|
||||
params: { ...filters, ...advancedFilters },
|
||||
}
|
||||
|
|
@ -393,8 +392,7 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
const context: PageContextObj = {
|
||||
user: user,
|
||||
teams: teams,
|
||||
raids: raids,
|
||||
sortedRaids: sortedRaids,
|
||||
raidGroups: raidGroups,
|
||||
pagination: pagination,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import NewHead from '~components/head/NewHead'
|
|||
|
||||
import api from '~utils/api'
|
||||
import fetchLatestVersion from '~utils/fetchLatestVersion'
|
||||
import organizeRaids from '~utils/organizeRaids'
|
||||
import { accountCookie, setHeaders } from '~utils/userToken'
|
||||
import { appState, initialAppState } from '~utils/appState'
|
||||
import { groupWeaponKeys } from '~utils/groupWeaponKeys'
|
||||
|
|
@ -69,7 +68,7 @@ const NewRoute: React.FC<Props> = ({
|
|||
|
||||
useEffect(() => {
|
||||
if (context && context.jobs && context.jobSkills) {
|
||||
appState.raids = context.raids
|
||||
appState.raids = context.raidGroups
|
||||
appState.jobs = context.jobs
|
||||
appState.jobSkills = context.jobSkills
|
||||
appState.weaponKeys = context.weaponKeys
|
||||
|
|
@ -106,12 +105,7 @@ const NewRoute: React.FC<Props> = ({
|
|||
return (
|
||||
<React.Fragment key={router.asPath}>
|
||||
{pageHead()}
|
||||
<Party
|
||||
new={true}
|
||||
raids={context.sortedRaids}
|
||||
pushHistory={callback}
|
||||
selectedTab={selectedTab}
|
||||
/>
|
||||
<Party new={true} pushHistory={callback} selectedTab={selectedTab} />
|
||||
</React.Fragment>
|
||||
)
|
||||
} else return pageError()
|
||||
|
|
@ -153,9 +147,7 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
|
||||
try {
|
||||
// Fetch and organize raids
|
||||
let { raids, sortedRaids } = await api.endpoints.raids
|
||||
.getAll()
|
||||
.then((response) => organizeRaids(response.data))
|
||||
let raidGroups: RaidGroup[] = await api.raidGroups().then((response) => response.data)
|
||||
|
||||
// Fetch jobs and job skills
|
||||
let jobs = await api.endpoints.jobs
|
||||
|
|
@ -174,8 +166,7 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
const context: PageContextObj = {
|
||||
jobs: jobs,
|
||||
jobSkills: jobSkills,
|
||||
raids: raids,
|
||||
sortedRaids: sortedRaids,
|
||||
raidGroups: raidGroups,
|
||||
weaponKeys: weaponKeys,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import PartyHead from '~components/party/PartyHead'
|
|||
import api from '~utils/api'
|
||||
import elementEmoji from '~utils/elementEmoji'
|
||||
import fetchLatestVersion from '~utils/fetchLatestVersion'
|
||||
import organizeRaids from '~utils/organizeRaids'
|
||||
import { setHeaders } from '~utils/userToken'
|
||||
import { appState } from '~utils/appState'
|
||||
import { groupWeaponKeys } from '~utils/groupWeaponKeys'
|
||||
|
|
@ -57,7 +56,7 @@ const PartyRoute: React.FC<Props> = ({
|
|||
// Set the initial data from props
|
||||
useEffect(() => {
|
||||
if (context && !error) {
|
||||
appState.raids = context.raids
|
||||
appState.raidGroups = context.raidGroups
|
||||
appState.jobs = context.jobs ? context.jobs : []
|
||||
appState.jobSkills = context.jobSkills ? context.jobSkills : []
|
||||
appState.weaponKeys = context.weaponKeys
|
||||
|
|
@ -85,11 +84,7 @@ const PartyRoute: React.FC<Props> = ({
|
|||
return (
|
||||
<React.Fragment key={router.asPath}>
|
||||
{pageHead()}
|
||||
<Party
|
||||
team={context.party}
|
||||
raids={context.sortedRaids}
|
||||
selectedTab={selectedTab}
|
||||
/>
|
||||
<Party team={context.party} selectedTab={selectedTab} />
|
||||
</React.Fragment>
|
||||
)
|
||||
} else return pageError()
|
||||
|
|
@ -115,9 +110,9 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
|
||||
try {
|
||||
// Fetch and organize raids
|
||||
let { raids, sortedRaids } = await api.endpoints.raids
|
||||
.getAll()
|
||||
.then((response) => organizeRaids(response.data))
|
||||
let raidGroups: RaidGroup[] = await api
|
||||
.raidGroups()
|
||||
.then((response) => response.data)
|
||||
|
||||
// Fetch jobs and job skills
|
||||
let jobs = await api.endpoints.jobs
|
||||
|
|
@ -148,8 +143,7 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
party: party,
|
||||
jobs: jobs,
|
||||
jobSkills: jobSkills,
|
||||
raids: raids,
|
||||
sortedRaids: sortedRaids,
|
||||
raidGroups: raidGroups,
|
||||
weaponKeys: weaponKeys,
|
||||
meta: {
|
||||
element: elementEmoji(party),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import api from '~utils/api'
|
|||
import { setHeaders } from '~utils/userToken'
|
||||
import extractFilters from '~utils/extractFilters'
|
||||
import fetchLatestVersion from '~utils/fetchLatestVersion'
|
||||
import organizeRaids from '~utils/organizeRaids'
|
||||
import useDidMountEffect from '~utils/useDidMountEffect'
|
||||
import { appState } from '~utils/appState'
|
||||
import { defaultFilterset } from '~utils/defaultFilters'
|
||||
|
|
@ -390,12 +389,12 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
|
||||
try {
|
||||
// Fetch and organize raids
|
||||
let { raids, sortedRaids } = await api.endpoints.raids
|
||||
.getAll()
|
||||
.then((response) => organizeRaids(response.data))
|
||||
let raidGroups: RaidGroup[] = await api
|
||||
.raidGroups()
|
||||
.then((response) => response.data)
|
||||
|
||||
// Create filter object
|
||||
const filters: FilterObject = extractFilters(query, raids)
|
||||
const filters: FilterObject = extractFilters(query, raidGroups)
|
||||
const params = {
|
||||
params: { ...filters, ...advancedFilters },
|
||||
}
|
||||
|
|
@ -416,8 +415,7 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
// Consolidate data into context object
|
||||
const context: PageContextObj = {
|
||||
teams: teams,
|
||||
raids: raids,
|
||||
sortedRaids: sortedRaids,
|
||||
raidGroups: raidGroups,
|
||||
pagination: pagination,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import api from '~utils/api'
|
|||
import { setHeaders } from '~utils/userToken'
|
||||
import extractFilters from '~utils/extractFilters'
|
||||
import fetchLatestVersion from '~utils/fetchLatestVersion'
|
||||
import organizeRaids from '~utils/organizeRaids'
|
||||
import useDidMountEffect from '~utils/useDidMountEffect'
|
||||
import { appState } from '~utils/appState'
|
||||
import { defaultFilterset } from '~utils/defaultFilters'
|
||||
|
|
@ -388,12 +387,12 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
|
||||
try {
|
||||
// Fetch and organize raids
|
||||
let { raids, sortedRaids } = await api.endpoints.raids
|
||||
.getAll()
|
||||
.then((response) => organizeRaids(response.data))
|
||||
let raidGroups: RaidGroup[] = await api
|
||||
.raidGroups()
|
||||
.then((response) => response.data)
|
||||
|
||||
// Create filter object
|
||||
const filters: FilterObject = extractFilters(query, raids)
|
||||
const filters: FilterObject = extractFilters(query, raidGroups)
|
||||
const params = {
|
||||
params: { ...filters, ...advancedFilters },
|
||||
}
|
||||
|
|
@ -414,8 +413,7 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex
|
|||
// Consolidate data into context object
|
||||
const context: PageContextObj = {
|
||||
teams: teams,
|
||||
raids: raids,
|
||||
sortedRaids: sortedRaids,
|
||||
raidGroups: raidGroups,
|
||||
pagination: pagination,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -120,6 +120,11 @@ class Api {
|
|||
return axios.get(resourceUrl, params)
|
||||
}
|
||||
|
||||
raidGroups(params?: {}) {
|
||||
const resourceUrl = `${this.url}/raids/groups`
|
||||
return axios.get(resourceUrl, params)
|
||||
}
|
||||
|
||||
remix({ shortcode, body, params}: { shortcode: string, body?: {}, params?: {} }) {
|
||||
const resourceUrl = `${this.url}/parties/${shortcode}/remix`
|
||||
return axios.post(resourceUrl, body, params)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import { elements, allElement } from '~data/elements'
|
||||
|
||||
export default (query: { [index: string]: string }, raids: Raid[]) => {
|
||||
export default (
|
||||
query: { [index: string]: string },
|
||||
raidGroups: RaidGroup[]
|
||||
) => {
|
||||
// Extract recency filter
|
||||
const recencyParam: number = parseInt(query.recency)
|
||||
|
||||
|
|
@ -14,8 +17,9 @@ export default (query: { [index: string]: string }, raids: Raid[]) => {
|
|||
)
|
||||
|
||||
// Extract raid filter
|
||||
const allRaids = raidGroups.flatMap((group) => group.raids)
|
||||
const raidParam: string = query.raid
|
||||
const raid: Raid | undefined = raids.find((r) => r.slug === raidParam)
|
||||
const raid: Raid | undefined = allRaids.find((r) => r.slug === raidParam)
|
||||
|
||||
// Return filter object
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
export default (raids: Raid[]) => {
|
||||
const numGroups = Math.max.apply(
|
||||
Math,
|
||||
raids.map((raid) => raid.group)
|
||||
)
|
||||
let groupedRaids = []
|
||||
|
||||
for (let i = 0; i <= numGroups; i++) {
|
||||
groupedRaids[i] = raids.filter((raid) => raid.group == i)
|
||||
}
|
||||
|
||||
return {
|
||||
raids: raids,
|
||||
sortedRaids: groupedRaids,
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue