Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add track events for cmdk #7668

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/frontend/core/src/commands/affine-creation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { createStore } from 'jotai';

import { openCreateWorkspaceModalAtom } from '../atoms';
import type { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
import { track } from '../mixpanel';
import { registerAffineCommand } from './registry';

export function registerAffineCreationCommands({
Expand All @@ -29,6 +30,8 @@ export function registerAffineCreationCommands({
}
: undefined,
run() {
track.$.cmdk.creation.createDoc({ mode: 'page' });

pageHelper.createPage();
},
})
Expand All @@ -41,6 +44,10 @@ export function registerAffineCreationCommands({
icon: <PlusIcon />,
label: t['com.affine.cmdk.affine.new-edgeless-page'](),
run() {
track.$.cmdk.creation.createDoc({
mode: 'edgeless',
});

pageHelper.createEdgeless();
},
})
Expand All @@ -53,6 +60,8 @@ export function registerAffineCreationCommands({
icon: <PlusIcon />,
label: t['com.affine.cmdk.affine.new-workspace'](),
run() {
track.$.cmdk.workspace.createWorkspace();

store.set(openCreateWorkspaceModalAtom, 'new');
},
})
Expand All @@ -67,6 +76,10 @@ export function registerAffineCreationCommands({
return environment.isDesktop;
},
run() {
track.$.cmdk.workspace.createWorkspace({
control: 'import',
});

store.set(openCreateWorkspaceModalAtom, 'add');
},
})
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/core/src/commands/affine-help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ContactWithUsIcon, NewIcon } from '@blocksuite/icons/rc';
import type { createStore } from 'jotai';

import { openSettingModalAtom } from '../atoms';
import { track } from '../mixpanel';
import { popupWindow } from '../utils';
import { registerAffineCommand } from './registry';

Expand All @@ -21,6 +22,7 @@ export function registerAffineHelpCommands({
icon: <NewIcon />,
label: t['com.affine.cmdk.affine.whats-new'](),
run() {
track.$.cmdk.help.openChangelog();
popupWindow(runtimeConfig.changelogUrl);
},
})
Expand All @@ -32,6 +34,7 @@ export function registerAffineHelpCommands({
icon: <ContactWithUsIcon />,
label: t['com.affine.cmdk.affine.contact-us'](),
run() {
track.$.cmdk.help.contactUs();
store.set(openSettingModalAtom, {
open: true,
activeTab: 'about',
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/core/src/commands/affine-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SidebarIcon } from '@blocksuite/icons/rc';
import type { createStore } from 'jotai';

import { appSidebarOpenAtom } from '../components/app-sidebar';
import { track } from '../mixpanel';
import { registerAffineCommand } from './registry';

export function registerAffineLayoutCommands({
Expand All @@ -27,6 +28,8 @@ export function registerAffineLayoutCommands({
binding: '$mod+/',
},
run() {
track.$.navigationPanel.$.toggle();

store.set(appSidebarOpenAtom, v => !v);
},
})
Expand Down
20 changes: 20 additions & 0 deletions packages/frontend/core/src/commands/affine-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: t['com.affine.cmdk.affine.navigation.goto-all-pages'](),
run() {
track.$.cmdk.navigation.navigate({
to: 'allDocs',
});

navigationHelper.jumpToSubPath(docCollection.id, WorkspaceSubPath.ALL);
},
})
Expand All @@ -40,6 +44,10 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: 'Go to Collection List',
run() {
track.$.cmdk.navigation.navigate({
to: 'collectionList',
});

navigationHelper.jumpToCollections(docCollection.id);
},
})
Expand All @@ -52,6 +60,10 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: 'Go to Tag List',
run() {
track.$.cmdk.navigation.navigate({
to: 'tagList',
});

navigationHelper.jumpToTags(docCollection.id);
},
})
Expand All @@ -64,6 +76,10 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: t['com.affine.cmdk.affine.navigation.goto-workspace'](),
run() {
track.$.cmdk.navigation.navigate({
to: 'workspace',
});

store.set(openWorkspaceListModalAtom, true);
},
})
Expand Down Expand Up @@ -109,6 +125,10 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: t['com.affine.cmdk.affine.navigation.goto-trash'](),
run() {
track.$.cmdk.navigation.navigate({
to: 'trash',
});

navigationHelper.jumpToSubPath(
docCollection.id,
WorkspaceSubPath.TRASH
Expand Down
52 changes: 52 additions & 0 deletions packages/frontend/core/src/commands/affine-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { createStore } from 'jotai';
import type { useTheme } from 'next-themes';

import type { useLanguageHelper } from '../hooks/affine/use-language-helper';
import { track } from '../mixpanel';
import { registerAffineCommand } from './registry';

export function registerAffineSettingsCommands({
Expand Down Expand Up @@ -34,6 +35,10 @@ export function registerAffineSettingsCommands({
icon: <SettingsIcon />,
preconditionStrategy: () => theme.theme !== 'system',
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'theme',
value: 'system',
});
theme.setTheme('system');
},
})
Expand All @@ -48,6 +53,10 @@ export function registerAffineSettingsCommands({
icon: <SettingsIcon />,
preconditionStrategy: () => theme.theme !== 'dark',
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'theme',
value: 'dark',
});
theme.setTheme('dark');
},
})
Expand All @@ -63,6 +72,11 @@ export function registerAffineSettingsCommands({
icon: <SettingsIcon />,
preconditionStrategy: () => theme.theme !== 'light',
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'theme',
value: 'light',
});

