Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion src/app/(app)/(tabs)/contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from "reactfire";
import ConfettiCannon from "react-native-confetti-cannon";
import { z } from "zod";
import { RectButton, Swipeable } from "react-native-gesture-handler";

export default function ContactScreen() {
const { currentUser } = useAuth();
Expand All @@ -46,6 +47,11 @@ export default function ContactScreen() {
}

const firestore = useFirestore();
const deleteContact = async (contactId: string) => {
const updatedContacts = userData.contacts.filter((id) => id !== contactId);
await updateDoc(userDoc, { contacts: updatedContacts });
};

const userDoc = doc(
firestore,
"users",
Expand Down Expand Up @@ -237,9 +243,15 @@ export default function ContactScreen() {
<FlatList
style={styles.container}
data={userData.contacts}
renderItem={({ item }) => <ContactItem userId={item} />}
renderItem={({ item }) => (
<SwipeableContactItem
userId={item}
onDelete={() => deleteContact(item)}
/>
)}
keyExtractor={(item) => item}
/>

<FAB.Group
open={open}
visible
Expand All @@ -262,6 +274,31 @@ export default function ContactScreen() {
);
}

const SwipeableContactItem = ({
userId,
onDelete,
}: {
userId: string;
onDelete: () => void;
}) => {
const renderRightActions = () => (
<RectButton
style={styles.deleteButton}
onPress={() => {
onDelete();
}}
>
<FAB icon="delete" style={{ backgroundColor: "#6e0000" }} />
</RectButton>
);

return (
<Swipeable renderRightActions={renderRightActions}>
<ContactItem userId={userId} />
</Swipeable>
);
};

function ContactItem({ userId }: { userId: string }) {
const firestore = useFirestore();
const { currentUser } = useAuth();
Expand Down Expand Up @@ -348,4 +385,9 @@ const styles = StyleSheet.create({
paddingVertical: 10,
paddingHorizontal: "2%",
},
deleteButton: {
width: 80,
justifyContent: "center",
alignItems: "center",
},
});
45 changes: 43 additions & 2 deletions src/app/(app)/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Message, Room } from "@/types";
import { Link } from "expo-router";
import {
CollectionReference,
Timestamp,
collection,
doc,
limit,
Expand All @@ -15,6 +16,7 @@ import { View, StyleSheet, FlatList } from "react-native";
import {
ActivityIndicator,
Avatar,
FAB,
Text,
TouchableRipple,
} from "react-native-paper";
Expand All @@ -24,12 +26,14 @@ import {
useFirestoreCollectionData,
useFirestoreDocData,
} from "reactfire";
import { RectButton, Swipeable } from "react-native-gesture-handler";

export default function IndexScreen() {
const { currentUser } = useAuth();
if (!currentUser) return null;

const firestore = useFirestore();
const deleteChat = async (contactId: string) => {};
const roomsCol = collection(firestore, "rooms") as CollectionReference<Room>;
const myRoomsQuery = query(
roomsCol,
Expand All @@ -49,13 +53,42 @@ export default function IndexScreen() {
return (
<FlatList
data={myRooms}
renderItem={({ item }) => <ChatItem room={item} />}
keyExtractor={(item) => item.id!}
renderItem={({ item }) => (
<>
<SwipeableChatItem
onDelete={() => deleteChat(item.id || "")}
userId={""}
/>
<ChatItem room={item} />
</>
)}
keyExtractor={(item) => item.id || "defaultKey"}
style={styles.container}
/>
);
}

const SwipeableChatItem = ({
userId,
onDelete,
}: {
userId: string;
onDelete: () => void;
}) => {
const renderRightActions = () => (
<RectButton
style={styles.deleteButton}
onPress={() => {
onDelete();
}}
>
<FAB icon="delete" style={{ backgroundColor: "#6e0000" }} />
</RectButton>
);

return <Swipeable renderRightActions={renderRightActions}></Swipeable>;
};

function ChatItem({ room }: { room: Room }) {
if (!room) return null;
const firestore = useFirestore();
Expand Down Expand Up @@ -187,4 +220,12 @@ const styles = StyleSheet.create({
messageContainer: {
flexDirection: "row",
},
deleteButton: {
width: 80,
justifyContent: "center",
alignItems: "center",
},
swipeableChatItem: {
backgroundColor: "white",
},
});