1+ //components
2+ import FriendBox from "@components/containers/friend" ;
3+ import CustomText from "@components/display/customText" ;
4+ import InputBox from "@components/inputs/inptField" ;
5+ import OnlyIconButton from "@components/inputs/onlyIconButton" ;
6+ import { FlashList , ListRenderItemInfo } from "@shopify/flash-list" ;
7+ import { StyleSheet , View } from "react-native" ;
8+
9+ //react
10+ import { useEffect , useState } from "react" ;
11+
12+ //typecasting
13+ import { auth , db } from "@auth/firebase" ;
14+ import NothingHere from "@components/display/nothing" ;
15+ import { friend } from "@utils/types" ;
16+ import { useRouter } from "expo-router" ;
17+ import { collection , onSnapshot } from "firebase/firestore" ;
18+
19+
20+
21+ export default function FriendsScreen ( ) {
22+ const [ search , setSearch ] = useState ( "" ) ;
23+
24+ const router = useRouter ( )
25+ const currUser = auth . currentUser ;
26+ const [ friends , setFriends ] = useState < friend [ ] > ( ) ;
27+
28+ useEffect ( ( ) => {
29+ const friendSub = onSnapshot ( collection ( db , "users" , currUser ? currUser . uid : "" , "friends" ) , ( snap ) => {
30+ const data : friend [ ] = snap . docs . map ( doc => (
31+ {
32+ id : doc . id ,
33+ ...( doc . data ( ) as Omit < friend , 'id' > )
34+ }
35+ ) ) ;
36+ console . log ( data , "contains all friends" )
37+ setFriends ( data ) ;
38+
39+ } ) ;
40+ } , [ ] )
41+ return (
42+ < View style = { { backgroundColor : "#17171d" , flex : 1 , paddingTop : 50 , paddingBottom : 100 , alignItems : "center" } } >
43+ < View style = { { flexDirection : "row" , alignItems : "center" , width : "100%" } } >
44+ < CustomText style = { { color : "white" , fontSize : 20 , textAlign : "center" , fontWeight : "bold" , marginVertical : 10 , marginLeft : "10%" } } > Your Friends</ CustomText >
45+ < OnlyIconButton
46+ icon = "account-plus-outline"
47+ func = { ( ) => { router . push ( "/(tabs)/friends/friendRequests" ) } }
48+ style = { { marginLeft : "auto" , marginRight : 30 } }
49+ />
50+ </ View >
51+
52+ < InputBox secure = { false } value = { search } valueFn = { setSearch } color = "white" icon = "magnify" type = "none" placeholder = "Search your friends here" />
53+ < View style = { styles . listContainer } >
54+ < FlashList
55+ data = { friends }
56+ keyExtractor = { item => item . id }
57+ ListEmptyComponent = { < NothingHere /> }
58+ renderItem = { ( { item } : ListRenderItemInfo < friend > ) => (
59+ // <CustomText>{item.id}</CustomText>
60+ < FriendBox
61+ id = { item . id }
62+ createdAt = { item . createdAt }
63+ />
64+ )
65+ }
66+ estimatedItemSize = { 100 }
67+ />
68+
69+ </ View >
70+ </ View >
71+ ) ;
72+ }
73+
74+ const styles = StyleSheet . create ( {
75+ listContainer : {
76+ width : '95%' ,
77+ marginVertical : 25 ,
78+ borderRadius : 12 ,
79+ borderWidth : StyleSheet . hairlineWidth ,
80+ borderColor : "#444456ff" ,
81+ flex : 1
82+ }
83+
84+ } ) ;
0 commit comments