Drag and drop events trigger data updates which subsequently allow different components to render each with customized functionalities
Local authentication utilizing BCryptJS
Demo chat features
Drag and drop meeting items
Additional drop areas update your meeting items
Project Challenges
Updating Mongoose arrays are more complicated that other transactions
Utilizing alternative ways of rendering components (props.children) for use with React-DnD
Roomifying chat adds additional complexity to managing socket connections
Managing socket connections with reference to users also adds complexity
Finding an efficient way of integrating sockets into the redux-thunk data flow
Learning Takeaways
Mongoose does not have built in support for findOrCreate functions and requires an npm package
Socket event handlers can assist with dispatching actions to our Redux store.
// example socket flow // in our React component we define an event handler containing our thunkasynchandleCreateRoom(event){event.preventDefault();constroomName=this.state.roomName;constownerId=this.props.user._id;awaitthis.props.createRoom(roomName,ownerId);this.setState({roomName: ""});}// our thunk contains a socket.emit function which communicates with and sends// data to our serverexportconstcreateRoom=(roomName,ownerId)=>asyncdispatch=>{try{constdata={roomName, ownerId}constres=awaitaxios.post("/api/rooms",data);socket.emit(CREATE_ROOM,res.data)}catch(err){console.error(err);}};// our server side socket handlers receive the event and then send back the data // to be dispatched so that other users have the new datasocket.on('CREATE_ROOM',room=>{constownerId=room.owners[0]socket.emit('CREATE_ROOM',room)if(ownerIdinonlineUsers){socket.join(room._id)}})// finally our client side socket handles the received data and triggers our state updatesocket.on('CREATE_ROOM',room=>{store.dispatch(createdRoom(room))})
React-Dnd provides an api that allows us to define methods which will be called during drop events. These methods allow us to pass props to other components and to trigger methods defined in the drop components that can update state. A sample data flow involves the following. First a drag and drop-able item is defined which holds required data passed in as props along with a handler function which will be called during a drop event. This requires a thunk from our store and a handler function to call that. Then we can define the drop area.
constDropTarget=props=>{const[{ isOver, canDrop, item },drop]=useDrop({accept: ItemTypes.CARD,drop: ()=>{console.log("dropping an item!");handleDroppedItem(item.cardContent._id)},collect: mon=>({isOver: !!mon.isOver(),canDrop: !!mon.canDrop(),item: mon.getItem()})});consthandleDroppedItem=itemId=>{// dispatch an action that updates a meeting itemprops.setFocusItem(props.currentRoomId,itemId);};//....
Features - time permitting and stretch goals
Update UI library
Define additional drop zones to allow for more interaction such as changing item card status, prioritizing and ordering items, and deleting
Add data visualization options to apply onto meeting items
Connect drag and drop events to socket functions so that all users connected to room receive the updates
Refine socket connection management either through refactoring code or integrating with Mongo database
Add edit and delete options on users, friends, rooms, messages,
Add addtional messaging features such as typing notifications, time sent, sticker/smilies, and image uploads
Incorporate drag and resize components for more custom UI
Segment room and friend menus into individual tabs