theme.setTheme('light');
},
})
Expand All @@ -80,6 +94,11 @@ export function registerAffineSettingsCommands({
preconditionStrategy: () =>
store.get(appSettingAtom).fontStyle !== 'Sans',
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'fontStyle',
value: 'Sans',
});

store.set(appSettingAtom, prev => ({
...prev,
fontStyle: 'Sans',
Expand All @@ -99,6 +118,11 @@ export function registerAffineSettingsCommands({
preconditionStrategy: () =>
store.get(appSettingAtom).fontStyle !== 'Serif',
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'fontStyle',
value: 'Serif',
});

store.set(appSettingAtom, prev => ({
...prev,
fontStyle: 'Serif',
Expand All @@ -118,6 +142,11 @@ export function registerAffineSettingsCommands({
preconditionStrategy: () =>
store.get(appSettingAtom).fontStyle !== 'Mono',
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'fontStyle',
value: 'Mono',
});

store.set(appSettingAtom, prev => ({
...prev,
fontStyle: 'Mono',
Expand All @@ -138,6 +167,11 @@ export function registerAffineSettingsCommands({
icon: <SettingsIcon />,
preconditionStrategy: () => currentLanguage?.tag !== language.tag,
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'language',
value: language.name,
});

onLanguageChange(language.tag);
},
})
Expand All @@ -158,6 +192,10 @@ export function registerAffineSettingsCommands({
icon: <SettingsIcon />,
preconditionStrategy: () => environment.isDesktop,
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'clientBorder',
value: store.get(appSettingAtom).clientBorder ? 'off' : 'on',
});
store.set(appSettingAtom, prev => ({
...prev,
clientBorder: !prev.clientBorder,
Expand All @@ -178,6 +216,11 @@ export function registerAffineSettingsCommands({
category: 'affine:settings',
icon: <SettingsIcon />,
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'fullWidthLayout',
value: store.get(appSettingAtom).fullWidthLayout ? 'off' : 'on',
});

store.set(appSettingAtom, prev => ({
...prev,
fullWidthLayout: !prev.fullWidthLayout,
Expand All @@ -201,6 +244,11 @@ export function registerAffineSettingsCommands({
icon: <SettingsIcon />,
preconditionStrategy: () => environment.isDesktop,
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'enableNoisyBackground',
value: store.get(appSettingAtom).enableNoisyBackground ? 'off' : 'on',
});

store.set(appSettingAtom, prev => ({
...prev,
enableNoisyBackground: !prev.enableNoisyBackground,
Expand All @@ -222,6 +270,10 @@ export function registerAffineSettingsCommands({
icon: <SettingsIcon />,
preconditionStrategy: () => environment.isDesktop && environment.isMacOs,
run() {
track.$.cmdk.settings.changeAppSetting({
key: 'enableBlurBackground',
value: store.get(appSettingAtom).enableBlurBackground ? 'off' : 'on',
});
store.set(appSettingAtom, prev => ({
...prev,
enableBlurBackground: !prev.enableBlurBackground,
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/core/src/commands/affine-updates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { useI18n } from '@affine/i18n';
import { ResetIcon } from '@blocksuite/icons/rc';
import type { createStore } from 'jotai';

import { track } from '../mixpanel';
import { registerAffineCommand } from './registry';

export function registerAffineUpdatesCommands({
Expand All @@ -24,6 +25,8 @@ export function registerAffineUpdatesCommands({
label: t['com.affine.cmdk.affine.restart-to-upgrade'](),
preconditionStrategy: () => !!store.get(updateReadyAtom),
run() {
track.$.cmdk.updates.quitAndInstall();

apis?.updater.quitAndInstall().catch(err => {
notify.error({
title: 'Failed to restart to upgrade',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export const PageHeaderMenuButton = ({

const handleSwitchMode = useCallback(() => {
doc.toggleMode();
track.$.header.docOptions.switchPageMode();
track.$.header.docOptions.switchPageMode({
mode: currentMode === 'page' ? 'edgeless' : 'page',
});
toast(
currentMode === 'page'
? t['com.affine.toastMessage.edgelessMode']()
Expand Down
Loading
Loading