@@ -8,13 +8,15 @@ import {
88} from '@hypothesis/frontend-shared' ;
99import classnames from 'classnames' ;
1010import type { ComponentChildren } from 'preact' ;
11+ import { useCallback } from 'preact/hooks' ;
1112
1213import { pluralize } from '../../shared/pluralize' ;
1314import type { SidebarSettings } from '../../types/config' ;
1415import type { TabName } from '../../types/sidebar' ;
1516import { applyTheme } from '../helpers/theme' ;
1617import { withServices } from '../service-context' ;
1718import type { AnnotationsService } from '../services/annotations' ;
19+ import type { FrameSyncService } from '../services/frame-sync' ;
1820import { useSidebarStore } from '../store' ;
1921import ThreadList from './ThreadList' ;
2022import { useRootThread } from './hooks/use-root-thread' ;
@@ -99,6 +101,7 @@ export type SidebarTabsProps = {
99101 // injected
100102 settings : SidebarSettings ;
101103 annotationsService : AnnotationsService ;
104+ frameSync : FrameSyncService ;
102105} ;
103106
104107/**
@@ -108,6 +111,7 @@ function SidebarTabs({
108111 annotationsService,
109112 isLoading,
110113 settings,
114+ frameSync,
111115} : SidebarTabsProps ) {
112116 const { rootThread, tabCounts } = useRootThread ( ) ;
113117 const store = useSidebarStore ( ) ;
@@ -143,6 +147,11 @@ function SidebarTabs({
143147 }
144148 const tabCountsSummary = tabCountsSummaryPieces . join ( ', ' ) ;
145149
150+ const createPageNoteWithDocumentMeta = useCallback ( async ( ) => {
151+ const { metadata } = await frameSync . getDocumentInfo ( ) ;
152+ annotationsService . createPageNote ( metadata ) ;
153+ } , [ annotationsService , frameSync ] ) ;
154+
146155 return (
147156 < >
148157 < div aria-live = "polite" role = "status" className = "sr-only" >
@@ -201,7 +210,7 @@ function SidebarTabs({
201210 < div className = "flex justify-end" >
202211 < Button
203212 data-testid = "new-note-button"
204- onClick = { ( ) => annotationsService . createPageNote ( ) }
213+ onClick = { createPageNoteWithDocumentMeta }
205214 variant = "primary"
206215 style = { applyTheme ( [ 'ctaBackgroundColor' ] , settings ) }
207216 >
@@ -244,4 +253,8 @@ function SidebarTabs({
244253 ) ;
245254}
246255
247- export default withServices ( SidebarTabs , [ 'annotationsService' , 'settings' ] ) ;
256+ export default withServices ( SidebarTabs , [
257+ 'annotationsService' ,
258+ 'frameSync' ,
259+ 'settings' ,
260+ ] ) ;
0 commit comments