-
-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: Move NavBar to
@nav
slot route
- Loading branch information
1 parent
7817e67
commit 0444569
Showing
18 changed files
with
188 additions
and
153 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use client'; | ||
|
||
import { Icon, MobileTabBar, type MobileTabBarProps } from '@lobehub/ui'; | ||
import { createStyles } from 'antd-style'; | ||
import { Bot, MessageSquare, User } from 'lucide-react'; | ||
import { useRouter } from 'next/navigation'; | ||
import { rgba } from 'polished'; | ||
import { memo, useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { useActiveTabKey } from '@/hooks/useActiveTabKey'; | ||
import { SidebarTabKey } from '@/store/global/initialState'; | ||
|
||
const useStyles = createStyles(({ css, token }) => ({ | ||
active: css` | ||
svg { | ||
fill: ${rgba(token.colorPrimary, 0.33)}; | ||
} | ||
`, | ||
container: css` | ||
position: fixed; | ||
z-index: 100; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
`, | ||
})); | ||
|
||
const Nav = memo(() => { | ||
const { t } = useTranslation('common'); | ||
const { styles } = useStyles(); | ||
const activeKey = useActiveTabKey(); | ||
const router = useRouter(); | ||
const items: MobileTabBarProps['items'] = useMemo( | ||
() => [ | ||
{ | ||
icon: (active) => ( | ||
<Icon className={active ? styles.active : undefined} icon={MessageSquare} /> | ||
), | ||
key: SidebarTabKey.Chat, | ||
onClick: () => { | ||
router.push('/chat'); | ||
}, | ||
title: t('tab.chat'), | ||
}, | ||
{ | ||
icon: (active) => <Icon className={active ? styles.active : undefined} icon={Bot} />, | ||
key: SidebarTabKey.Market, | ||
onClick: () => { | ||
router.push('/market'); | ||
}, | ||
title: t('tab.market'), | ||
}, | ||
{ | ||
icon: (active) => <Icon className={active ? styles.active : undefined} icon={User} />, | ||
key: SidebarTabKey.Setting, | ||
onClick: () => { | ||
router.push('/settings'); | ||
}, | ||
title: t('tab.setting'), | ||
}, | ||
], | ||
[t], | ||
); | ||
|
||
return <MobileTabBar activeKey={activeKey} className={styles.container} items={items} safeArea />; | ||
}); | ||
|
||
Nav.displayName = 'MobileNav'; | ||
|
||
export default Nav; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { isMobileDevice } from '@/utils/responsive'; | ||
|
||
import Desktop from './_layout/Desktop'; | ||
import Mobile from './_layout/Mobile'; | ||
|
||
const Default = () => { | ||
const mobile = isMobileDevice(); | ||
|
||
const Nav = mobile ? Mobile : Desktop; | ||
|
||
return <Nav />; | ||
}; | ||
|
||
Default.displayName = 'Nav'; | ||
|
||
export default Default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use client'; | ||
|
||
import { useTheme } from 'antd-style'; | ||
import { memo } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import { useIsPWA } from '@/hooks/useIsPWA'; | ||
|
||
import { LayoutProps } from './type'; | ||
|
||
const Layout = memo<LayoutProps>(({ children, nav }) => { | ||
const isPWA = useIsPWA(); | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Flexbox | ||
height={'100%'} | ||
horizontal | ||
style={{ | ||
borderTop: isPWA ? `1px solid ${theme.colorBorder}` : undefined, | ||
position: 'relative', | ||
}} | ||
width={'100%'} | ||
> | ||
{nav} | ||
{children} | ||
</Flexbox> | ||
); | ||
}); | ||
|
||
Layout.displayName = 'DesktopMainLayout'; | ||
|
||
export default Layout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use client'; | ||
|
||
import { usePathname } from 'next/navigation'; | ||
import { memo } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import { LayoutProps } from './type'; | ||
|
||
const MOBILE_IGNORE_NAV_ROUTES = ['/settings', '/me/', '/profile', '/chat/']; | ||
|
||
const Layout = memo(({ children, nav }: LayoutProps) => { | ||
const pathname = usePathname(); | ||
const hideNav = MOBILE_IGNORE_NAV_ROUTES.some((path) => pathname.startsWith(path)); | ||
|
||
return ( | ||
<Flexbox | ||
style={{ | ||
height: '100%', | ||
overflowX: 'hidden', | ||
overflowY: 'auto', | ||
position: 'relative', | ||
width: '100vw', | ||
}} | ||
> | ||
{children} | ||
{!hideNav && nav} | ||
</Flexbox> | ||
); | ||
}); | ||
|
||
Layout.displayName = 'MobileMainLayout'; | ||
|
||
export default Layout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
export interface LayoutProps { | ||
children: ReactNode; | ||
nav: ReactNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { isMobileDevice } from '@/utils/responsive'; | ||
|
||
import Desktop from './_layout/Desktop'; | ||
import Mobile from './_layout/Mobile'; | ||
import { LayoutProps } from './_layout/type'; | ||
|
||
const MainLayout = ({ children, nav }: LayoutProps) => { | ||
const mobile = isMobileDevice(); | ||
|
||
const Layout = mobile ? Mobile : Desktop; | ||
|
||
return <Layout nav={nav}>{children}</Layout>; | ||
}; | ||
|
||
MainLayout.displayName = 'MainLayout'; | ||
|
||
export default MainLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.