client/src/pages/Group.js
// Posts new message to DB then sends a new message alert for server to handle
Posts new message to DB then sends a new message alert for server to handle
Posts new message to DB then sends a new message alert for server to handle
function sendMessage(event) {
    let fullName = userState.first_name + " " + userState.last_name;
    let timeStamp = Date.now();
    console.log("Send Message Funciton");
    console.log(currentGroupState.name);
    if (formObject.message) {
      API.postMessage(
        {
          text: formObject.message,
          name: fullName,
          date: timeStamp,
        },
        currentGroupState.name
      )
        .then((res) => {
          setFormObject({});
          socket.current.emit("new message", {
            group: groupState._id,
            currentGroup: currentGroupState._id,
            currentGroupName: currentGroupState.name,
          });
          console.log(res.data);
          loadCurrentGroup(currentGroupState.name);
          scrollToBottom();
        })
        .catch((err) => console.log(err));
    }
  }
function sendMessage ( event ) { let fullName = userState . first_name + " " + userState . last_name ; let timeStamp = Date . now ( ) ; console . log ( "Send Message Funciton" ) ; console . log ( currentGroupState . name ) ; if ( formObject . message ) { API . postMessage ( { text : formObject . message , name : fullName , date : timeStamp , } , currentGroupState . name ) . then ( ( res ) => { setFormObject ( { } ) ; socket . current . emit ( "new message" , { group : groupState . _id , currentGroup : currentGroupState . _id , currentGroupName : currentGroupState . name , } ) ; console . log ( res . data ) ; loadCurrentGroup ( currentGroupState . name ) ; scrollToBottom ( ) ; } ) . catch ( ( err ) => console . log ( err ) ) ; } }
Posts new message to DB then sends a new message alert for server to handle
Posts new message to DB then sends a new message alert for server to handle
// event.preventDefault(); //event.target.reset();