Skip to content

Commit

Permalink
GroupCreation
Browse files Browse the repository at this point in the history
  • Loading branch information
PriyanshuDas01 committed Oct 14, 2024
1 parent 68da3d2 commit 8c54654
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 9 deletions.
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name=".MainApplication"
Expand Down
296 changes: 296 additions & 0 deletions components/groupCreate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
import React, { useState, useEffect } from 'react';
import { View, Text, TextInput, FlatList, Image, TouchableOpacity, StyleSheet, Dimensions, StatusBar, Alert } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome5';
import { NavigationProp, RouteProp } from '@react-navigation/native';
import { launchImageLibrary } from 'react-native-image-picker';

const { width } = Dimensions.get('window');

// Sample user data (the creator of the group)
const sampleUser = {
id: "0",
name: "Me",
email: "[email protected]",
avatar: "https://via.placeholder.com/50",
};

// Sample contacts data
const sampleContacts = [
{
id: "1",
name: "Jane Smith",
email: "[email protected]",
avatar: "https://via.placeholder.com/50",
},
{
id: "2",
name: "Alice Johnson",
email: "[email protected]",
avatar: "https://via.placeholder.com/50",
},
{
id: "3",
name: "Bob Brown",
email: "[email protected]",
avatar: "https://via.placeholder.com/50",
},
];

export default function GroupComponent({ navigation, route }: { navigation: NavigationProp<any>, route: RouteProp<any> }) {
const [groupName, setGroupName] = useState('');
const [contacts, setContacts] = useState(sampleContacts); // Sample contacts data
const [selectedContacts, setSelectedContacts] = useState<any[]>([]); // State for selected contacts
const [groupImage, setGroupImage] = useState<string>('https://via.placeholder.com/100'); // Default group image


// ...............................................Group>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

useEffect(() => {
setSelectedContacts([sampleUser]);
}, []);

// Handle contact selection
const handleSelectContact = (contact: any) => {
setSelectedContacts([...selectedContacts, contact]);
setContacts(contacts.filter((c) => c.id !== contact.id)); // Remove the selected contact from the contacts list
};

// Handle removing selected contact
const handleRemoveContact = (contact: any) => {
if (contact.id === sampleUser.id) {
return; // Don't allow removing the user (creator) from the selected contacts
}
setSelectedContacts(selectedContacts.filter((c) => c.id !== contact.id)); // Remove contact from selected
setContacts([...contacts, contact]); // Add contact back to the contacts list
};

const handleSelectImage = () => {
launchImageLibrary(
{
mediaType: 'photo',
includeBase64: false,
quality: 1,
},
(response) => {
// Check if user canceled the picker
if (response.didCancel) {
console.log('User cancelled image picker');
return;
}

// Check for any errors in response
if (response.errorCode) {
console.log('ImagePicker Error: ', response.errorMessage); // Log error message
return;
}

// Check if assets are available and set the image
if (response.assets && response.assets.length > 0) {
const source = response.assets[0].uri; // Get the image URI
if (source) {
setGroupImage(source); // Set the selected image
}
}
}
);
};

// ...........................................................Group Cretion ........................

// Handle group creation
const handleCreateGroup = () => {
if (!groupName.trim()) {
Alert.alert('Group Creation', 'Please enter a group name.');
return;
}
if (selectedContacts.length < 2) {
Alert.alert('Group Creation', 'You need to select at least 1 person to create a group.');
return;
}
console.log('Group created with:', groupName, groupImage, selectedContacts);
// Add group creation logic here
setGroupName(''); // Reset group name
setGroupImage('https://via.placeholder.com/100');
setSelectedContacts([sampleUser]);
setContacts(sampleContacts);
};

// Render contacts list
const renderContact = ({ item }: { item: any }) => (
<TouchableOpacity style={styles.contactItem} onPress={() => handleSelectContact(item)}>
<Image source={{ uri: item.avatar || 'https://via.placeholder.com/50' }} style={styles.avatar} />
<Text style={styles.contactName}>{item.name}</Text>
</TouchableOpacity>
);

// Render selected contacts list (name below image)
const renderSelectedContact = ({ item }: { item: any }) => (
<TouchableOpacity style={styles.selectedContactItem} onPress={() => handleRemoveContact(item)}>
<Image source={{ uri: item.avatar || 'https://via.placeholder.com/50' }} style={styles.avatarSmall} />
<Text style={styles.selectedContactName}>{item.name}</Text>
{item.id !== sampleUser.id && (
<Icon name="times" size={16} color="#fff" style={styles.removeIcon} />
)}
</TouchableOpacity>
);

return (
<View style={styles.container}>
<StatusBar barStyle="light-content" />
<Text style={styles.title}>Create Group</Text>

{/* Group Image Selection */}
<TouchableOpacity onPress={handleSelectImage}>
<Image source={{ uri: groupImage }} style={styles.groupIcon} />
<Text style={styles.changeIconText}>+ Add Group Icon </Text>
</TouchableOpacity>

{/* Group Name Input */}
<TextInput
style={styles.input}
placeholder="Group Name"
placeholderTextColor="#999"
value={groupName}
onChangeText={setGroupName}
/>

{/* Selected Contacts */}
{selectedContacts.length > 1 && (
<>
<Text style={styles.subtitle}>Create group with...</Text>
<FlatList
data={selectedContacts}
renderItem={renderSelectedContact}
keyExtractor={(item) => item.email}
horizontal
style={styles.selectedContactList}
/>
</>
)}

{/* Select Contacts */}
<Text style={styles.subtitle}>Select Contacts</Text>
<FlatList
data={contacts}
renderItem={renderContact}
keyExtractor={(item) => item.email}
style={styles.contactList}
/>

{/* Create Group Button */}
<TouchableOpacity style={styles.createGroupButton} onPress={handleCreateGroup}>
<Icon name="arrow-right" size={20} color="#fff" />
</TouchableOpacity>
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#1e1e1e',
paddingHorizontal: 20,
paddingTop: 20,
},
title: {
fontSize: 28,
color: '#fff',
textAlign: 'center',
marginBottom: 20,
fontWeight: '500',
},
subtitle: {
fontSize: 18,
color: '#bbb',
marginBottom: 10,
fontWeight: '500',
},
input: {
backgroundColor: 'rgba(51, 51, 51, 0.7)',
color: '#fff',
padding: 15,
borderRadius: 10,
marginBottom: 20,
fontWeight: '900',
},
groupIcon: {
width: 70,
height: 70,
borderRadius: 50,
alignSelf: 'center',
marginBottom: 10,
},
changeIconText: {
color: '#DD651B',
textAlign: 'center',
marginBottom: 20,
fontWeight:'600',
},
contactList: {
flexGrow: 0,
marginBottom: 20,
},
contactItem: {
padding: 15,
borderRadius: 10,
marginBottom: 10,
flexDirection: 'row',
alignItems: 'center',
},
avatar: {
width: 40,
height: 40,
borderRadius: 25,
marginRight: 12,
},
avatarSmall: {
width: 40,
height: 40,
borderRadius: 20,
marginBottom: 8,
},
contactName: {
color: '#fff',
fontSize: 18,
fontWeight: '700',
},
selectedContactItem: {
backgroundColor: '#333',
padding: 10,
borderRadius: 20,
marginRight: 10,
alignItems: 'center',
width: 80,
},
selectedContactList: {
marginBottom: 20,
flexGrow: 0,
},
selectedContactName: {
color: '#fff',
fontSize: 14,
fontWeight: '700',
textAlign: 'center',
},
removeIcon: {
position: 'absolute',
top: 0,
right: 0,
},
createGroupButton: {
position: 'absolute',
bottom: 40,
right: 20,
width: 60,
height: 60,
borderRadius: 30,
backgroundColor: '#DD651B',
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#000',
shadowOffset: { width: 0, height: 5 },
shadowOpacity: 0.3,
shadowRadius: 4,
elevation: 5,
},
});
8 changes: 8 additions & 0 deletions ios/adf/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
<key>NSMicrophoneUsageDescription</key>
<string>We need to use the microphone</string>

