Skip to content

Commit

Permalink
Add ability to view friends (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Advayp authored Feb 24, 2025
1 parent 70aa535 commit 72746a3
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 89 deletions.
14 changes: 14 additions & 0 deletions frontend/app/main/(tabs)/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { useRouter } from 'expo-router';
import { AccountSettingsModal } from '@/components/AccountSettingsModal';
import { logout } from '@/services/auth/logout';
import FriendRequestModal from '@/components/FriendRequestModal';
import FriendViewModal from '@/components/FriendViewModal';
import { Ionicons } from '@expo/vector-icons';

const Profile = () => {
const { user, error, isLoading, fetchUser } = useAuth();
Expand All @@ -33,6 +35,8 @@ const Profile = () => {
const [isFriendRequestModalVisible, setIsFriendRequestModalVisible] =
useState(false);

const [isFriendsModalVisible, setIsFriendsModalVisible] = useState(false);

useEffect(() => {
fetchGenres();
}, []);
Expand Down Expand Up @@ -165,6 +169,16 @@ const Profile = () => {
onClose={() => setIsFriendRequestModalVisible(false)}
visible={isFriendRequestModalVisible}
/>
<TouchableOpacity
style={{ position: 'absolute', top: 50, left: 30 }}
onPress={() => setIsFriendsModalVisible(true)}
>
<Ionicons name="people-outline" size={24} color="white" />
</TouchableOpacity>
<FriendViewModal
visible={isFriendsModalVisible}
onClose={() => setIsFriendsModalVisible(false)}
/>
</SafeAreaView>
);
};
Expand Down
57 changes: 5 additions & 52 deletions frontend/app/main/(tabs)/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AntDesign } from '@expo/vector-icons';
import { useAuth } from '@/hooks/useAuth';
import { sendFriendRequest } from '@/services/friendRequests';
import Toast from 'react-native-toast-message';
import { UserView } from '@/components/UserView';

export default function SearchScreen() {
const [songSearchResults, setSongSearchResults] = useState<Song[]>([]);
Expand Down Expand Up @@ -119,59 +120,11 @@ const UserListView: React.FC<{
.filter((value) => value.id !== currentUserId)
.map((user) => {
return (
<View
style={{
flexDirection: 'row',
padding: 12,
backgroundColor: '#1A1A1A',
borderRadius: 8,
alignItems: 'center',
marginVertical: 4,
marginHorizontal: 8,
marginBlock: 5,
gap: 15,
justifyContent: 'space-between',
}}
<UserView
key={user.id}
>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
gap: 15,
}}
>
<Image
source={{ uri: user.profilePictureURL }}
style={{
width: 40,
height: 40,
borderRadius: '50%',
borderWidth: 3,
borderColor: '#a568ff',
}}
/>
<Text
style={{
color: 'white',
fontFamily: 'LexendDeca_500Medium',
fontSize: 17,
}}
>
{user.username}
</Text>
</View>
<TouchableOpacity
style={{
marginRight: 10,
}}
onPress={() => {
handleFriendRequest(user.id);
}}
>
<AntDesign name="adduser" size={22} color="white" />
</TouchableOpacity>
</View>
user={user}
handleFriendRequest={handleFriendRequest}
/>
);
})}
</>
Expand Down
62 changes: 32 additions & 30 deletions frontend/components/FriendRequestModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
View,
Text,
TouchableOpacity,
FlatList,
StyleSheet,
Image,
ScrollView,
} from 'react-native';

