Skip to content

Commit

Permalink
chore(core): add journal open event
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Sep 3, 2024
1 parent 106f332 commit 3ffe16d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useJournalHelper } from '@affine/core/hooks/use-journal';
import { track } from '@affine/core/mixpanel';
import {
PeekViewService,
useInsidePeekView,
Expand Down Expand Up @@ -131,6 +132,8 @@ export function AffinePageReference({
const peekView = useService(PeekViewService).peekView;
const isInPeekView = useInsidePeekView();

const isJournal = journalHelper.isPageJournal(pageId);

useEffect(() => {
if (isSameDoc) {
if (mode === DocMode.Edgeless && elementIds?.length) {
Expand All @@ -145,6 +148,9 @@ export function AffinePageReference({

const onClick = useCallback(
(e: React.MouseEvent) => {
if (isJournal) {
track.doc.editor.pageRef.journalVisited();
}
if (e.shiftKey && ref.current) {
e.preventDefault();
e.stopPropagation();
Expand All @@ -162,7 +168,7 @@ export function AffinePageReference({

return;
},
[isInPeekView, peekView, anchor, std]
[isJournal, std, anchor, isInPeekView, peekView]
);

// A block/element reference link
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/core/src/hooks/use-journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { initEmptyPage, useService } from '@toeverything/infra';
import dayjs from 'dayjs';
import { useCallback, useMemo } from 'react';

import { track } from '../mixpanel';
import { WorkbenchService } from '../modules/workbench';
import type { DocCollection } from '../shared';
import { useCurrentWorkspacePropertiesAdapter } from './use-affine-adapter';
Expand Down Expand Up @@ -162,6 +163,7 @@ export const useJournalRouteHelper = (docCollection: DocCollection) => {
workbench.openDoc(page.id, {
at: newTab ? 'new-tab' : 'active',
});
track.$.navigationPanel.journal.journalVisited();
return page.id;
},
[getJournalByDate, workbench]
Expand Down
5 changes: 4 additions & 1 deletion packages/frontend/core/src/mixpanel/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type DocEvents =
| 'restoreDoc'
| 'switchPageMode'
| 'openDocOptionsMenu'
| 'openDocInfo';
| 'openDocInfo'
| 'journalVisited';
type EditorEvents = 'bold' | 'italic' | 'underline' | 'strikeThrough';
// END SECTION

Expand Down Expand Up @@ -221,6 +222,7 @@ const PageEvents = {
'openSettings',
],
profileAndBadge: ['openSettings'],
journal: ['journalVisited'],
},
aiOnboarding: {
dialog: ['viewPlans'],
Expand Down Expand Up @@ -263,6 +265,7 @@ const PageEvents = {
slashMenu: ['linkDoc', 'createDoc'],
atMenu: ['linkDoc'],
formatToolbar: ['bold'],
pageRef: ['journalVisited'],
},
inlineDocInfo: {
$: ['toggle'],
Expand Down

0 comments on commit 3ffe16d

Please sign in to comment.