Skip to content

Commit

Permalink
Allow search params to open settings
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Jan 27, 2025
1 parent dd1aa7e commit b436350
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions web/components/buttons/user-settings-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number> = {
'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 <div />

Expand Down Expand Up @@ -128,6 +142,7 @@ export function UserSettingButton(props: { user: User }) {
</Row>
<QueryUncontrolledTabs
className={'mb-4'}
defaultIndex={tabIndex}
tabs={buildArray([
isYou
? [
Expand Down

0 comments on commit b436350

Please sign in to comment.