11import React , { useEffect , useState , useMemo } from "react" ;
22import { Collapse , Spinner , Icon } from "@blueprintjs/core" ;
33import { findSimilarNodesVectorOnly , type VectorMatch } from "~/utils/hyde" ;
4- import { useNodeContext , type NodeContext } from "~/utils/useNodeContext" ;
54import ReactDOM from "react-dom" ;
5+ import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle" ;
6+ import { DiscourseNode } from "~/utils/getDiscourseNodes" ;
7+ import extractContentFromTitle from "~/utils/extractContentFromTitle" ;
68
79type VectorSearchParams = {
810 text : string ;
@@ -17,10 +19,12 @@ export const VectorDuplicateMatches = ({
1719 pageTitle,
1820 text,
1921 limit = 15 ,
22+ node,
2023} : {
2124 pageTitle ?: string ;
2225 text ?: string ;
2326 limit ?: number ;
27+ node : DiscourseNode ;
2428} ) => {
2529 const [ debouncedText , setDebouncedText ] = useState ( text ) ;
2630 useEffect ( ( ) => {
@@ -37,13 +41,14 @@ export const VectorDuplicateMatches = ({
3741 const [ hasSearched , setHasSearched ] = useState ( false ) ;
3842 const [ suggestions , setSuggestions ] = useState < VectorMatch [ ] > ( [ ] ) ;
3943
40- const nodeContext : NodeContext | null = useNodeContext ( pageTitle || "" ) ;
44+ const searchText = extractContentFromTitle ( pageTitle || "" , node ) ;
45+ const pageUid = getPageUidByPageTitle ( searchText ) ;
4146 const activeContext = useMemo (
4247 ( ) =>
4348 text !== undefined
4449 ? { searchText : debouncedText || "" , pageUid : null }
45- : nodeContext ,
46- [ text , debouncedText , nodeContext ] ,
50+ : { searchText , pageUid } ,
51+ [ text , debouncedText , searchText , pageUid ] ,
4752 ) ;
4853
4954 useEffect ( ( ) => {
@@ -163,6 +168,7 @@ export const VectorDuplicateMatches = ({
163168export const renderPossibleDuplicates = (
164169 h1 : HTMLHeadingElement ,
165170 title : string ,
171+ node : DiscourseNode ,
166172) => {
167173 const titleContainer = h1 . parentElement ;
168174 if ( ! titleContainer || ! titleContainer . parentElement ) {
@@ -195,7 +201,7 @@ export const renderPossibleDuplicates = (
195201
196202 /*eslint-disable-next-line react/no-deprecated*/
197203 ReactDOM . render (
198- React . createElement ( VectorDuplicateMatches , { pageTitle : title } ) ,
204+ React . createElement ( VectorDuplicateMatches , { pageTitle : title , node } ) ,
199205 vectorContainer ,
200206 ) ;
201207 /*eslint-disable-next-line react/no-deprecated*/
0 commit comments