From 021587ffabe42124ce57d636ab86f051fc34507b Mon Sep 17 00:00:00 2001 From: JimmFly Date: Thu, 24 Oct 2024 03:36:10 +0000 Subject: [PATCH] chore: add track event to toggle sidebar switch (#8582) close AF-1530 --- packages/frontend/core/src/commands/affine-layout.tsx | 4 +++- .../app-sidebar/views/sidebar-header/sidebar-switch.tsx | 4 ++++ packages/frontend/track/src/events.ts | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/frontend/core/src/commands/affine-layout.tsx b/packages/frontend/core/src/commands/affine-layout.tsx index 5e3d6beb7c264..97af73ea2f143 100644 --- a/packages/frontend/core/src/commands/affine-layout.tsx +++ b/packages/frontend/core/src/commands/affine-layout.tsx @@ -27,7 +27,9 @@ export function registerAffineLayoutCommands({ binding: '$mod+/', }, run() { - track.$.navigationPanel.$.toggle(); + track.$.navigationPanel.$.toggle({ + type: appSidebarService.sidebar.open$.value ? 'collapse' : 'expand', + }); appSidebarService.sidebar.toggleSidebar(); }, }) diff --git a/packages/frontend/core/src/modules/app-sidebar/views/sidebar-header/sidebar-switch.tsx b/packages/frontend/core/src/modules/app-sidebar/views/sidebar-header/sidebar-switch.tsx index e201884d15b4b..019c345b8880e 100644 --- a/packages/frontend/core/src/modules/app-sidebar/views/sidebar-header/sidebar-switch.tsx +++ b/packages/frontend/core/src/modules/app-sidebar/views/sidebar-header/sidebar-switch.tsx @@ -1,5 +1,6 @@ import { IconButton } from '@affine/component'; import { useI18n } from '@affine/i18n'; +import { track } from '@affine/track'; import { SidebarIcon } from '@blocksuite/icons/rc'; import { useLiveData, useService } from '@toeverything/infra'; import { useCallback, useRef } from 'react'; @@ -27,6 +28,9 @@ export const SidebarSwitch = ({ }, [appSidebarService, open, preventHovering]); const handleClickSwitch = useCallback(() => { + track.$.navigationPanel.$.toggle({ + type: open ? 'collapse' : 'expand', + }); if (timeoutRef.current) { clearTimeout(timeoutRef.current); } diff --git a/packages/frontend/track/src/events.ts b/packages/frontend/track/src/events.ts index e7c73ac2d4403..ecdffc7bd99df 100644 --- a/packages/frontend/track/src/events.ts +++ b/packages/frontend/track/src/events.ts @@ -386,6 +386,7 @@ export type EventArgs = { action: TabActionType; }; toggleFavorite: OrganizeItemArgs & { on: boolean }; + toggle: { type: 'collapse' | 'expand' }; createDoc: { mode?: 'edgeless' | 'page' }; switchPageMode: { mode: 'edgeless' | 'page' }; createShareLink: { mode: 'edgeless' | 'page' };