Let’s Build a WhatsApp Clone Using Vue.js and Firebase

nilmadhabmondal

Nil Madhab

Posted on April 23, 2021

Let’s Build a WhatsApp Clone Using Vue.js and Firebase

Let’s Build a WhatsApp Clone Using Vue.js and Firebase

How to build a clone of WhatsApp Web Using Vue.js, Firebase, and Spring Boot.

Whatspp Clone for realtime chat

Introduction

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

Live Demo:
simplecoding-social

Github code for this tutorial:
webtutsplus/social-network-frontend

Project Structure

Relevant files for this tutorial

Let’s Build the Chat page

Let's build the view for the entire page, it has two components:

  1. ChatSidebar

  2. ChatView

ChatSidebar and ChatView 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:
webtutsplus/social-network-frontend

Response of the API


Once we have the rooms information, we send it to the child components. Let's look at the ChatSidebar component

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!


SidebarChatUserRow component

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.


ChatView component

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.

chat main

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.

Firebase chats store

Creating a new chat

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.

submit form


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.

Emit an event in **SidebarChatUserRow** component

Retrieving the event in Chatview and updating everything

The complete code for the chatview.view component:
webtutsplus/social-network-frontend

In this tutorial, we have covered some really interesting modern JavaScript topics like:

  1. How to pass props.

  2. How to render components.

  3. How to emit events and use them.

  4. 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!

References

Let’s Build a Robust Social Login Using Spring Boot, Vue.js and Firebase

More content at plainenglish.io

💖 💪 🙅 🚩
nilmadhabmondal
Nil Madhab

Posted on April 23, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related