Skip to content

Commit 7dccc6f

Browse files
committed
Added friend requests, and friends, made comments update in realtime
1 parent 4b7cb03 commit 7dccc6f

19 files changed

Lines changed: 664 additions & 160 deletions

app/(tabs)/friends.tsx

Lines changed: 0 additions & 47 deletions
This file was deleted.

app/(tabs)/friends/_layout.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// navigation
2+
import { Stack } from "expo-router";
3+
4+
export default function HomeLayout() {
5+
return (
6+
<Stack screenOptions={{ headerShown: false, contentStyle: { backgroundColor: "#17171d" } }}>
7+
<Stack.Screen name="index" options={{ contentStyle: { backgroundColor: "#17171d" } }} />
8+
</Stack >
9+
);
10+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { auth, db } from "@auth/firebase";
2+
import FriendRequest from "@components/containers/friendRequest";
3+
import CustomText from "@components/display/customText";
4+
import NothingHere from "@components/display/nothing";
5+
import OnlyIconButton from "@components/inputs/onlyIconButton";
6+
import { FlashList, ListRenderItemInfo } from "@shopify/flash-list";
7+
import { friendRequest } from "@utils/types";
8+
import { useRouter } from "expo-router";
9+
import { collection, onSnapshot } from "firebase/firestore";
10+
import { useEffect, useState } from "react";
11+
import { StyleSheet, View } from "react-native";
12+
import { useSafeAreaInsets } from "react-native-safe-area-context";
13+
14+
export default function FriendRequests() {
15+
const router = useRouter();
16+
const insets = useSafeAreaInsets();
17+
const currUser = auth.currentUser;
18+
const [requests, setRequests] = useState<friendRequest[]>([]);
19+
20+
useEffect(() => {
21+
const friendRequestSub = onSnapshot(collection(db, "users", currUser ? currUser.uid : "", "friendRequests"), (snap) => {
22+
const data: friendRequest[] = snap.docs.map(doc => (
23+
{
24+
id: doc.id,
25+
...(doc.data() as Omit<friendRequest, 'id'>)
26+
}
27+
));
28+
setRequests(data);
29+
30+
});
31+
}, [])
32+
33+
return (
34+
<View style={{ backgroundColor: "#17171d", flex: 1, paddingTop: insets.top, paddingBottom: 100, alignItems: "center" }}>
35+
<View style={{ flexDirection: "row", alignItems: "center", width: "100%", marginBottom: 20 }}>
36+
<OnlyIconButton icon="arrow-left" func={() => { router.back() }} style={{ top: 0, left: 20, zIndex: 5 }} />
37+
<CustomText style={{ color: "white", left: 50, fontSize: 18, top: 0, fontWeight: 700 }}>Friend Requests</CustomText>
38+
</View>
39+
<View style={styles.listContainer}>
40+
<FlashList
41+
data={requests}
42+
keyExtractor={item => item.id}
43+
ListEmptyComponent={<NothingHere />}
44+
renderItem={({ item }: ListRenderItemInfo<friendRequest>) => (
45+
<FriendRequest
46+
id={item.id}
47+
createdAt={item.createdAt}
48+
/>
49+
)
50+
}
51+
estimatedItemSize={100}
52+
/>
53+
</View>
54+
</View>
55+
);
56+
}
57+
58+
const styles = StyleSheet.create({
59+
listContainer: {
60+
width: '95%',
61+
marginVertical: 5,
62+
borderRadius: 12,
63+
borderWidth: StyleSheet.hairlineWidth,
64+
borderColor: "#444456ff",
65+
flex: 1,
66+
},
67+
text: {
68+
color: "white",
69+
fontSize: 15,
70+
},
71+
textValue: {
72+
color: "#8492a6",
73+
fontSize: 15,
74+
},
75+
heading: {
76+
color: "#8492a6",
77+
fontSize: 20,
78+
fontWeight: 700,
79+
marginVertical: 10,
80+
},
81+
field: {
82+
flexDirection: "row",
83+
justifyContent: "space-around",
84+
marginVertical: 10
85+
},
86+
section: {
87+
padding: 20,
88+
backgroundColor: "#25252f",
89+
borderWidth: 1,
90+
borderColor: "#17171d",
91+
width: "100%"
92+
}
93+
});

app/(tabs)/friends/index.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
});

app/(tabs)/home/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//components
22
import HomeHeader from "@components/containers/HomeHeader";
33
import PostList from "@components/display/postList";
4-
import { KeyboardAvoidingView, View } from "react-native";
4+
import { ActivityIndicator, KeyboardAvoidingView, View } from "react-native";
55
import { useSafeAreaInsets } from "react-native-safe-area-context";
66

77
//react
@@ -19,6 +19,13 @@ export default function HomeScreen() {
1919
Header={
2020
<View style={{ height: 20 + insets.top }}></View>
2121
}
22+
EmptyElement={
23+
<ActivityIndicator
24+
color={"#338eda"}
25+
style={{ marginTop: 70 }}
26+
/>
27+
28+
}
2229
/>
2330
</KeyboardAvoidingView>
2431
);

0 commit comments

Comments
 (0)