<!-- ............................added for image selection;; -->

<key>NSCameraUsageDescription</key>
<string>Your message to explain why you need camera access</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Your message to explain why you need photo library access</string>
<!-- ............................................................................................. -->

<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
Expand Down
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"@react-native-async-storage/async-storage": "^2.0.0",
"@react-navigation/native": "^6.1.18",
"@react-navigation/native-stack": "^6.11.0",
"@zegocloud/zego-uikit-prebuilt-call-rn": "^6.0.2",
"@zegocloud/zego-uikit-rn": "^2.14.7",
"@stablelib/base64": "^2.0.0",
"@stablelib/utf8": "^2.0.0",
"@zegocloud/zego-uikit-prebuilt-call-rn": "^6.0.2",
"@zegocloud/zego-uikit-rn": "^2.14.7",
"convex": "^1.16.4",
"convex-ents": "^0.11.0",
"convex-helpers": "^0.1.60",
Expand All @@ -28,22 +28,20 @@
"react-dom": "^18.3.1",
"react-native": "0.75.4",
"react-native-async-storage": "^0.0.1",

"react-native-device-info": "^13.1.0",
"react-native-encrypted-storage": "^4.0.3",
"react-native-keep-awake": "^4.0.0",
"react-native-sound": "^0.11.2",

"react-native-gesture-handler": "^2.20.0",
"react-native-get-random-values": "^1.11.0",
"react-native-image-picker": "^7.1.2",
"react-native-keep-awake": "^4.0.0",
"react-native-linear-gradient": "^2.8.3",
"react-native-paper": "^5.12.5",
"react-native-reanimated": "^3.15.5",
"react-native-safe-area-context": "^4.11.0",
"react-native-screens": "^3.34.0",
"react-native-securerandom": "^1.0.1",
"react-native-sound": "^0.11.2",
"react-native-vector-icons": "^10.2.0",

"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1",
"twrnc": "^4.5.1",
Expand All @@ -63,11 +61,11 @@
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"jest": "^29.6.3",
"metro-config": "^0.80.12",
"prettier": "2.8.8",
"react-native-dotenv": "^3.4.11",
"react-test-renderer": "18.3.1",
"typescript": "5.0.4",
"metro-config": "^0.80.12"
"typescript": "5.0.4"
},
"engines": {
"node": ">=18"
Expand Down

0 comments on commit 8c54654

Please sign in to comment.