1
- import React , { useEffect , useState } from 'react' ;
1
+ import React , { useEffect , useRef , useState } from 'react' ;
2
2
import {
3
3
View ,
4
4
Text ,
@@ -36,30 +36,15 @@ export function Search({navigation}) {
36
36
const loading = useSelector ( state => state . data . loading ) ;
37
37
const IsAnime = useSelector ( state => state . data . Anime ) ;
38
38
const [ searchTerm , setSearchTerm ] = useState ( '' ) ;
39
- const [ activeTab , setActiveTab ] = useState ( 'ComicOnline ' ) ;
39
+ const [ activeTab , setActiveTab ] = useState ( 'ComicHub ' ) ;
40
40
const [ viewAll , setViewAll ] = useState ( null ) ;
41
- const [ searchData , setSearchData ] = useState ( { ComicOnline : [ ] , ComicHub : [ ] } ) ;
42
- const flatlistRef = React . useRef ( ) ;
41
+ const [ searchData , setSearchData ] = useState ( { ComicHub : [ ] , ComicOnline : [ ] } ) ;
42
+ const flatlistRef = useRef ( ) ;
43
43
let Tag = View ;
44
44
45
45
const fetchData = async ( ) => {
46
46
if ( loading ) return ;
47
47
if ( ! searchTerm . trim ( ) ) return ;
48
- if ( IsAnime ) {
49
- console . log ( 'searching by anime' ) ;
50
-
51
- await analytics ( ) . logEvent ( 'search_anime' , {
52
- search : searchTerm ?. trim ( ) ?. toString ( ) ,
53
- } ) ;
54
- let data = await SearchAnime ( searchTerm , dispatch ) ;
55
- if ( data . length == 0 ) {
56
- setSearchData ( [ ] ) ;
57
- Alert . alert ( 'No results found' ) ;
58
- return ;
59
- }
60
- setSearchData ( data ) ;
61
- return ;
62
- }
63
48
64
49
await analytics ( ) . logEvent ( 'search_comic' , {
65
50
search : searchTerm ?. trim ( ) ?. toString ( ) ,
@@ -68,17 +53,19 @@ export function Search({navigation}) {
68
53
// https://readcomicsonline.ru/comic/{comic-name}/{chapter-name}
69
54
let link = searchTerm . trim ( ) ;
70
55
if (
71
- ! link . startsWith ( 'https://readcomicsonline.ru/comic/' ) ||
56
+ ( ! link . startsWith ( 'https://readcomicsonline.ru/comic/' ) &&
57
+ ! link . startsWith ( 'https://comichubfree.com/comic/' ) ) ||
72
58
! link . includes ( 'comic/' )
73
59
) {
74
- const [ readcomicsonlineResult , comichubfreeResult ] = await Promise . all ( [
75
- dispatch ( searchComic ( link , 'readcomicsonline' ) ) ,
60
+ if ( link . startsWith ( 'http://' ) || link . startsWith ( 'https://' ) ) {
61
+ Alert . alert ( 'Invalid link' , 'Please enter a valid comic link' ) ;
62
+ return ;
63
+ }
64
+
65
+ const [ comichubfreeResult , readcomicsonlineResult ] = await Promise . all ( [
76
66
dispatch ( searchComic ( link , 'comichubfree' ) ) ,
67
+ dispatch ( searchComic ( link , 'readcomicsonline' ) ) ,
77
68
] ) ;
78
- console . log ( 'readcomicsonlineResult' , {
79
- readcomicsonlineResult,
80
- comichubfreeResult,
81
- } ) ;
82
69
83
70
if ( readcomicsonlineResult || comichubfreeResult ) {
84
71
if (
@@ -88,8 +75,8 @@ export function Search({navigation}) {
88
75
Alert . alert ( 'No results found' ) ;
89
76
}
90
77
setSearchData ( {
91
- ComicOnline : readcomicsonlineResult ,
92
78
ComicHub : comichubfreeResult ,
79
+ ComicOnline : readcomicsonlineResult ,
93
80
} ) ;
94
81
}
95
82
return ;
@@ -196,8 +183,8 @@ export function Search({navigation}) {
196
183
alignItems : 'center' ,
197
184
gap : 12 ,
198
185
} } >
199
- < Text style = { { fontSize : 5 , color : 'white' , marginLeft : 12 } } >
200
- { '\u2B24' }
186
+ < Text style = { { fontSize : 14 , color : 'white' , marginLeft : 12 } } >
187
+ { index + 1 } .
201
188
</ Text >
202
189
< Text style = { styles . link } > { item ?. title } </ Text >
203
190
</ TouchableOpacity >
@@ -248,7 +235,7 @@ export function Search({navigation}) {
248
235
< View
249
236
style = { {
250
237
flexDirection : 'row' ,
251
- left : IsAnime ? 0 : widthPercentageToDP ( '6 %' ) ,
238
+ left : widthPercentageToDP ( '7 %' ) ,
252
239
} } >
253
240
< Text
254
241
style = { {
@@ -335,8 +322,11 @@ export function Search({navigation}) {
335
322
< View
336
323
style = { {
337
324
flexDirection : 'row' ,
338
- alignItems : 'center' ,
339
- gap : 5 ,
325
+ marginTop : 24 ,
326
+ paddingHorizontal : 16 ,
327
+ borderBottomColor : 'rgba(255,255,255,0.1)' ,
328
+ borderBottomWidth : 1 ,
329
+ justifyContent : 'space-between' ,
340
330
} } >
341
331
{ Object . keys ( searchData ) . map ( ( key , idx ) => {
342
332
return (
@@ -346,27 +336,40 @@ export function Search({navigation}) {
346
336
setActiveTab ( key ) ;
347
337
} }
348
338
style = { {
349
- paddingVertical : 5 ,
350
- paddingHorizontal : 10 ,
351
- borderRadius : 12 ,
352
- backgroundColor :
353
- activeTab !== key ? '#14142a' : 'steelblue' ,
339
+ marginRight : 28 ,
340
+ borderBottomColor :
341
+ activeTab === key ? '#3268de' : 'transparent' ,
342
+ borderBottomWidth : 2 ,
343
+ paddingBottom : 4 ,
344
+ flexDirection : 'row' ,
345
+ gap : 6 ,
354
346
} } >
355
347
< Text
356
- style = { [
357
- activeTab !== key
358
- ? styles . SwitchUnselectedText
359
- : styles . SwitchSelectedText ,
360
- ] } >
348
+ style = { {
349
+ fontSize : 14 ,
350
+ fontWeight : '700' ,
351
+ color :
352
+ activeTab === key
353
+ ? 'rgba(255,255,255,1)'
354
+ : 'rgba(255,255,255,0.6)' ,
355
+ } } >
361
356
{ key }
362
357
</ Text >
358
+ < Text
359
+ style = { {
360
+ fontSize : 14 ,
361
+ fontWeight : '700' ,
362
+ color :
363
+ activeTab === key
364
+ ? 'rgba(255, 6, 6, 1)'
365
+ : 'rgba(255, 6, 6, 0.6)' ,
366
+ } } >
367
+ ({ searchData [ key ] ?. length } )
368
+ </ Text >
363
369
</ TouchableOpacity >
364
370
) ;
365
371
} ) }
366
372
</ View >
367
- < Text style = { styles . title } >
368
- Total results: { searchData ?. [ activeTab ] ?. length }
369
- </ Text >
370
373
</ View >
371
374
}
372
375
ListEmptyComponent = {
@@ -403,6 +406,8 @@ export function Search({navigation}) {
403
406
ListFooterComponent = {
404
407
< View style = { { marginVertical : heightPercentageToDP ( '6%' ) } } />
405
408
}
409
+ maxToRenderPerBatch = { 15 }
410
+ initialNumToRender = { 10 }
406
411
/>
407
412
< Modal
408
413
transparent
0 commit comments