1
1
import React , { useEffect , useState } from 'react' ;
2
- import { StyleSheet , SafeAreaView , ScrollView , Text } from 'react-native' ;
2
+ import { StyleSheet , SafeAreaView , ScrollView , Text , View } from 'react-native' ;
3
3
import { InputField } from '@/components/InputField' ;
4
4
import CurveTextHeader from '@/components/CurveTextHeader' ;
5
5
import { Button } from '@/components/Button' ;
@@ -11,35 +11,61 @@ import TrackCard from '@/components/TrackCard';
11
11
export default function SearchScreen ( ) {
12
12
const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
13
13
const [ searchResults , setSearchResults ] = useState < Song [ ] > ( [ ] ) ;
14
-
15
- const router = useRouter ( ) ;
14
+ const [ queryTarget , setQueryTarget ] = useState < 'users' | 'songs' > ( 'songs' ) ;
16
15
17
16
const updateSearchResults = async ( query : string ) => {
18
- const newSongs = await searchSongs ( query ) ;
19
- setSearchResults ( newSongs ) ;
17
+ if ( queryTarget === 'songs' ) {
18
+ const newSongs = await searchSongs ( query ) ;
19
+ setSearchResults ( newSongs ) ;
20
+ }
20
21
} ;
21
22
22
23
const handleSearch = ( query : string ) => {
23
24
setSearchQuery ( query ) ;
24
- updateSearchResults ( query ) ;
25
25
} ;
26
26
27
27
return (
28
28
< SafeAreaView style = { styles . container } >
29
29
< CurveTextHeader additionalStyles = { { borderBottomWidth : 0 } } />
30
30
< InputField
31
31
label = ""
32
- placeholder = " Search songs ..."
32
+ placeholder = { ` Search ${ queryTarget } ...` }
33
33
onChange = { handleSearch }
34
34
style = { { marginTop : 10 , width : '90%' } }
35
35
/>
36
- < Button
37
- title = "Liked Songs"
38
- style = { { width : '90%' , marginTop : 5 , marginBottom : 10 } }
39
- onPress = { ( ) => {
40
- router . push ( '/likedSongs' ) ;
36
+ < View
37
+ style = { {
38
+ flexDirection : 'row' ,
39
+ width : '90%' ,
40
+ gap : 5 ,
41
+ marginBottom : 3 ,
41
42
} }
42
- />
43
+ >
44
+ < Button
45
+ title = "Users"
46
+ style = { {
47
+ width : '49%' ,
48
+ borderWidth : queryTarget === 'users' ? 0 : 1 ,
49
+ borderColor : 'white' ,
50
+ } }
51
+ kind = { queryTarget === 'users' ? 'primary' : 'secondary' }
52
+ onPress = { ( ) => {
53
+ setQueryTarget ( 'users' ) ;
54
+ } }
55
+ />
56
+ < Button
57
+ title = "Songs"
58
+ style = { {
59
+ width : '49%' ,
60
+ borderWidth : queryTarget === 'songs' ? 0 : 1 ,
61
+ borderColor : 'white' ,
62
+ } }
63
+ kind = { queryTarget === 'songs' ? 'primary' : 'secondary' }
64
+ onPress = { ( ) => {
65
+ setQueryTarget ( 'songs' ) ;
66
+ } }
67
+ />
68
+ </ View >
43
69
< ScrollView style = { { width : '90%' , backgroundColor : 'black' } } >
44
70
{ searchResults . map ( ( song ) => {
45
71
return < TrackCard rawTrack = { song } key = { song . trackID } /> ;
0 commit comments