diff --git a/bob_party/assets/Icons/UnSelected/Add.png b/bob_party/assets/Icons/UnSelected/Add.png new file mode 100644 index 0000000..f2b7273 Binary files /dev/null and b/bob_party/assets/Icons/UnSelected/Add.png differ diff --git a/bob_party/src/components/TopBar.tsx b/bob_party/src/components/TopBar.tsx index 48059b8..26da7d5 100644 --- a/bob_party/src/components/TopBar.tsx +++ b/bob_party/src/components/TopBar.tsx @@ -79,6 +79,18 @@ FC<{nav: any, state?: string}> = ) + case 'addConversation': + return ( + + {nav.goBack()}}> + + + Chat with your friends + + + + + ) default: return ( diff --git a/bob_party/src/navigation/AppNavigator.tsx b/bob_party/src/navigation/AppNavigator.tsx index b066ad7..8726749 100644 --- a/bob_party/src/navigation/AppNavigator.tsx +++ b/bob_party/src/navigation/AppNavigator.tsx @@ -15,6 +15,7 @@ import SignUp from '../screens/SignUp' import LobbySolo from '../screens/LobbySolo' import CookieClicker from '../Games/CookieClicker/cookieClicker' import Conversation from '../screens/ConversationScreen' +import AddConversation from '../screens/AddConversation' import TicTacToe from '../Games/Tic-Tac-Toe/tic_tac_toe' @@ -60,6 +61,7 @@ function ChatStackScreen() { + ); } diff --git a/bob_party/src/screens/AddConversation.tsx b/bob_party/src/screens/AddConversation.tsx new file mode 100644 index 0000000..a4d3560 --- /dev/null +++ b/bob_party/src/screens/AddConversation.tsx @@ -0,0 +1,80 @@ +import { Pressable, TextInput, View, Text, Alert } from "react-native"; +import styles from "./style/SignIn.style"; +import stylesScreen from './style/screens.style' +import { useState } from "react"; +import React from "react"; +import { MANAGER_CONVERSATION, MANAGER_USER } from "../../appManagers"; +import { resolvePreset } from "@babel/core"; +import { useConversationStore } from "../context/conversationContext"; +import { socket } from "../../socketConfig"; + +export default function AddConversation(props: {navigation:any}){ + const {navigation}=props; + const [name, setName] = useState(''); + const [listId, setListId] = useState(''); + + const setTabConv = useConversationStore((state) => state.setTabConv); + + + async function handleCreateConv(name: string, listId: string){ + if (name.trim().length === 0){ + Alert.alert("Everyone needs a name even a conversation :)"); + return; + } + if (listId.trim().length === 0){ + Alert.alert("Specify the id of your friends to chat with them :)"); + return; + } + listId = listId.replace(/\s+/g, ''); + const tabId= listId.split(',').map(function(item) { + return parseInt(item, 10); + }); + let length=0; + let end=new Promise((resolve, reject) => { + tabId.forEach(async id =>{ + if (isNaN(id)){ + Alert.alert("The id must only be numbers"); + return; + } + if (id===MANAGER_USER.getCurrentUser()?.getId()){ + Alert.alert("You can't be part of the conversation 2 times :("); + return; + } + let us=await MANAGER_USER.getLoaderUser().loadByID(id).then((res)=>{ + if (res===null){ + Alert.alert("The id: " + id + " doesn't exist"); + return; + } + length++; + if (length==tabId.length){ + resolve(); + } + }); + }); + }); + await Promise.all([end]); + const tmp=MANAGER_USER.getCurrentUser(); + if (tmp!==null){ + await MANAGER_CONVERSATION.getsaverConversation().saveConversation(name, tmp, tabId, tmp.getUsername() + " created a conversation", new Date()).then((res)=>{ + if (res!==null){ + MANAGER_CONVERSATION.getTabConv().push(res); + setTabConv(MANAGER_CONVERSATION.getTabConv()); + socket.emit("messageSent", res); + navigation.goBack(); + } + }); + } + } + + return ( + + + setName(val)} autoCapitalize='none' /> + setListId(val)} autoCapitalize='none'/> + handleCreateConv(name, listId)}> + Add conversation + + + + ) +} \ No newline at end of file diff --git a/bob_party/src/screens/Chat.tsx b/bob_party/src/screens/Chat.tsx index 58e7c96..2fd579e 100644 --- a/bob_party/src/screens/Chat.tsx +++ b/bob_party/src/screens/Chat.tsx @@ -16,7 +16,7 @@ import styles from '../components/style/TopBar.style'; function Chat(props: { navigation: any; }) { const { navigation } = props - const cross = require('../../assets/Icons/UnSelected/Cross.png'); + const add = require('../../assets/Icons/UnSelected/Add.png'); return ( @@ -30,8 +30,8 @@ function Chat(props: { navigation: any; }) { renderItem={({item}) => } /> - navigation.navigate('Settings')}> - + navigation.navigate('AddConversation')} style={{alignItems:"center", alignContent:"center"}}> +