Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

revert: resize in app sidebar (#2193)

Himself6573a7c0158070
diff --git a/apps/web/src/components/root-app-sidebar/index.tsx b/apps/web/src/components/root-app-sidebar/index.tsx
index c8b1975255..32ffa42b0c 100644
--- a/apps/web/src/components/root-app-sidebar/index.tsx
+++ b/apps/web/src/components/root-app-sidebar/index.tsx
@@ -75,7 +75,7 @@ export const RootAppSidebar = ({
}, [createPage, openPage]);
const sidebarOpen = useAtomValue(appSidebarOpenAtom);
useEffect(() => {
- if (environment.isDesktop && typeof sidebarOpen === 'boolean') {
+ if (environment.isDesktop) {
window.apis?.onSidebarVisibilityChange(sidebarOpen);
}
}, [sidebarOpen]);
diff --git a/packages/component/src/components/app-sidebar/index.jotai.ts b/packages/component/src/components/app-sidebar/index.jotai.ts
index 603beaf964..864a3eb668 100644
--- a/packages/component/src/components/app-sidebar/index.jotai.ts
+++ b/packages/component/src/components/app-sidebar/index.jotai.ts
@@ -1,9 +1,6 @@
import { atomWithStorage } from 'jotai/utils';
-export const appSidebarOpenAtom = atomWithStorage(
- 'app-sidebar-open',
- undefined as boolean | undefined
-);
+export const appSidebarOpenAtom = atomWithStorage('app-sidebar-open', true);
export const appSidebarWidthAtom = atomWithStorage(
'app-sidebar-width',
256 /* px */
diff --git a/packages/component/src/components/app-sidebar/index.tsx b/packages/component/src/components/app-sidebar/index.tsx
index ad80a52b48..866d8f0c51 100644
--- a/packages/component/src/components/app-sidebar/index.tsx
+++ b/packages/component/src/components/app-sidebar/index.tsx
@@ -8,13 +8,7 @@ import { assignInlineVars } from '@vanilla-extract/dynamic';
import { useAtom, useAtomValue } from 'jotai';
import type { PropsWithChildren, ReactElement } from 'react';
import type { ReactNode } from 'react';
-import {
- forwardRef,
- useCallback,
- useEffect,
- useImperativeHandle,
- useRef,
-} from 'react';
+import { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
import { IconButton } from '../../ui/button/IconButton';
import {
@@ -40,7 +34,6 @@ export const AppSidebar = forwardRef<HTMLElement, AppSidebarProps>(
const [open, setOpen] = useAtom(appSidebarOpenAtom);
const appSidebarWidth = useAtomValue(appSidebarWidthAtom);
- const initialRender = open === undefined;
const handleSidebarOpen = useCallback(() => {
setOpen(open => !open);
@@ -48,20 +41,8 @@ export const AppSidebar = forwardRef<HTMLElement, AppSidebarProps>(
useImperativeHandle(forwardedRef, () => ref.current as HTMLElement);
- useEffect(() => {
- if (open === undefined && ref.current) {
- const initialOpen =
- window.getComputedStyle(ref.current).position === 'relative';
-
- setOpen(initialOpen);
- }
- }, [open, setOpen]);
-
const environment = getEnvironment();
const isMacosDesktop = environment.isDesktop && environment.isMacOs;
- if (initialRender) {
- return <div />;
- }
return (
<>
<nav
@@ -115,7 +96,9 @@ export const AppSidebar = forwardRef<HTMLElement, AppSidebarProps>(
data-testid="app-sidebar-float-mask"
data-open={open}
className={sidebarFloatMaskStyle}
- onClick={() => setOpen(false)}
+ onClick={useCallback(() => {
+ setOpen(false);
+ }, [setOpen])}
/>
</>
);