forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (lobehub#2306)
* β»οΈ refactor: Move NavBar to `@nav` slot route * π fix: Fix sub routes layout * π fix: Fix MobileSessionHeader * π§ chore: Merge error page * β test: Update tests * π fix: Fix ServerLayout * π fix: Fix Mobile Header * π style: Rename components * β test: Update test
- Loading branch information
1 parent
7ef77fc
commit aee7231
Showing
35 changed files
with
312 additions
and
207 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,10 @@ | ||
import ServerLayout from '@/components/server/ServerLayout'; | ||
|
||
import Desktop from './_layout/Desktop'; | ||
import Mobile from './_layout/Mobile'; | ||
|
||
const Nav = ServerLayout({ Desktop, Mobile }); | ||
|
||
Nav.displayName = 'Nav'; | ||
|
||
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,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,24 @@ | ||
'use client'; | ||
|
||
import { usePathname } from 'next/navigation'; | ||
import { memo } from 'react'; | ||
|
||
import { LayoutProps } from './type'; | ||
|
||
const MOBILE_IGNORE_NAV_ROUTES = ['/settings/', '/chat/']; | ||
|
||
const Layout = memo(({ children, nav }: LayoutProps) => { | ||
const pathname = usePathname(); | ||
const hideNav = MOBILE_IGNORE_NAV_ROUTES.some((path) => pathname.startsWith(path)); | ||
|
||
return ( | ||
<> | ||
{children} | ||
{!hideNav && nav} | ||
</> | ||
); | ||
}); | ||
|
||
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
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 |
---|---|---|
|
@@ -48,6 +48,7 @@ const MobileHeader = memo(() => { | |
</> | ||
} | ||
showBackButton | ||
style={{ width: '100%' }} | ||
/> | ||
); | ||
}); | ||
|
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 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,5 @@ | ||
'use client'; | ||
|
||
import dynamic from 'next/dynamic'; | ||
|
||
export default dynamic(() => import('@/components/Error')); |
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,11 @@ | ||
import ServerLayout from '@/components/server/ServerLayout'; | ||
|
||
import Desktop from './_layout/Desktop'; | ||
import Mobile from './_layout/Mobile'; | ||
import { LayoutProps } from './_layout/type'; | ||
|
||
const MainLayout = ServerLayout<LayoutProps>({ Desktop, Mobile }); | ||
|
||
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 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,3 @@ | ||
import dynamic from 'next/dynamic'; | ||
|
||
export default dynamic(() => import('@/components/404')); |
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
Oops, something went wrong.