mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
feat: implement useFullscreen hook and integrate with NavbarRight for dynamic padding (#6000)
* feat: implement useFullscreen hook and integrate with NavbarRight for dynamic padding * feat: integrate useFullscreen hook to adjust sidebar layout based on fullscreen state * fix: adjust sidebar height based on fullscreen state for better layout --------- Co-authored-by: George Zhao <georgezhao@SKJLAB>
This commit is contained in:
parent
365eb9bab5
commit
0f97d0302e
@ -1,5 +1,6 @@
|
||||
import { isLinux, isMac, isWindows } from '@renderer/config/constant'
|
||||
import useNavBackgroundColor from '@renderer/hooks/useNavBackgroundColor'
|
||||
import { useFullscreen } from '@renderer/hooks/useFullscreen'
|
||||
import type { FC, PropsWithChildren } from 'react'
|
||||
import type { HTMLAttributes } from 'react'
|
||||
import styled from 'styled-components'
|
||||
@ -25,7 +26,12 @@ export const NavbarCenter: FC<Props> = ({ children, ...props }) => {
|
||||
}
|
||||
|
||||
export const NavbarRight: FC<Props> = ({ children, ...props }) => {
|
||||
return <NavbarRightContainer {...props}>{children}</NavbarRightContainer>
|
||||
const isFullscreen = useFullscreen()
|
||||
return (
|
||||
<NavbarRightContainer {...props} $isFullscreen={isFullscreen}>
|
||||
{children}
|
||||
</NavbarRightContainer>
|
||||
)
|
||||
}
|
||||
|
||||
const NavbarContainer = styled.div`
|
||||
@ -58,11 +64,11 @@ const NavbarCenterContainer = styled.div`
|
||||
color: var(--color-text-1);
|
||||
`
|
||||
|
||||
const NavbarRightContainer = styled.div`
|
||||
const NavbarRightContainer = styled.div<{ $isFullscreen: boolean }>`
|
||||
min-width: var(--topic-list-width);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 12px;
|
||||
padding-right: ${isWindows ? '140px' : isLinux ? '120px' : '12px'};
|
||||
padding-right: ${({ $isFullscreen }) => ($isFullscreen ? '12px' : isWindows ? '140px' : isLinux ? '120px' : '12px')};
|
||||
justify-content: flex-end;
|
||||
`
|
||||
|
||||
@ -3,6 +3,7 @@ import { isMac } from '@renderer/config/constant'
|
||||
import { AppLogo, UserAvatar } from '@renderer/config/env'
|
||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||
import useAvatar from '@renderer/hooks/useAvatar'
|
||||
import { useFullscreen } from '@renderer/hooks/useFullscreen'
|
||||
import { useMinappPopup } from '@renderer/hooks/useMinappPopup'
|
||||
import { useMinapps } from '@renderer/hooks/useMinapps'
|
||||
import useNavBackgroundColor from '@renderer/hooks/useNavBackgroundColor'
|
||||
@ -68,8 +69,13 @@ const Sidebar: FC = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const isFullscreen = useFullscreen()
|
||||
|
||||
return (
|
||||
<Container id="app-sidebar" style={{ backgroundColor, zIndex: minappShow ? 10000 : 'initial' }}>
|
||||
<Container
|
||||
$isFullscreen={isFullscreen}
|
||||
id="app-sidebar"
|
||||
style={{ backgroundColor, zIndex: minappShow ? 10000 : 'initial' }}>
|
||||
{isEmoji(avatar) ? (
|
||||
<EmojiAvatar onClick={onEditUser} className="sidebar-avatar" size={31} fontSize={18}>
|
||||
{avatar}
|
||||
@ -311,7 +317,7 @@ const PinnedApps: FC = () => {
|
||||
)
|
||||
}
|
||||
|
||||
const Container = styled.div`
|
||||
const Container = styled.div<{ $isFullscreen: boolean }>`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
@ -319,9 +325,9 @@ const Container = styled.div`
|
||||
padding-bottom: 12px;
|
||||
width: var(--sidebar-width);
|
||||
min-width: var(--sidebar-width);
|
||||
height: ${isMac ? 'calc(100vh - var(--navbar-height))' : '100vh'};
|
||||
height: ${({ $isFullscreen }) => (isMac && !$isFullscreen ? 'calc(100vh - var(--navbar-height))' : '100vh')};
|
||||
-webkit-app-region: drag !important;
|
||||
margin-top: ${isMac ? 'var(--navbar-height)' : 0};
|
||||
margin-top: ${({ $isFullscreen }) => (isMac && !$isFullscreen ? 'var(--navbar-height)' : 0)};
|
||||
|
||||
.sidebar-avatar {
|
||||
margin-bottom: ${isMac ? '12px' : '12px'};
|
||||
|
||||
18
src/renderer/src/hooks/useFullscreen.ts
Normal file
18
src/renderer/src/hooks/useFullscreen.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { IpcChannel } from '@shared/IpcChannel'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
export function useFullscreen() {
|
||||
const [isFullscreen, setIsFullscreen] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const cleanup = window.electron.ipcRenderer.on(IpcChannel.FullscreenStatusChanged, (_, fullscreen) => {
|
||||
setIsFullscreen(fullscreen)
|
||||
})
|
||||
|
||||
return () => {
|
||||
cleanup()
|
||||
}
|
||||
}, [])
|
||||
|
||||
return isFullscreen
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
import { NavbarRight } from '@renderer/components/app/Navbar'
|
||||
import { HStack } from '@renderer/components/Layout'
|
||||
import { isLinux, isWindows } from '@renderer/config/constant'
|
||||
import { useFullscreen } from '@renderer/hooks/useFullscreen'
|
||||
import { Button, Dropdown, Menu, type MenuProps } from 'antd'
|
||||
import { ChevronDown, Search } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@ -73,7 +74,7 @@ export const McpSettingsNavbar = () => {
|
||||
}))
|
||||
|
||||
return (
|
||||
<NavbarRight style={{ paddingRight: isWindows ? 150 : isLinux ? 120 : 12 }}>
|
||||
<NavbarRight style={{ paddingRight: useFullscreen() ? '12px' : isWindows ? 150 : isLinux ? 120 : 12 }}>
|
||||
<HStack alignItems="center" gap={5}>
|
||||
<Button
|
||||
size="small"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user