Skip to content

Commit 30f00d9

Browse files
committed
Extend search page to support users too
1 parent 9f10855 commit 30f00d9

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

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

+39-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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';
33
import { InputField } from '@/components/InputField';
44
import CurveTextHeader from '@/components/CurveTextHeader';
55
import { Button } from '@/components/Button';
@@ -11,35 +11,61 @@ import TrackCard from '@/components/TrackCard';
1111
export default function SearchScreen() {
1212
const [searchQuery, setSearchQuery] = useState('');
1313
const [searchResults, setSearchResults] = useState<Song[]>([]);
14-
15-
const router = useRouter();
14+
const [queryTarget, setQueryTarget] = useState<'users' | 'songs'>('songs');
1615

1716
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+
}
2021
};
2122

2223
const handleSearch = (query: string) => {
2324
setSearchQuery(query);
24-
updateSearchResults(query);
2525
};
2626

2727
return (
2828
<SafeAreaView style={styles.container}>
2929
<CurveTextHeader additionalStyles={{ borderBottomWidth: 0 }} />
3030
<InputField
3131
label=""
32-
placeholder="Search songs..."
32+
placeholder={`Search ${queryTarget}...`}
3333
onChange={handleSearch}
3434
style={{ marginTop: 10, width: '90%' }}
3535
/>
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,
4142
}}
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>
4369
<ScrollView style={{ width: '90%', backgroundColor: 'black' }}>
4470
{searchResults.map((song) => {
4571
return <TrackCard rawTrack={song} key={song.trackID} />;

0 commit comments

Comments
 (0)