We have to pass around the slug as well

This commit is contained in:
Justin Edmund 2022-02-04 00:55:58 -08:00
parent 2bf1c75364
commit be90172fad
5 changed files with 24 additions and 11 deletions

View file

@ -38,6 +38,7 @@ const CharacterGrid = (props: Props) => {
const [found, setFound] = useState(false)
const [loading, setLoading] = useState(true)
const { id, setId } = useContext(PartyContext)
const { slug, setSlug } = useContext(PartyContext)
const { editable, setEditable } = useContext(AppContext)
// Set up states for Grid data
@ -55,9 +56,10 @@ const CharacterGrid = (props: Props) => {
// Fetch data from the server
useEffect(() => {
if (props.slug) fetchGrid(props.slug)
const shortcode = (props.slug) ? props.slug : slug
if (shortcode) fetchGrid(shortcode)
else setEditable(true)
}, [])
}, [slug, props.slug])
// Initialize an array of current uncap values for each characters
useEffect(() => {
@ -136,6 +138,9 @@ const CharacterGrid = (props: Props) => {
props.createParty()
.then(response => {
const party = response.data.party
setId(party.id)
setSlug(party.shortcode)
if (props.pushHistory) props.pushHistory(`/p/${party.shortcode}`)
saveCharacter(party.id, character, position)
.then(response => storeGridCharacter(response.data.grid_character))

View file

@ -39,6 +39,7 @@ const Party = (props: Props) => {
// Set up states
const [currentTab, setCurrentTab] = useState<GridType>(GridType.Weapon)
const [id, setId] = useState('')
const [slug, setSlug] = useState('')
const [element, setElement] = useState<TeamElement>(TeamElement.Any)
const [editable, setEditable] = useState(false)
const [hasExtra, setHasExtra] = useState(false)
@ -127,7 +128,7 @@ const Party = (props: Props) => {
return (
<div>
<PartyContext.Provider value={{ id, setId, element, setElement, editable, setEditable, hasExtra, setHasExtra }}>
<PartyContext.Provider value={{ id, setId, slug, setSlug, element, setElement, editable, setEditable, hasExtra, setHasExtra }}>
{ navigation }
{ currentGrid() }
</PartyContext.Provider>

View file

@ -35,13 +35,11 @@ const SummonGrid = (props: Props) => {
}
} : {}
// Set up state for party
const { id, setId } = useContext(PartyContext)
// Set up state for view management
const [found, setFound] = useState(false)
const [loading, setLoading] = useState(true)
const { id, setId } = useContext(PartyContext)
const { slug, setSlug } = useContext(PartyContext)
const { editable, setEditable } = useContext(AppContext)
// Set up states for Grid data
@ -61,9 +59,10 @@ const SummonGrid = (props: Props) => {
// Fetch data from the server
useEffect(() => {
if (props.slug) fetchGrid(props.slug)
const shortcode = (props.slug) ? props.slug : slug
if (shortcode) fetchGrid(shortcode)
else setEditable(true)
}, [])
}, [slug, props.slug])
// Initialize an array of current uncap values for each summon
useEffect(() => {
@ -154,6 +153,9 @@ const SummonGrid = (props: Props) => {
props.createParty()
.then(response => {
const party = response.data.party
setId(party.id)
setSlug(party.shortcode)
if (props.pushHistory) props.pushHistory(`/p/${party.shortcode}`)
saveSummon(party.id, summon, position)
.then(response => storeGridSummon(response.data.grid_summon))

View file

@ -43,6 +43,7 @@ const WeaponGrid = (props: Props) => {
// Set up the party context
const { setEditable: setAppEditable } = useContext(AppContext)
const { id, setId } = useContext(PartyContext)
const { slug, setSlug } = useContext(PartyContext)
const { editable, setEditable } = useContext(PartyContext)
const { hasExtra, setHasExtra } = useContext(PartyContext)
const { setElement } = useContext(PartyContext)
@ -63,12 +64,13 @@ const WeaponGrid = (props: Props) => {
// Fetch data from the server
useEffect(() => {
if (props.slug) fetchGrid(props.slug)
const shortcode = (props.slug) ? props.slug : slug
if (shortcode) fetchGrid(shortcode)
else {
setEditable(true)
setAppEditable(true)
}
}, [props.slug])
}, [slug, props.slug])
// Initialize an array of current uncap values for each weapon
useEffect(() => {
@ -159,6 +161,7 @@ const WeaponGrid = (props: Props) => {
.then(response => {
const party = response.data.party
setId(party.id)
setSlug(party.shortcode)
if (props.pushHistory) props.pushHistory(`/p/${party.shortcode}`)
saveWeapon(party.id, weapon, position)

View file

@ -4,6 +4,8 @@ import { TeamElement } from '~utils/enums'
const PartyContext = createContext({
id: '',
setId: (id: string) => {},
slug: '',
setSlug: (slug: string) => {},
element: TeamElement.Any,
setElement: (element: TeamElement) => {},
editable: false,