From b4363509d4b7ff8d5d03caae909c88d2e15a3267 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Mon, 27 Jan 2025 10:35:52 -0800 Subject: [PATCH] Allow search params to open settings --- .../buttons/user-settings-button.tsx | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/web/components/buttons/user-settings-button.tsx b/web/components/buttons/user-settings-button.tsx index d667f29e9d..793e311a90 100644 --- a/web/components/buttons/user-settings-button.tsx +++ b/web/components/buttons/user-settings-button.tsx @@ -34,17 +34,31 @@ export function UserSettingButton(props: { user: User }) { const { id: userId, name } = user const currentPrivateUser = usePrivateUser() const [isModalOpen, setIsModalOpen] = useState(false) + const [tabIndex, setTabIndex] = useState(0) const isAdmin = useAdmin() const isTrusted = useTrusted() const numReferrals = useReferralCount(user) const router = useRouter() useEffect(() => { - const tab = router.query.tab - if (tab && tab.toString().toLowerCase() === 'edit+profile') { + const tab = router.query.tab?.toString().toLowerCase() + console.log('tab', tab) + if (!tab) return + + const isYou = currentPrivateUser?.id === userId + const tabMapping: Record = { + 'edit profile': 0, + 'account settings': isYou ? 1 : 0, + block: !isYou ? 0 : 0, + report: !isYou ? 1 : 0, + } + + const index = tabMapping[tab] + if (index !== undefined) { setIsModalOpen(true) + setTabIndex(index) } - }, [router.query]) + }, [router.query, currentPrivateUser, userId]) if (!currentPrivateUser) return
@@ -128,6 +142,7 @@ export function UserSettingButton(props: { user: User }) {