mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-19 02:51:47 +08:00
fix: hide the mode switcher in small screen
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
|||||||
useLocalTrigger,
|
useLocalTrigger,
|
||||||
useShowSettingsSidebar,
|
useShowSettingsSidebar,
|
||||||
} from '@toeverything/datasource/state';
|
} from '@toeverything/datasource/state';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { EditorBoardSwitcher } from './EditorBoardSwitcher';
|
import { EditorBoardSwitcher } from './EditorBoardSwitcher';
|
||||||
import { fsApiSupported } from './FileSystem';
|
import { fsApiSupported } from './FileSystem';
|
||||||
import { Logo } from './Logo';
|
import { Logo } from './Logo';
|
||||||
@@ -23,6 +23,22 @@ export const LayoutHeader = () => {
|
|||||||
useShowSettingsSidebar();
|
useShowSettingsSidebar();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
// because of header not compatible with small screen, hide the mode switcher in that case, this will be optimize in future.
|
||||||
|
const [hideSwitcher, setHideSwither] = useState(false);
|
||||||
|
const [rootEle, setRootEle] = useState<HTMLDivElement>();
|
||||||
|
useEffect(() => {
|
||||||
|
if (rootEle) {
|
||||||
|
const observer = new ResizeObserver(entries => {
|
||||||
|
setHideSwither(entries[0].contentRect.width < 970);
|
||||||
|
});
|
||||||
|
observer.observe(rootEle);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
observer.disconnect();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [rootEle]);
|
||||||
|
|
||||||
const warningTips = useMemo(() => {
|
const warningTips = useMemo(() => {
|
||||||
if (!fsApiSupported()) {
|
if (!fsApiSupported()) {
|
||||||
return t('WarningTips.IsNotfsApiSupported');
|
return t('WarningTips.IsNotfsApiSupported');
|
||||||
@@ -42,7 +58,7 @@ export const LayoutHeader = () => {
|
|||||||
}, [currentEditors]);
|
}, [currentEditors]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledContainerForHeaderRoot>
|
<StyledContainerForHeaderRoot ref={setRootEle}>
|
||||||
<StyledHeaderRoot>
|
<StyledHeaderRoot>
|
||||||
<FlexContainer>
|
<FlexContainer>
|
||||||
<Logo />
|
<Logo />
|
||||||
@@ -85,9 +101,11 @@ export const LayoutHeader = () => {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
</StyledHelper>
|
</StyledHelper>
|
||||||
</FlexContainer>
|
</FlexContainer>
|
||||||
<StyledContainerForEditorBoardSwitcher>
|
{hideSwitcher ? null : (
|
||||||
<EditorBoardSwitcher />
|
<StyledContainerForEditorBoardSwitcher>
|
||||||
</StyledContainerForEditorBoardSwitcher>
|
<EditorBoardSwitcher />
|
||||||
|
</StyledContainerForEditorBoardSwitcher>
|
||||||
|
)}
|
||||||
</StyledHeaderRoot>
|
</StyledHeaderRoot>
|
||||||
</StyledContainerForHeaderRoot>
|
</StyledContainerForHeaderRoot>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user