import { useEffect, useMemo, useState } from 'react' import { ModalProps } from '../../types/modal' import Modal from '../shared/Modal' import { useTranslation } from 'next-i18next' import useMangoAccount from 'hooks/useMangoAccount' import useUnownedAccount from 'hooks/useUnownedAccount' import { ArrowLeftIcon, ChevronRightIcon } from '@heroicons/react/20/solid' import RpcSettings from '@components/settings/RpcSettings' import DisplaySettings from '@components/settings/DisplaySettings' import AccountSettings from '@components/settings/AccountSettings' import NotificationSettings from '@components/settings/NotificationSettings' import HotKeysSettings from '@components/settings/HotKeysSettings' import PreferredExplorerSettings from '@components/settings/PreferredExplorerSettings' import { useViewport } from 'hooks/useViewport' import { IconButton } from '@components/shared/Button' import AnimationSettings from '@components/settings/AnimationSettings' import SoundSettings from '@components/settings/SoundSettings' enum SettingsCategories { NETWORK = 'settings:network', DISPLAY = 'settings:display', ACCOUNT = 'account', NOTIFICATIONS = 'settings:notifications', PREFERENCES = 'settings:preferences', HOTKEYS = 'settings:hot-keys', } const DEFAULT_TABS = [ SettingsCategories.NETWORK, SettingsCategories.DISPLAY, SettingsCategories.NOTIFICATIONS, SettingsCategories.PREFERENCES, SettingsCategories.HOTKEYS, ] const SettingsModal = ({ isOpen, onClose }: ModalProps) => { const { t } = useTranslation(['common', 'settings']) const { mangoAccountAddress } = useMangoAccount() const { isUnownedAccount } = useUnownedAccount() const { isDesktop } = useViewport() const [activeTab, setActiveTab] = useState( isDesktop ? DEFAULT_TABS[0] : null, ) const tabsToShow = useMemo(() => { if (!mangoAccountAddress || isUnownedAccount) return DEFAULT_TABS const tabs = [ ...DEFAULT_TABS.slice(0, 2), SettingsCategories.ACCOUNT, ...DEFAULT_TABS.slice(2), ] return isDesktop ? tabs : tabs.slice(0, -1) }, [mangoAccountAddress, isDesktop, isUnownedAccount]) // set an active tab is screen width is desktop and no tab is set useEffect(() => { if (!activeTab && isDesktop) { setActiveTab(DEFAULT_TABS[0]) } }, [activeTab, isDesktop]) return (

{t('settings')}

{isDesktop || !activeTab ? (
{tabsToShow.map((tab) => ( ))}
) : null} {isDesktop || activeTab ? (
) : null}
) } export default SettingsModal const TabContent = ({ activeTab, setActiveTab, }: { activeTab: SettingsCategories | null setActiveTab: (tab: SettingsCategories | null) => void }) => { const { NETWORK, DISPLAY, ACCOUNT, NOTIFICATIONS, HOTKEYS, PREFERENCES } = SettingsCategories switch (activeTab) { case NETWORK: return ( <> ) case DISPLAY: return ( <> ) case ACCOUNT: return ( <> ) case NOTIFICATIONS: return ( <> ) case HOTKEYS: return ( <> ) case PREFERENCES: return ( <> ) default: return null } } const TabButton = ({ activeTab, setActiveTab, title, }: { activeTab: SettingsCategories | null setActiveTab: (tab: SettingsCategories) => void title: SettingsCategories }) => { const { t } = useTranslation(['common', 'settings']) return ( ) } const MobileCategoryHeading = ({ setActiveTab, title, }: { setActiveTab: (tab: null) => void title: SettingsCategories }) => { const { t } = useTranslation(['common', 'settings']) return (
setActiveTab(null)} >

{t(title)}

) }