@@ -25,7 +25,7 @@ import {
25
25
getLocationForDataSourceViewContentNode ,
26
26
getVisualForDataSourceViewContentNode ,
27
27
} from "@app/lib/content_nodes" ;
28
- import { useSpaces , useSpacesSearch } from "@app/lib/swr/spaces" ;
28
+ import { useSpaces , useSpaceSearchWithInfiniteScroll , useSpacesSearch } from "@app/lib/swr/spaces" ;
29
29
import type { DataSourceViewContentNode , LightWorkspaceType } from "@app/types" ;
30
30
import { MIN_SEARCH_QUERY_SIZE } from "@app/types" ;
31
31
@@ -67,9 +67,7 @@ export const InputBarAttachmentsPicker = ({
67
67
const fileInputRef = useRef < HTMLInputElement > ( null ) ;
68
68
const itemsContainerRef = useRef < HTMLDivElement > ( null ) ;
69
69
const [ isOpen , setIsOpen ] = useState ( false ) ;
70
- const [ currentResultNodes , setCurrentResultNodes ] = useState <
71
- DataSourceViewContentNode [ ]
72
- > ( [ ] ) ;
70
+
73
71
74
72
const {
75
73
inputValue : search ,
@@ -81,23 +79,15 @@ export const InputBarAttachmentsPicker = ({
81
79
minLength : MIN_SEARCH_QUERY_SIZE ,
82
80
} ) ;
83
81
84
- const {
85
- cursorPagination,
86
- reset : resetPagination ,
87
- handleLoadNext,
88
- pageIndex,
89
- } = useCursorPagination ( PAGE_SIZE ) ;
90
-
91
82
const { spaces, isSpacesLoading } = useSpaces ( { workspaceId : owner . sId } ) ;
92
- const { searchResultNodes, isSearchLoading, nextPageCursor } =
93
- useSpacesSearch ( {
83
+
84
+
85
+ const { searchResultNodes, isSearchLoading, hasMore, nextPage } =
86
+ useSpaceSearchWithInfiniteScroll ( {
94
87
includeDataSources : true ,
95
88
owner,
96
89
search : searchQuery ,
97
90
viewType : "all" ,
98
- disabled : isSpacesLoading || ! searchQuery ,
99
- spaceIds : spaces . map ( ( s ) => s . sId ) ,
100
- pagination : cursorPagination ,
101
91
} ) ;
102
92
103
93
const attachedNodeIds = useMemo ( ( ) => {
@@ -115,22 +105,11 @@ export const InputBarAttachmentsPicker = ({
115
105
}
116
106
} ;
117
107
118
- useEffect ( ( ) => {
119
- resetPagination ( ) ;
120
- } , [ searchQuery , resetPagination ] ) ;
121
-
122
- useEffect ( ( ) => {
123
- if ( searchResultNodes && ! isSearchLoading ) {
124
- const unfoldedNodes = getUnfoldedNodes ( searchResultNodes ) ;
125
- setCurrentResultNodes ( ( prevResultNodes ) => {
126
- if ( pageIndex === 0 ) {
127
- return unfoldedNodes ;
128
- } else {
129
- return [ ...prevResultNodes , ...unfoldedNodes ] ;
130
- }
131
- } ) ;
132
- }
133
- } , [ searchResultNodes , isSearchLoading , pageIndex ] ) ;
108
+ // useEffect(() => {
109
+ // resetPagination();
110
+ // }, [searchQuery, resetPagination]);
111
+
112
+ const unfoldedNodes = getUnfoldedNodes ( searchResultNodes ) ;
134
113
135
114
return (
136
115
< DropdownMenu
@@ -197,8 +176,8 @@ export const InputBarAttachmentsPicker = ({
197
176
< DropdownMenuSeparator />
198
177
< ScrollArea className = "flex max-h-96 flex-col" hideScrollBar >
199
178
< div className = "pt-0" ref = { itemsContainerRef } >
200
- { currentResultNodes . length > 0 ? (
201
- currentResultNodes . map ( ( item , index ) => (
179
+ { unfoldedNodes . length > 0 ? (
180
+ unfoldedNodes . map ( ( item , index ) => (
202
181
< DropdownMenuItem
203
182
key = { index }
204
183
label = { item . title }
@@ -232,9 +211,9 @@ export const InputBarAttachmentsPicker = ({
232
211
) }
233
212
</ div >
234
213
< InfiniteScroll
235
- nextPage = { ( ) => handleLoadNext ( nextPageCursor ) }
236
- hasMore = { ! ! nextPageCursor }
237
- showLoader = { currentResultNodes . length > 0 && isSearchLoading }
214
+ nextPage = { nextPage }
215
+ hasMore = { hasMore }
216
+ showLoader = { unfoldedNodes . length > 0 && isSearchLoading }
238
217
loader = { < Loader /> }
239
218
/>
240
219
< ScrollBar className = "py-0" />
0 commit comments