Skip to content

Commit

Permalink
chore(core): events for backlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Dec 20, 2024
1 parent bdbefd3 commit bdc8806
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { toURLSearchParams } from '@affine/core/modules/navigation';
import { WorkbenchLink } from '@affine/core/modules/workbench';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import type { JobMiddleware } from '@blocksuite/affine/store';
import { ToggleExpandIcon } from '@blocksuite/icons/rc';
import * as Collapsible from '@radix-ui/react-collapsible';
Expand Down Expand Up @@ -93,8 +94,16 @@ const CollapsibleSection = ({
docId,
linkDocId
);

const handleToggle = useCallback(() => {
setOpen(!open);
track.doc.biDirectionalLinksPanel.$.toggle({
type: open ? 'collapse' : 'expand',
});
}, [open, setOpen]);

return (
<Collapsible.Root open={open} onOpenChange={setOpen}>
<Collapsible.Root open={open} onOpenChange={handleToggle}>
<Collapsible.Trigger className={styles.link}>
{title}
{length ? (
Expand Down Expand Up @@ -197,6 +206,9 @@ export const BiDirectionalLinkPanel = () => {

const handleClickShow = useCallback(() => {
setShow(!show);
track.doc.biDirectionalLinksPanel.$.toggle({
type: show ? 'collapse' : 'expand',
});
}, [show, setShow]);

const textRendererOptions = useMemo(() => {
Expand Down Expand Up @@ -243,7 +255,14 @@ export const BiDirectionalLinkPanel = () => {
{backlinkGroups.map(linkGroup => (
<CollapsibleSection
key={linkGroup.docId}
title={<AffinePageReference pageId={linkGroup.docId} />}
title={
<AffinePageReference
pageId={linkGroup.docId}
onClick={() => {
track.doc.biDirectionalLinksPanel.backlinkTitle.navigate();
}}
/>
}
length={linkGroup.links.length}
docId={docService.doc.id}
linkDocId={linkGroup.docId}
Expand Down Expand Up @@ -289,6 +308,9 @@ export const BiDirectionalLinkPanel = () => {
to={to}
key={link.blockId}
className={styles.linkPreview}
onClick={() => {
track.doc.biDirectionalLinksPanel.backlinkPreview.navigate();
}}
>
{edgelessLink ? (
<>
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/track/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ const PageEvents = {
sidepanel: {
property: ['addProperty'],
},
biDirectionalLinksPanel: {
$: ['toggle'],
backlinkTitle: ['toggle', 'navigate'],
backlinkPreview: ['navigate'],
},
},
edgeless: {},
workspace: {
Expand Down

0 comments on commit bdc8806

Please sign in to comment.