Skip to content

Commit

Permalink
♻️ refactor: Refactor hook
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Dec 24, 2024
1 parent d1d27d3 commit 85f8fff
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { memo } from 'react';
import urlJoin from 'url-join';

import Menu from '@/components/Menu';
import { useActiveSettingsKey } from '@/hooks/useActiveSettingsKey';
import { useActiveSettingsKey } from '@/hooks/useActiveTabKey';
import { useQuery } from '@/hooks/useQuery';
import { useQueryRoute } from '@/hooks/useQueryRoute';
import { ProfileTabs, SettingsTabs } from '@/store/global/initialState';
Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/profile/_layout/Desktop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Flexbox } from 'react-layout-kit';

import Footer from '@/features/Setting/Footer';
import SettingContainer from '@/features/Setting/SettingContainer';
import { useActiveProfileKey } from '@/hooks/useActiveProfileKey';
import { useActiveProfileKey } from '@/hooks/useActiveTabKey';

import { LayoutProps } from '../type';
import Header from './Header';
Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/profile/_layout/Mobile/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';

import { useActiveProfileKey } from '@/hooks/useActiveProfileKey';
import { useActiveProfileKey } from '@/hooks/useActiveTabKey';
import { mobileHeaderSticky } from '@/styles/mobileHeader';

const Header = memo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { memo } from 'react';
import urlJoin from 'url-join';

import Menu from '@/components/Menu';
import { useActiveSettingsKey } from '@/hooks/useActiveSettingsKey';
import { useActiveSettingsKey } from '@/hooks/useActiveTabKey';
import { useQuery } from '@/hooks/useQuery';
import { useQueryRoute } from '@/hooks/useQueryRoute';
import { SettingsTabs } from '@/store/global/initialState';
Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/settings/_layout/Desktop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Flexbox } from 'react-layout-kit';
import InitClientDB from '@/features/InitClientDB';
import Footer from '@/features/Setting/Footer';
import SettingContainer from '@/features/Setting/SettingContainer';
import { useActiveSettingsKey } from '@/hooks/useActiveSettingsKey';
import { useActiveSettingsKey } from '@/hooks/useActiveTabKey';
import { SettingsTabs } from '@/store/global/initialState';

import { LayoutProps } from '../type';
Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/settings/_layout/Mobile/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';

import { useActiveSettingsKey } from '@/hooks/useActiveSettingsKey';
import { useActiveSettingsKey } from '@/hooks/useActiveTabKey';
import { SettingsTabs } from '@/store/global/initialState';
import { useUserStore } from '@/store/user';
import { authSelectors } from '@/store/user/selectors';
Expand Down
2 changes: 1 addition & 1 deletion src/app/@modal/(.)settings/modal/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import dynamic from 'next/dynamic';
import { PropsWithChildren, memo } from 'react';
import { useTranslation } from 'react-i18next';

import { useActiveSettingsKey } from '@/hooks/useActiveSettingsKey';
import { useActiveSettingsKey } from '@/hooks/useActiveTabKey';
import { SettingsTabs } from '@/store/global/initialState';

import SettingModalLayout from '../../_layout/SettingModalLayout';
Expand Down
17 changes: 0 additions & 17 deletions src/hooks/useActiveProfileKey.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/hooks/useActiveSettingsKey.ts

This file was deleted.

35 changes: 34 additions & 1 deletion src/hooks/useActiveTabKey.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { usePathname } from 'next/navigation';

import { SidebarTabKey } from '@/store/global/initialState';
import { useQuery } from '@/hooks/useQuery';
import { ProfileTabs, SettingsTabs, SidebarTabKey } from '@/store/global/initialState';

/**
* Returns the active tab key (chat/market/settings/...)
Expand All @@ -10,3 +11,35 @@ export const useActiveTabKey = () => {

return pathname.split('/').find(Boolean)! as SidebarTabKey;
};

/**
* Returns the active setting page key (common/sync/agent/...)
*/
export const useActiveSettingsKey = () => {
const pathname = usePathname();
const { tab } = useQuery();

const tabs = pathname.split('/').at(-1);

if (tabs === 'settings') return SettingsTabs.Common;

if (tabs === 'modal') return tab as SettingsTabs;

return tabs as SettingsTabs;
};

/**
* Returns the active profile page key (profile/security/stats/...)
*/
export const useActiveProfileKey = () => {
const pathname = usePathname();
const { tab } = useQuery();

const tabs = pathname.split('/').at(-1);

if (tabs === 'profile') return ProfileTabs.Profile;

if (tabs === 'modal') return tab as ProfileTabs;

return tabs as ProfileTabs;
};

0 comments on commit 85f8fff

Please sign in to comment.