Vue & Firebase Real-time Chat (Preview) #8 - New Message Component

Net Ninja · Intermediate ·🛠️ AI Tools & Apps ·8y ago
Skills: API Design70%

Key Takeaways

Builds a new message component for a real-time chat application using Vue.js and Firebase

Full Transcript

okay so we've made this chat window right here this component and we said that we wanted to separate this form at the bottom where a user adds a new message into its own component so let's create that new component first of all over here and we'll call it new message view now then we don't need to create a route for this because obviously it's not going to have its own page we're just going to nest this component inside here so we'll do that first of all we'll import the file inside here we'll say import and it would be new message from and then apps forward slash components forward slash new message okay so now we can register it down here we'll create a new property core components which will be an object and inside this object will register the new message component okay so now instead of this input field right here we'll nest the new message component now in this new message component we'll be getting the message from the user in an input field and sending it to the database but we also want to get from the user the name now we currently have access to the name here as a prop but we can pass it also down into this new message component as well so we'll say name is equal to and then we'll say name in here now this is going to pass downn name as a literal string so we need to do some data binding here to bind something dynamic in here so now it will look for this property name over here and we can pass it down into this component so we have access to it okay so let's save that first of all and then head to new message to create this template so template tags first of all then inside we need a div with a class of new - message so inside this component we just want basically a form with an input field and maybe a label so let's create that form first of all we don't need the action but we will attach a submit event to it so at sign submit and we want to prevent the default action will set this equal to a function called add message now we don't have that created yet we'll do it in a minute okay so inside this form we want a label first of all and this is going to be for the new message input field and in the text area we'll say new message and then I want a user to click enter to add this because when you click enter in a form that submits the form we don't just have to click on a button we can click enter inside a form and that will fire the submit event as well so I'll just say in brackets enter to add okay so now we have the label we just need the input field so import it's of type text and it's gonna have a name property equal to new - message alright now we'll create our script tag down here and then come back to this in a second so let's do I'm a script tag where we have our data property inside this returns an object okay so now we need some kind of property to store the value of this input field um now we'll call this new message so new message like so and to begin with set it equal to null now what we can do over here then is say v-model equals new message so that whatever user types into this field it updates this property with so we're storing that property now we also need to give this a nameless component and it's new message and remember we're receiving a prop from the parent component so we'll say props and that prop is the name okay so now we have this hooked up to here so when a user clicks enter it's gonna fire this function right here ads message so let's define that in our methods property create the function called add message and inside here what do we want to do well ultimately we want to send this data the message and the name and also a timestamp of when this message was created to the database but for now let's just log them to the console we'll say console.log this new message will also log this name because that's the proper receive it and then we'll also log date now to create a timestamp so when a user clicks enter it's going to grab the now date and it's going to tap that on here and we're going to publish that to the database as well so let's save this and see if it works over here we can see this component is embedded into the chat window if we inspect the elements so we can get the console over here we have some errors there but if we refresh hopefully we don't get those errors okay cool now we'll enter in a name first of all mário enter the chat and let's add a message so we'll just say Haider press ENTER and now we get hey there the message Mario the name and this timestamp right here now this is milliseconds since a certain date so it doesn't look like a particular time but that millisecond value will allow us to form at a time later on okay so we'll use this to store in the database then when we retrieve it back we can take that time stamp this millisecond value and we can turn it into a date that is logical something like 4:00 p.m. on Thursday or something like that okay so there we go we've created this new message component now and we grab the data that we need so now we can look at how it can get this data and send it to our fire store

Original Description

FULL COURSE LINK - https://www.udemy.com/build-web-apps-with-vuejs-firebase/?couponCode=NINJAYT18 Use Code NINJAYT18 for discount. Discount should already be applied when using the link above! See the full course for a full Vue.js tutorial, including building 3 projects with Firebase.
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 49 of 60

1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

Related Reads

Up next
How to Get Your Brand Cited by ChatGPT, Claude and Gemini
Arvow
Watch →