interface FriendRequestModalProps {
Expand Down Expand Up @@ -51,36 +51,38 @@ const FriendRequestModal: React.FC<FriendRequestModalProps> = ({
<View style={styles.modalView}>
<Text style={styles.modalText}>Friend Requests</Text>
<View style={styles.horizontalLine} />
{friendRequests.map((item) => (
<View style={styles.requestItem} key={item.id}>
<View style={styles.profileView}>
<Image
source={{ uri: item.from.profilePictureURL }}
style={{
width: 30,
height: 30,
borderRadius: '50%',
marginRight: 5,
}}
/>
<Text style={styles.requestText}>{item.from.username}</Text>
<ScrollView>
{friendRequests.map((item) => (
<View style={styles.requestItem} key={item.id}>
<View style={styles.profileView}>
<Image
source={{ uri: item.from.profilePictureURL }}
style={{
width: 30,
height: 30,
borderRadius: '50%',
marginRight: 5,
}}
/>
<Text style={styles.requestText}>{item.from.username}</Text>
</View>
<View style={[styles.buttonContainer, { marginLeft: 30 }]}>
<TouchableOpacity
style={[styles.button]}
onPress={() => handleFriendRequest(item.id, 'accept')}
>
<Ionicons name="checkmark" size={20} color="#a568ff" />
</TouchableOpacity>
<TouchableOpacity
style={[styles.button]}
onPress={() => handleFriendRequest(item.id, 'decline')}
>
<Ionicons name="close" size={20} color="#a568ff" />
</TouchableOpacity>
</View>
</View>
<View style={[styles.buttonContainer, { marginLeft: 30 }]}>
<TouchableOpacity
style={[styles.button]}
onPress={() => handleFriendRequest(item.id, 'accept')}
>
<Ionicons name="checkmark" size={20} color="#a568ff" />
</TouchableOpacity>
<TouchableOpacity
style={[styles.button]}
onPress={() => handleFriendRequest(item.id, 'decline')}
>
<Ionicons name="close" size={20} color="#a568ff" />
</TouchableOpacity>
</View>
</View>
))}
))}
</ScrollView>
<TouchableOpacity
style={[styles.button, styles.buttonClose, { padding: 10 }]}
onPress={onClose}
Expand Down
178 changes: 178 additions & 0 deletions frontend/components/FriendViewModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import { useFeed } from '@/hooks/useFeed';
import {
getFriendRequests,
handleFriendRequest,
} from '@/services/friendRequests';
import { FriendRequest } from '@/types';
import { AntDesign, Ionicons } from '@expo/vector-icons';
import React, { useEffect, useState } from 'react';
import {
Modal,
View,
Text,
TouchableOpacity,
StyleSheet,
Image,
ScrollView,
} from 'react-native';

interface FriendRequestModalProps {
visible: boolean;
onClose: () => void;
}

const FriendViewModal: React.FC<FriendRequestModalProps> = ({
visible,
onClose,
}) => {
const { friends } = useFeed();

return (
<Modal
animationType="slide"
transparent={true}
visible={visible}
onRequestClose={onClose}
>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<Text style={styles.modalText}>Friends</Text>
<View style={styles.horizontalLine} />
<ScrollView>
{friends.map((user) => (
<View
style={{
flexDirection: 'row',
padding: 12,
backgroundColor: '#1A1A1A',
borderRadius: 8,
alignItems: 'center',
marginVertical: 4,
marginHorizontal: 8,
marginBlock: 5,
gap: 15,
justifyContent: 'space-between',
}}
key={user.id}
>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
gap: 15,
}}
>
<Image
source={{ uri: user.profilePictureURL }}
style={{
width: 40,
height: 40,
borderRadius: '50%',
borderWidth: 3,
borderColor: '#a568ff',
}}
/>
<Text
style={{
color: 'white',
fontFamily: 'LexendDeca_500Medium',
fontSize: 17,
}}
>
{user.username}
</Text>
</View>
</View>
))}
</ScrollView>
<TouchableOpacity
style={[styles.button, styles.buttonClose, { padding: 10 }]}
onPress={onClose}
>
<Text style={styles.textStyle}>Close</Text>
</TouchableOpacity>
</View>
</View>
</Modal>
);
};

const styles = StyleSheet.create({
centeredView: {
justifyContent: 'center',
alignItems: 'center',
marginTop: 22,
},
modalView: {
margin: 20,
backgroundColor: 'black',
borderRadius: 20,
padding: 35,
alignItems: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
height: '70%',
width: '70%',
borderColor: '#eee',
borderWidth: 1,
},
buttonContainer: {
flexDirection: 'row',
width: '100%',
},
button: {
borderRadius: 20,
elevation: 2,
},
buttonClose: {
backgroundColor: '#a568ff',
marginTop: 15,
},
textStyle: {
color: 'white',
fontWeight: 'bold',
textAlign: 'center',
},
modalText: {
textAlign: 'center',
fontSize: 20,
fontWeight: 'bold',
fontFamily: 'LexendDeca_500Semibold',
color: 'white',
},
requestItem: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 10,
width: '100%',
backgroundColor: '#2b2b2b',
padding: 5,
borderRadius: 10,
},
requestText: {
fontSize: 15,
color: 'white',
fontFamily: 'LexendDeca_400Regular',
},
profileView: {
flexDirection: 'row',
alignItems: 'center',
gap: 2,
},
horizontalLine: {
borderBottomColor: '#a568ff',
borderBottomWidth: 1,
width: '100%',
marginVertical: 10,
marginBottom: 15,
},
});

export default FriendViewModal;
Loading

0 comments on commit 72746a3

Please sign in to comment.