From be90172fada1d09d606d8ce6e4e2fa6dd47f67e8 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 4 Feb 2022 00:55:58 -0800 Subject: [PATCH] We have to pass around the slug as well --- components/CharacterGrid/index.tsx | 9 +++++++-- components/Party/index.tsx | 3 ++- components/SummonGrid/index.tsx | 14 ++++++++------ components/WeaponGrid/index.tsx | 7 +++++-- context/PartyContext.tsx | 2 ++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/components/CharacterGrid/index.tsx b/components/CharacterGrid/index.tsx index 5b4a9bb9..ac5c08ce 100644 --- a/components/CharacterGrid/index.tsx +++ b/components/CharacterGrid/index.tsx @@ -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)) diff --git a/components/Party/index.tsx b/components/Party/index.tsx index 2c4ee3ea..be92ea5f 100644 --- a/components/Party/index.tsx +++ b/components/Party/index.tsx @@ -39,6 +39,7 @@ const Party = (props: Props) => { // Set up states const [currentTab, setCurrentTab] = useState(GridType.Weapon) const [id, setId] = useState('') + const [slug, setSlug] = useState('') const [element, setElement] = useState(TeamElement.Any) const [editable, setEditable] = useState(false) const [hasExtra, setHasExtra] = useState(false) @@ -127,7 +128,7 @@ const Party = (props: Props) => { return (
- + { navigation } { currentGrid() } diff --git a/components/SummonGrid/index.tsx b/components/SummonGrid/index.tsx index 24e0b1f1..3b337fef 100644 --- a/components/SummonGrid/index.tsx +++ b/components/SummonGrid/index.tsx @@ -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)) diff --git a/components/WeaponGrid/index.tsx b/components/WeaponGrid/index.tsx index 96e8a8ca..fed35048 100644 --- a/components/WeaponGrid/index.tsx +++ b/components/WeaponGrid/index.tsx @@ -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) diff --git a/context/PartyContext.tsx b/context/PartyContext.tsx index 31885fcd..87599c19 100644 --- a/context/PartyContext.tsx +++ b/context/PartyContext.tsx @@ -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,