From e356c3605349816f55efada7abc635138268ed63 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 29 Jan 2023 00:23:51 -0800 Subject: [PATCH] Fix tabs not sticking on new route This was occurring because the new path wasn't sending the Party component the current tab from the URL like the party path was. --- pages/new/index.tsx | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/pages/new/index.tsx b/pages/new/index.tsx index dc4fe4c9..a25d3f8f 100644 --- a/pages/new/index.tsx +++ b/pages/new/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react' +import React, { useEffect, useState } from 'react' import { useRouter } from 'next/router' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import clonedeep from 'lodash.clonedeep' @@ -17,6 +17,7 @@ import { groupWeaponKeys } from '~utils/groupWeaponKeys' import type { AxiosError } from 'axios' import type { NextApiRequest, NextApiResponse } from 'next' import type { PageContextObj, ResponseStatus } from '~types' +import { GridType } from '~utils/enums' interface Props { context?: PageContextObj @@ -33,11 +34,29 @@ const NewRoute: React.FC = ({ }: Props) => { // Set up router const router = useRouter() + const [selectedTab, setSelectedTab] = useState(GridType.Weapon) function callback(path: string) { router.push(path, undefined, { shallow: true }) } + useEffect(() => { + const parts = router.asPath.split('/') + const tab = parts[parts.length - 1] + + switch (tab) { + case 'characters': + setSelectedTab(GridType.Character) + break + case 'weapons': + setSelectedTab(GridType.Weapon) + break + case 'summons': + setSelectedTab(GridType.Summon) + break + } + }, [router.asPath]) + useEffect(() => { if (context && context.jobs && context.jobSkills) { appState.raids = context.raids @@ -72,7 +91,12 @@ const NewRoute: React.FC = ({ return ( {pageHead()} - + ) } else return pageError()