Add: AddConversation
continuous-integration/drone/push Build is passing Details

peristanceBDD
Thomas Chazot 2 years ago
parent e2fb286b00
commit d016ed0589

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

@ -79,6 +79,18 @@ FC<{nav: any, state?: string}> =
</Pressable>
</View>
)
case 'addConversation':
return (
<View style={styles.header}>
<Pressable onPress={() => {nav.goBack()}}>
<Image source={cross} style={styles.icon}/>
</Pressable>
<Text style={styles.titre}>Chat with your friends</Text>
<Pressable>
<Image source={msc} style={styles.icon}/>
</Pressable>
</View>
)
default:
return (

@ -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() {
<ChatStack.Screen name="Chat" component={Chat} />
<ChatStack.Screen name="Settings" component={Settings} />
<ChatStack.Screen name="Conversation" component={Conversation} />
<ChatStack.Screen name="AddConversation" component={AddConversation} />
</ChatStack.Navigator>
);
}

@ -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<void>((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 (
<View style={stylesScreen.container}>
<View style={stylesScreen.bodyCenter}>
<TextInput style={styles.textInput} placeholder='Conversation name' onChangeText={(val) => setName(val)} autoCapitalize='none' />
<TextInput style={styles.textInput} placeholder="Players' id (separated by a comma)" onChangeText={(val) => setListId(val)} autoCapitalize='none'/>
<Pressable style={styles.button} onPress={() => handleCreateConv(name, listId)}>
<Text style={styles.text}>Add conversation</Text>
</Pressable>
</View>
</View>
)
}

@ -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 (
<View style={stylesScreen.container}>
@ -30,8 +30,8 @@ function Chat(props: { navigation: any; }) {
renderItem={({item}) => <ConversationPreviewComponent conv={item} navigation={navigation}/>}
/>
</View>
<Pressable onPress={() => navigation.navigate('Settings')}>
<Image source={cross} style={styles.icon}/>
<Pressable onPress={() => navigation.navigate('AddConversation')} style={{alignItems:"center", alignContent:"center"}}>
<Image source={add} style={styles.icon}/>
</Pressable>
<BotBar

@ -25,7 +25,6 @@ export default class LoaderGameApi implements ILoaderGame{
case "GameSolo":
let mapSolo = new Map();
for (let i=0; i<game.keys.length; i++){
console.log(game.keys[i], game.name);
mapSolo.set(new Number(game.keys[i]), new Number(game.values[i]))
}
tab.push(new GameSolo(game.id, game.name, game.image, game.nbPlayerMin, game.nbPlayerMax, mapSolo));

Loading…
Cancel
Save