Giter Club home page Giter Club logo

chat-app-using-reactjs's Introduction

React_Chat_App

Demo :

chapp app demo link to youtube

Few notes on creating this App:

• Create a dummy messgalist.js for test purpose
• Signup and login to Create a Chatkit instance and provide them in the config.js and import them to App.js
• Create a ChatKit Manager instance with the below code in 'ComponentDidMount' function
	const chatManager = new Chatkit.chatManager({
		instanceLocator:instanceLocator,
		userId : "Saranya",
		tokenProvider: new Chatkit.TokenProvider({
            url: tokenUrl
        })
	})
	
• Create a test user and test room in chatkit instance and programatically connect using the below code,
        chatManager.connect()
        .then(currentUser => {
            currentUser.subscribeToRoom({
                roomId: '19544441',
                hooks: {
                    onMessage: message => {
                        console.log('message.text: ', message.text);
                    }
                }
            })
        })
• Now setState for the new messages being logged and pass this to the main App.js as message list
• Convert the messages in the chatroom into a messagelist using setState
                        localMessageData.push(
                            {"senderId" : message.senderId,
                            "text" : message.text
                            }   
                        )
                        this.setState({
                           messageList : localMessageData
                       })


• Send this messaglist to Messagelist.js to render in UI
• Separate the messages into Message.js component and call it from MessageList.js file
• Add a SendMessageForm component with a simple form element with input text box and add this to App.js. OnChange the value of this controlled component setState will set the value typed in the input box and and OnSubmit this value will be sent to ChatKit server
• Make the currentUser in the chatKit connect function a global one by assigning it to this.currentUser
• Add below function to a another method in App.JS and pass this method as props to SendUserForm to get the value from submiting the form
        this.currentUser.sendMessage(
            {
                text:message,
                roomId : '19544441'
            }
        )
• Create RoomList.js which ll accept rooms (joinable rooms and already joined rooms) as array from App.js and use map method to display each room to the RoomList panel
• From App.js get the rooms of the current chat instance by below code,
            this.currentUser.getJoinableRooms()
            .then(joinableRooms=>{
                this.setState({
                    joinableRooms : joinableRooms,
                    joinedRooms : this.currentUser.rooms
                })
            })

• Now separate the subscribe to room list and pass this to RoomList.js as props to get the room id while clicking on a particular room
• Since joinable rooms and joined rooms keep getting shuffled as the user clicks the room, to order the rooms list, use a sort function in RoomsList.js to order the rooms based on the room id
• To highlight the clicked room, get the active room id and compare it with the currently clicked room Id and assign a difference class name with specific css style associated
• To scroll down the messages - in MessageLost.js
	  componentDidUpdate(){
	    const messageListNode = ReactDOM.findDOMNode(this)
	    messageListNode.scrollTop = messageListNode.scrollHeight
	  }
	
	○ The Element.scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically.
	○ The Element.scrollHeight read-only property is a measurement of the height of an element's content, including content not visible on the screen due to overflow.
• To create a room use the below function similar to SendMessageForm,

	    newRoomFromUser(roomName){
	        console.log("New room is "+roomName)
	        this.currentUser.createRoom({
	            name:roomName
	        })
	        .then(room=>this.subscribeToRoom(room.id))
	    }

chat-app-using-reactjs's People

Contributors

saranyaeaswaran avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.