1
1
import {
2
2
Button ,
3
+ Input ,
3
4
Modal ,
4
5
ModalBody ,
5
6
ModalContent ,
@@ -20,7 +21,7 @@ import {
20
21
isNotionConfigured ,
21
22
runNotionSync ,
22
23
} from '@/actions/knowledge/notion' ;
23
- import { CiShare1 } from 'react-icons/ci' ;
24
+ import { CiSearch , CiShare1 } from 'react-icons/ci' ;
24
25
import { EditContext } from '@/contexts/edit' ;
25
26
import { importFiles } from '@/actions/knowledge/filehelper' ;
26
27
@@ -31,6 +32,8 @@ interface NotionFileModalProps {
31
32
setIsSyncing : React . Dispatch < React . SetStateAction < boolean > > ;
32
33
notionConfigured : boolean ;
33
34
setNotionConfigured : React . Dispatch < React . SetStateAction < boolean > > ;
35
+ syncError : string ;
36
+ setSyncError : React . Dispatch < React . SetStateAction < string > > ;
34
37
}
35
38
36
39
export const NotionFileModal = ( {
@@ -40,14 +43,16 @@ export const NotionFileModal = ({
40
43
setNotionConfigured,
41
44
isSyncing,
42
45
setIsSyncing,
46
+ syncError,
47
+ setSyncError,
43
48
} : NotionFileModalProps ) => {
44
49
const { droppedFiles, setDroppedFiles } = useContext ( EditContext ) ;
50
+ const [ searchQuery , setSearchQuery ] = useState < string > ( '' ) ;
45
51
46
52
const [ notionFiles , setNotionFiles ] = useState <
47
53
Map < string , { url : string ; fileName : string } >
48
54
> ( new Map ( ) ) ;
49
55
50
- const [ syncError , setSyncError ] = useState ( '' ) ;
51
56
const [ selectedFile , setSelectedFile ] = useState < string [ ] > (
52
57
Array . from ( droppedFiles . keys ( ) )
53
58
) ;
@@ -76,13 +81,13 @@ export const NotionFileModal = ({
76
81
const files = await importFiles ( selectedFile , 'notion' ) ;
77
82
setDroppedFiles ( ( prev ) => {
78
83
const newMap = new Map ( prev ) ;
79
- for ( const file of Array . from ( newMap . entries ( ) ) ) {
80
- if ( file [ 1 ] . type === 'notion' ) {
81
- newMap . delete ( file [ 0 ] ) ;
84
+ for ( const [ key , file ] of Array . from ( newMap . entries ( ) ) ) {
85
+ if ( file . type === 'notion' ) {
86
+ newMap . delete ( key ) ;
82
87
}
83
88
}
84
- for ( const file of Array . from ( files . entries ( ) ) ) {
85
- newMap . set ( file [ 0 ] , file [ 1 ] ) ;
89
+ for ( const [ key , file ] of Array . from ( files . entries ( ) ) ) {
90
+ newMap . set ( key , file ) ;
86
91
}
87
92
return newMap ;
88
93
} ) ;
@@ -146,12 +151,23 @@ export const NotionFileModal = ({
146
151
</ div >
147
152
</ ModalHeader >
148
153
< ModalBody >
154
+ < Input
155
+ className = "w-[20%] flex justify-end"
156
+ placeholder = "Search"
157
+ size = "sm"
158
+ value = { searchQuery }
159
+ onChange = { ( e ) => {
160
+ setSearchQuery ( e . target . value ) ;
161
+ } }
162
+ startContent = { < CiSearch /> }
163
+ />
149
164
{ notionConfigured && notionFiles . size > 0 ? (
150
165
< div className = "flex flex-col gap-1" >
151
166
< Table
152
167
selectionMode = "multiple"
153
168
selectionBehavior = "toggle"
154
169
aria-label = "notion-files"
170
+ isCompact = { true }
155
171
selectedKeys = { selectedFile }
156
172
onSelectionChange = { ( selected ) => {
157
173
handleSelectedFileChange ( selected ) ;
@@ -162,26 +178,34 @@ export const NotionFileModal = ({
162
178
< TableColumn > Link</ TableColumn >
163
179
</ TableHeader >
164
180
< TableBody >
165
- { Array . from ( notionFiles . entries ( ) ) . map ( ( [ key , value ] ) => (
166
- < TableRow key = { key } >
167
- < TableCell >
168
- < div className = "flex flex-col" >
169
- < p > { value . fileName } </ p >
170
- </ div >
171
- </ TableCell >
172
- < TableCell >
173
- < Button
174
- isIconOnly
175
- color = "primary"
176
- variant = "flat"
177
- startContent = { < CiShare1 /> }
178
- onClick = { ( ) => {
179
- window . open ( value . url ) ;
180
- } }
181
- />
182
- </ TableCell >
183
- </ TableRow >
184
- ) ) }
181
+ { Array . from ( notionFiles . entries ( ) )
182
+ . filter ( ( [ _ , file ] ) => {
183
+ if ( ! searchQuery ) return true ;
184
+ return file . fileName
185
+ . toLowerCase ( )
186
+ . includes ( searchQuery . toLowerCase ( ) ) ;
187
+ } )
188
+ . map ( ( [ key , value ] ) => (
189
+ < TableRow key = { key } >
190
+ < TableCell >
191
+ < div className = "flex flex-col" >
192
+ < p > { value . fileName } </ p >
193
+ </ div >
194
+ </ TableCell >
195
+ < TableCell >
196
+ < Button
197
+ isIconOnly
198
+ size = "sm"
199
+ color = "primary"
200
+ variant = "flat"
201
+ startContent = { < CiShare1 /> }
202
+ onClick = { ( ) => {
203
+ window . open ( value . url ) ;
204
+ } }
205
+ />
206
+ </ TableCell >
207
+ </ TableRow >
208
+ ) ) }
185
209
</ TableBody >
186
210
</ Table >
187
211
</ div >
@@ -194,7 +218,7 @@ export const NotionFileModal = ({
194
218
) }
195
219
</ ModalBody >
196
220
< ModalFooter >
197
- < Button color = "primary" onClick = { onClickImport } >
221
+ < Button color = "primary" size = "sm" onClick = { onClickImport } >
198
222
Import
199
223
</ Button >
200
224
</ ModalFooter >
0 commit comments