Skip to content

Commit e8f8837

Browse files
committed
Add search results for users to search page
1 parent fff9214 commit e8f8837

File tree

5 files changed

+58
-17
lines changed

5 files changed

+58
-17
lines changed

frontend/app/main/(tabs)/search.tsx

+57-9
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@ import { InputField } from '@/components/InputField';
44
import CurveTextHeader from '@/components/CurveTextHeader';
55
import { Button } from '@/components/Button';
66
import { useRouter } from 'expo-router';
7-
import { Song } from '@/types';
7+
import { Song, User } from '@/types';
88
import { getLikedSongs, searchSongs } from '@/services/songs';
99
import TrackCard from '@/components/TrackCard';
10+
import { searchUsers } from '@/services/user';
1011

1112
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[]>([]);
1415
const [queryTarget, setQueryTarget] = useState<'users' | 'songs'>('songs');
1516

1617
const updateSearchResults = async (query: string) => {
1718
if (queryTarget === 'songs') {
1819
const newSongs = await searchSongs(query);
19-
setSearchResults(newSongs);
20+
setSongSearchResults(newSongs);
21+
} else {
22+
const newUsers = await searchUsers(query);
23+
setUserSearchResults(newUsers);
2024
}
2125
};
2226

2327
const handleSearch = (query: string) => {
24-
setSearchQuery(query);
28+
updateSearchResults(query);
2529
};
2630

2731
return (
@@ -51,6 +55,7 @@ export default function SearchScreen() {
5155
kind={queryTarget === 'users' ? 'primary' : 'secondary'}
5256
onPress={() => {
5357
setQueryTarget('users');
58+
setSongSearchResults([]);
5459
}}
5560
/>
5661
<Button
@@ -63,18 +68,61 @@ export default function SearchScreen() {
6368
kind={queryTarget === 'songs' ? 'primary' : 'secondary'}
6469
onPress={() => {
6570
setQueryTarget('songs');
71+
setUserSearchResults([]);
6672
}}
6773
/>
6874
</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+
)}
7385
</ScrollView>
7486
</SafeAreaView>
7587
);
7688
}
7789

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+
78126
const styles = StyleSheet.create({
79127
container: {
80128
padding: 16,

frontend/app/playlists/[id].tsx

-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export default function PlaylistScreen() {
1616
useEffect(() => {
1717
const fetchPlaylist = async () => {
1818
const playlist = await getSpecificPlaylist(parseInt(id as string));
19-
console.log(playlist.songs);
2019
setPlaylist(playlist);
2120
};
2221
fetchPlaylist();
@@ -50,9 +49,7 @@ export default function PlaylistScreen() {
5049
</Text>
5150
</View>
5251

53-
{/* Songs List */}
5452
<View style={{ padding: 20, marginTop: -40 }}>
55-
{/* Placeholder song items */}
5653
{playlist.songs.map((song, idx) => (
5754
<SongItem key={idx} rawSong={song} idx={idx + 1} />
5855
))}
@@ -74,7 +71,6 @@ const SongItem = ({ rawSong, idx }: { rawSong: Song; idx: number }) => {
7471
rawSong.genre,
7572
accessToken!
7673
);
77-
console.log(song);
7874
setSong(song);
7975
};
8076
fetchSong();

frontend/services/playlist.ts

-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,5 @@ export const getSpecificPlaylist = async (id: number) => {
6464

6565
const data = await response.json();
6666

67-
console.log(data);
6867
return data as Playlist;
6968
};

frontend/services/spotify.ts

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export const hydrateTrackInfo = async (
1111
},
1212
});
1313

14-
console.log(response);
15-
1614
const data = await response.json();
1715

1816
const res = {

frontend/services/user.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const updateUser = async ({
3333
return [data.user, null];
3434
};
3535

36-
export const search = async (query: string): Promise<User[]> => {
36+
export const searchUsers = async (query: string): Promise<User[]> => {
3737
const response = await fetch(`${LOCAL_API_ENDPOINT}/user/search?q=${query}`);
3838

3939
const data = await response.json();

0 commit comments

Comments
 (0)