From bf85f9d99c6ade54aa505389b40051016c24cccb Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 27 Feb 2022 00:39:04 -0800 Subject: [PATCH] Reset the state when a new party is loaded --- components/Party/index.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/Party/index.tsx b/components/Party/index.tsx index eb3bfb73..d4b547c1 100644 --- a/components/Party/index.tsx +++ b/components/Party/index.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState } from 'react' import { useSnapshot } from 'valtio' import { useCookies } from 'react-cookie' +import clonedeep from 'lodash.clonedeep' import PartySegmentedControl from '~components/PartySegmentedControl' import PartyDetails from '~components/PartyDetails' @@ -9,7 +10,7 @@ import SummonGrid from '~components/SummonGrid' import CharacterGrid from '~components/CharacterGrid' import api from '~utils/api' -import { appState } from '~utils/appState' +import { appState, initialAppState } from '~utils/appState' import { GridType, TeamElement } from '~utils/enums' import './index.scss' @@ -34,6 +35,12 @@ const Party = (props: Props) => { const { party } = useSnapshot(appState) const [currentTab, setCurrentTab] = useState(GridType.Weapon) + // Reset state on first load + useEffect(() => { + const resetState = clonedeep(initialAppState) + appState.grid = resetState.grid + }, []) + // Fetch data from the server useEffect(() => { const shortcode = (props.slug) ? props.slug : undefined @@ -193,4 +200,4 @@ const Party = (props: Props) => { ) } -export default Party \ No newline at end of file +export default Party