Code Monkey home page Code Monkey logo

miiakivi / superchat Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3.47 MB

Chat application build using Firebase, Firestore database and Firebase Storage services, Google authentication. In app users have to sign in to send and receive text and image messages to other online users.

Home Page: https://miianyy.github.io/superchat/

JavaScript 78.11% CSS 21.89%
react firebase firebase-auth backend javascript firestore-database chat chat-application

superchat's Introduction

Super chat app

This project's goal was to practice using Googles BAAS Firebase. I created a chat app that uses Firebase Firestorr database, Firebase authentication and firebase realtime database. This was my first touch using and building the backend to my projects.

two users chatting in the app

General

Users sign in to the chat using Google authentication. They can choose their own username, color and icon which are used as indicators for other users in the chat.

In the app there is one chat room where users can send text and image messages to each other. Users can see other users that are currently using app in the sidebars list.

I created this element by updating the user document in the database every 20 seconds when user is using the app. Other function listens any updates in user database and shows user in the online list if their last appearance has been in the last three minutes.

Firebase

Chat messages sent by users are stored in a "Super Chat" database collection called "messages" as documents. Documents store information such as who sent the message, when it was sent, and what is in the message. When user sends new message to the chat, this information is sent to the database.

// Example message
await db.collection('messages').add({
    senderName: "miianyy",
    senderIcon: "blonde-hair",
    text: "Hello, how are you",
    createdAt: firebase.firestore.FieldValue.serverTimestamp(),
    uid,
    color: "blue",
})

When chat room is first loaded and after every time new message is added chat messages are updated and new messages show to users.

// Stores all of the messages from database
const [messages, setMessages] = useState([]);

useEffect(() => {
    // Gets all messages documents from database
    db.collection('messages').orderBy('createdAt').limit(50)
      .onSnapshot((snapshot) => {
          setMessages(snapshot.docs.map(doc => doc.data()));
      })
}, [])

return (
    <section>
        { messages.map((msg, index) => {
            return <ChatMessage key={ uniqid() } message={ msg }/>
        }) }
    </section>
)

User can also send image messages to each other. These images are stored in the Firebase Storage to their own folders and files. In the "messages" collection, is a document containing the url location of the image in the Firebase Storage. Using this url the image can be displayed to the user.

Things I learned

  • How navigate in the Firebase Console
  • How to create new database to Firestore and how to create new documents in it using Firebase Console and in my code
  • How to fetch the data from database document and how to update or delete it
    • If user wants to change or update their user settings, how can I update all the messages documents from that current user so in the message shows right user settings
  • How other users that are using chat, can see who others are currently using the chat

Technologies

  • React
    • React hooks
      • useState
      • useEffect
      • useRef
    • Styled Components ๐Ÿ’…
    • create-react-app
  • JavaScript
    • es6
    • async await
    • try/catch
  • CSS
    • mobile first

superchat's People

Contributors

miiakivi 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.