@@ -4,24 +4,28 @@ import { InputField } from '@/components/InputField';
4
4
import CurveTextHeader from '@/components/CurveTextHeader' ;
5
5
import { Button } from '@/components/Button' ;
6
6
import { useRouter } from 'expo-router' ;
7
- import { Song } from '@/types' ;
7
+ import { Song , User } from '@/types' ;
8
8
import { getLikedSongs , searchSongs } from '@/services/songs' ;
9
9
import TrackCard from '@/components/TrackCard' ;
10
+ import { searchUsers } from '@/services/user' ;
10
11
11
12
export default function SearchScreen ( ) {
12
- const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
13
- const [ searchResults , setSearchResults ] = useState < Song [ ] > ( [ ] ) ;
13
+ const [ songSearchResults , setSongSearchResults ] = useState < Song [ ] > ( [ ] ) ;
14
+ const [ userSearchResults , setUserSearchResults ] = useState < User [ ] > ( [ ] ) ;
14
15
const [ queryTarget , setQueryTarget ] = useState < 'users' | 'songs' > ( 'songs' ) ;
15
16
16
17
const updateSearchResults = async ( query : string ) => {
17
18
if ( queryTarget === 'songs' ) {
18
19
const newSongs = await searchSongs ( query ) ;
19
- setSearchResults ( newSongs ) ;
20
+ setSongSearchResults ( newSongs ) ;
21
+ } else {
22
+ const newUsers = await searchUsers ( query ) ;
23
+ setUserSearchResults ( newUsers ) ;
20
24
}
21
25
} ;
22
26
23
27
const handleSearch = ( query : string ) => {
24
- setSearchQuery ( query ) ;
28
+ updateSearchResults ( query ) ;
25
29
} ;
26
30
27
31
return (
@@ -51,6 +55,7 @@ export default function SearchScreen() {
51
55
kind = { queryTarget === 'users' ? 'primary' : 'secondary' }
52
56
onPress = { ( ) => {
53
57
setQueryTarget ( 'users' ) ;
58
+ setSongSearchResults ( [ ] ) ;
54
59
} }
55
60
/>
56
61
< Button
@@ -63,18 +68,61 @@ export default function SearchScreen() {
63
68
kind = { queryTarget === 'songs' ? 'primary' : 'secondary' }
64
69
onPress = { ( ) => {
65
70
setQueryTarget ( 'songs' ) ;
71
+ setUserSearchResults ( [ ] ) ;
66
72
} }
67
73
/>
68
74
</ View >
69
- < ScrollView style = { { width : '90%' , backgroundColor : 'black' } } >
70
- { searchResults . map ( ( song ) => {
71
- return < TrackCard rawTrack = { song } key = { song . trackID } /> ;
72
- } ) }
75
+ < ScrollView
76
+ style = { { width : '95%' , backgroundColor : 'black' , marginTop : 20 } }
77
+ >
78
+ { queryTarget === 'songs' ? (
79
+ songSearchResults . map ( ( song ) => {
80
+ return < TrackCard rawTrack = { song } key = { song . trackID } /> ;
81
+ } )
82
+ ) : (
83
+ < UserListView users = { userSearchResults } />
84
+ ) }
73
85
</ ScrollView >
74
86
</ SafeAreaView >
75
87
) ;
76
88
}
77
89
90
+ const UserListView : React . FC < { users : User [ ] } > = ( { users } ) => {
91
+ return (
92
+ < >
93
+ { users . map ( ( user ) => {
94
+ return (
95
+ < View
96
+ style = { {
97
+ flexDirection : 'row' ,
98
+ padding : 12 ,
99
+ backgroundColor : '#1A1A1A' ,
100
+ borderRadius : 8 ,
101
+ alignItems : 'center' ,
102
+ marginVertical : 4 ,
103
+ marginHorizontal : 8 ,
104
+ marginBlock : 5 ,
105
+ borderWidth : 1 ,
106
+ borderColor : '#a568ff' ,
107
+ } }
108
+ >
109
+ < Text
110
+ key = { user . id }
111
+ style = { {
112
+ color : 'white' ,
113
+ fontFamily : 'LexendDeca_500Medium' ,
114
+ fontSize : 17 ,
115
+ } }
116
+ >
117
+ { user . username }
118
+ </ Text >
119
+ </ View >
120
+ ) ;
121
+ } ) }
122
+ </ >
123
+ ) ;
124
+ } ;
125
+
78
126
const styles = StyleSheet . create ( {
79
127
container : {
80
128
padding : 16 ,
0 commit comments