@@ -30,15 +30,17 @@ export function useOpenAI(){
3030
3131 const location = useLocation ( )
3232
33-
34- useEffect ( ( ) => {
33+ const resetSearch = ( ) => {
3534 if ( location . state && location . state . previewPage === "documentView" ) {
36- const resultSaved = localStorage . getItem ( `${ location . pathname } ___SEARCH__RESULT` )
37- const startSaved = localStorage . getItem ( `${ location . pathname } ___START` ) || 0
38- setStartValue ( Number ( startSaved ) )
39- if ( resultSaved ) setSearchResult ( JSON . parse ( resultSaved ) )
35+ const resultSaved = localStorage . getItem ( `${ location . pathname } ___SEARCH__RESULT` )
36+ const startSaved = localStorage . getItem ( `${ location . pathname } ___START` ) || 0
37+ setStartValue ( Number ( startSaved ) )
38+ if ( resultSaved ) setSearchResult ( JSON . parse ( resultSaved ) )
39+ } else {
40+ setStartValue ( 0 )
41+ setSearchResult ( false )
4042 }
41- } , [ location ] )
43+ }
4244
4345 function getUrl ( action = "changes" ) {
4446 const client = woqlClient . copy ( )
@@ -54,9 +56,9 @@ export function useOpenAI(){
5456 ///changes/:orgid/:dbid/indexedcommit
5557 const getSearchableCommit = async ( limit = 1 , status = null ) => {
5658 try {
57- setLoading ( true )
5859 setSearchableCommit ( false )
59- const url = `${ getUrl ( ) } /indexedcommits?limit=${ limit } &status=${ status } `
60+ setLoading ( true )
61+ const url = `${ getUrl ( 'indexes' ) } ?limit=${ limit } &status=${ status } `
6062 const result = await woqlClient . sendCustomRequest ( "GET" , url )
6163 if ( result && result . bindings ) {
6264 setSearchableCommit ( result . bindings )
@@ -72,9 +74,10 @@ export function useOpenAI(){
7274 const getResearchResult = async ( commit , freeText , domain , branch = "main" ) => {
7375 if ( woqlClient ) {
7476 try {
77+ setSearchResult ( false )
7578 setLoading ( true )
7679 localStorage . setItem ( `${ location . pathname } ___SEARCH__TEXT` , freeText )
77- const url = `${ getUrl ( 'index ' ) } /search?domain=${ domain } &commit=${ commit } `
80+ const url = `${ getUrl ( 'indexes ' ) } /search?domain=${ domain } &commit=${ commit } `
7881 const result = await woqlClient . sendCustomRequest ( "POST" , url , { freeText :freeText } )
7982 localStorage . setItem ( `${ location . pathname } ___SEARCH__RESULT` , JSON . stringify ( result ) )
8083 setSearchResult ( result )
@@ -104,7 +107,7 @@ export function useOpenAI(){
104107
105108 const pollingCall = async ( commitid , updateStatus ) => {
106109 try {
107- const pollingUrl = `${ getUrl ( ) } /check/${ commitid } `
110+ const pollingUrl = `${ getUrl ( 'indexes' ) } /check/${ commitid } `
108111 const document = await woqlClient . sendCustomRequest ( "GET" , pollingUrl )
109112 if ( document . indexing_status !== "Assigned" && document . indexing_status !== "Error" ) {
110113 await timeout ( 5000 )
@@ -301,6 +304,7 @@ export function useOpenAI(){
301304
302305
303306 return { pollingCall,
307+ resetSearch,
304308 getPrewiew,
305309 resetPreviewResult,
306310 getSearchableCommit,
0 commit comments