How to build a clone of WhatsApp Web Using Vue.js, Firebase, and Spring Boot.
We use a lot of social media platforms every day, like Facebook, LinkedIn, Twitter, Whatsapp, Instagram. One of the most used features every day is real time chat. In this tutorial, we are going to build one, using Vue.js and Firebase.
This is part of a series of tutorials, where we will be building a fully functional social networking app, where users can log in, post, add friends, and chat.
Previously, we used Firebase to create a social login using Spring Boot in the backend and Vue.js in the frontend.
Let’s Build a Robust Social Login Using Spring Boot, Vue.js and Firebase
Github code for this tutorial:
Let's build the view for the entire page, it has two components:
For each friend, we have a room name, which we store in the backend. And we retrieve it via this API.
Complete code for the above can be found here:
Response of the API
Once we have the rooms information, we send it to the child components. Let's look at the ChatSidebar component
It gets the rooms prop from the parent Chat and display a list of SidebarChatUserRow components for each user from the rooms list prop passed from parent Chat.vue.
It also has 3 icons in the top right, which look really good!
This component is very simple — it’s just to display the email and avatar for each user. We can add the last message later, if we want.
This is the right side part of the chat, where we display the actual chats. First, we will discuss how we are displaying the chats and then we will see, when we click a different user, how to update the chats.
By default, we pass the first user’s room, so it has a prop room, which also has the user information (avatar, email) which we display in the header.
From the roomname, we find the associated roomId in Firebase and get all the associated chats and display those chats.
There is a form, where we hide the send button and onclick action. We prevent the default submit and refresh action of form by v-on:submit.prevent directive.
We get the data for inputMsg div and add a new entry in firebase by adding the chat in room name.
Now we have one important function left, which is about selecting a different friend from the Sidechatbar and how to update the chatview.
As they are not a parent-child type, we can’t directly pass prop or update the props. The answer is emitting the event and listening for it.
The complete code for the chatview.view component:
How to pass props.
How to render components.
How to emit events and use them.
How to integrate Firebase.
That's it. You can run the frontend code on your local computer and comment here if anything goes wrong. Thanks for reading!
More content at plainenglish.io