Facebook-Inspired Reactions System with Angular and Firebase

Fireship · Beginner ·📊 Data Analytics & Business Intelligence ·9y ago

Key Takeaways

This video teaches how to create a Facebook-inspired reactions system using Angular 4 and Firebase

Full Transcript

in this episode we're going to replicate Facebook reactions using angular for and firebase first let's head over to Facebook just to see how it works you can hover over like button which brings up a tooltip with all the different reactions when you click reaction it updates your own as well as the list of other users reactions below that first thing we're going to do is import the graphics into our project I found some free Facebook icons on icon finder calm and then save them under the assets folder in the angular project now we can generate the reaction service and import the angularfire auth module as well as the database module we're also going to make heavy use of lodash to handle the sorting and counting of reactions we'll keep track of the user ID on the service and then we create an array of the actual emoji graphics we want each emoji to be tied to a specific index and we'll save that index in the database in this case light will be 0 loved one Wow 2 etc so our database is a collection of item IDs things that can be reacted to and each document is the keys of the users and the number that corresponds to their reaction the first thing we'll do is get the associated reaction score and item as a firebase object observable next we create a function that allows the user to update their reaction which has a default value of 0 for life we format the data by passing the user ID is the key and the reaction is the value and then we just update that object in firebase following the same idea we create another function that allows the user to remove their reaction from the database now we create a utility function to counsel reactions to come back from firebase it returns a JavaScript object where the key is the value of the reaction and the value is the number of reactions for that type we'll use it to display the total count for each reaction type in the component template the final step is to determine the current users reaction so we just check the object for that specific user ID now we can start building the front-end component first we're going to need the input decorator as well as ondestroy and we'll also inject the reaction service and we'll use lo - in here as well the component will accept an input variable which represents the parents ID that can be any kind of content that can be reacted to then we'll declare a few other variables that represent the data we're going to be showing in the template during ng on a knit we first get big lists of emoji then we subscribe to the object observable when it emits a value it'll be a JavaScript object of user IDs and their reactions we can use this object to count the total reactions for each type as well as determine the current users reaction from there we create an event handler that will actually update or remove a reaction if the user already has a reaction with a matching value then we'll go ahead and delete that reaction if the value is different it means the users updating or creating a new reaction so we go ahead and update that in the database next we create another event handler that will require when the user hovers over the like button which will show the emojis and we create a utility method to return the emoji image path in the assets folder and one more utility method to see if a reaction type has reactions so we know whether or not to display it in the template then we unsubscribe when the components destroyed to avoid memory leaks now let's put this all together in the component HTML first we create a wrapper around everything and use the mouse enter mouse we've events to toggle the physical of the emojis inside this div we loop over the six emojis and use our emoji pass helper to find the Associated graphic in the assets folder notice how we also get the index while looping through this array because that will be the value we save to the database corresponding to this reaction type next we'll add a like button that the user can click that will add just a generic light if the user has liked this piece of content we'll go ahead and add a conditional class that will color a blue and make it bold and also we want to display the type of reaction the users have in both cases we check to see if the user reaction is not null we can use the value of the reaction to get the corresponding emoji from the emoji list and it's indexed now we need to display the total reaction Cal we do this by looping over the emoji list again and we'll see if a reaction has taken place and then we'll get the total count for that reaction just like before we use the Emoji path helper to display the corresponding image then we can get the count from our reaction count object by just passing up that index let's try it out in the app if we hover over the like button it should bring up the emojis and if we click it it should add a light telling us what the light type is the reaction counts are all kept up to date in real time so if we have multiple users reacting to the same piece of content we'll see the reaction counts be updated in real time when looking into the database console we can see that going to user clicks the reaction it adds their user ID key and the value for that reaction to the database that's it for this episode if you found the video helpful please like and subscribe and if you want to support the channel consider becoming a pro subscriber at angular firebase comm for just a few bucks a month you'll get access to your exclusive content as well as free one on one project consulting thanks for watching and I'll see you next time [Music]

Original Description

Fully documented lesson at https://angularfirebase.com/lessons/facebook-inspired-reactions-from-scratch-with-angular-and-firebase/ Learn how to create Facebook style reactions with Angular 4 and Firebase NoSQL from scratch.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Fireship · Fireship · 21 of 60

1 Angular 4 Development and Production Environments with Firebase
Angular 4 Development and Production Environments with Firebase
Fireship
2 OAuth with Angular and Firebase Tutorial
OAuth with Angular and Firebase Tutorial
Fireship
3 Anonymous Authentication with Angular and Firebase - Lazy Registration
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
4 Angular Router Guards for Firebase Users
Angular Router Guards for Firebase Users
Fireship
5 Angular Firebase CRUD App with NoSQL Database Tutorial
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
6 Upload Files from Angular to Firebase Storage
Upload Files from Angular to Firebase Storage
Fireship
7 How to Deploy an Angular App to Firebase Hosting
How to Deploy an Angular App to Firebase Hosting
Fireship
8 Sharing Data between Components in Angular
Sharing Data between Components in Angular
Fireship
9 Loading Spinners for Asynchronous Firebase Data
Loading Spinners for Asynchronous Firebase Data
Fireship
10 Angular 4 Transactional Email with Google Firebase Cloud Functions
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
11 Firebase Database Rules Tutorial
Firebase Database Rules Tutorial
Fireship
12 Autocomplete Search with Angular4 and Firebase
Autocomplete Search with Angular4 and Firebase
Fireship
13 Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
14 Angular Drag-and-Drop File Uploads to Firebase Storage
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
15 Text Translation with Firebase Cloud Functions onWrite and Angular 4
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
16 Custom Usernames with Firebase Authentication
Custom Usernames with Firebase Authentication
Fireship
17 Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
18 Simple Pagination with Firebase and Angular 4
Simple Pagination with Firebase and Angular 4
Fireship
19 How to Connect Firebase Users to their Data - 3 Methods
How to Connect Firebase Users to their Data - 3 Methods
Fireship
20 Add Toast Message Notifications to your Angular App
Add Toast Message Notifications to your Angular App
Fireship
Facebook-Inspired Reactions System with Angular and Firebase
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
22 Learn NgModule in Angular with Examples
Learn NgModule in Angular with Examples
Fireship
23 Lazy Loading Components in Angular 4
Lazy Loading Components in Angular 4
Fireship
24 Stripe Checkout Payments with Angular and Firebase - Part 1
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
25 Process Stripe Payments with Firebase Cloud Functions - Part 2
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
26 Selling Digital Content in Angular with Stripe Payments - Part 3
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
27 Angular 4 Full Text Search with Algolia - Part 1
Angular 4 Full Text Search with Algolia - Part 1
Fireship
28 Algolia with Firebase Cloud Functions - Part 2
Algolia with Firebase Cloud Functions - Part 2
Fireship
29 Firebase Phone Authentication in Angular 4
Firebase Phone Authentication in Angular 4
Fireship
30 Top 7 RxJS Concepts for Angular Developers
Top 7 RxJS Concepts for Angular Developers
Fireship
31 Learn Angular Animations with 5 Examples
Learn Angular Animations with 5 Examples
Fireship
32 Advanced Firebase Data Filtering (Multi-Property)
Advanced Firebase Data Filtering (Multi-Property)
Fireship
33 Realtime Maps with Mapbox + Firebase + Angular
Realtime Maps with Mapbox + Firebase + Angular
Fireship
34 Angular Reactive Forms with Firebase Database Backend
Angular Reactive Forms with Firebase Database Backend
Fireship
35 Send Push Notifications in Angular with Firebase Cloud Messaging
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
36 Top 7 Ways to Debug Angular 4 Apps
Top 7 Ways to Debug Angular 4 Apps
Fireship
37 Infinite Scroll with Angular and Firebase
Infinite Scroll with Angular and Firebase
Fireship
38 Use TypeScript with Firebase Cloud Functions
Use TypeScript with Firebase Cloud Functions
Fireship
39 Realtime Graphs and Charts with Plotly and Firebase
Realtime Graphs and Charts with Plotly and Firebase
Fireship
40 Role-Based User Permissions in Firebase
Role-Based User Permissions in Firebase
Fireship
41 User Presence System in Realtime - Online, Offline, Away
User Presence System in Realtime - Online, Offline, Away
Fireship
42 Location-based Queries with GeoFire and Angular Google Maps
Location-based Queries with GeoFire and Angular Google Maps
Fireship
43 Angular ngrx Redux Quick Start Tutorial
Angular ngrx Redux Quick Start Tutorial
Fireship
44 Angular Ngrx Effects with Firebase Database
Angular Ngrx Effects with Firebase Database
Fireship
45 Progressive Web Apps with Angular
Progressive Web Apps with Angular
Fireship
46 Angular Ngrx with Firebase Google OAuth User Authentication
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
47 RxJS Quick Start with Practical Examples
RxJS Quick Start with Practical Examples
Fireship
48 Send SMS Text Messages with Twilio and Firebase
Send SMS Text Messages with Twilio and Firebase
Fireship
49 Firebase Database Performance Profiling
Firebase Database Performance Profiling
Fireship
50 Native Desktop Apps with Angular and Electron
Native Desktop Apps with Angular and Electron
Fireship
51 Subscription Payments with Stripe, Angular, and Firebase
Subscription Payments with Stripe, Angular, and Firebase
Fireship
52 Firestore with AngularFire5 Quick Start Tutorial
Firestore with AngularFire5 Quick Start Tutorial
Fireship
53 Angular HTTP Client Quick Start Tutorial
Angular HTTP Client Quick Start Tutorial
Fireship
54 Google Sign-In with Firestore Custom User Data
Google Sign-In with Firestore Custom User Data
Fireship
55 Star Review System from Scratch with Firestore + Angular
Star Review System from Scratch with Firestore + Angular
Fireship
56 Angular Chatbot with Dialogflow (API.ai)
Angular Chatbot with Dialogflow (API.ai)
Fireship
57 Learn @ngrx/entity and Feature Modules
Learn @ngrx/entity and Feature Modules
Fireship
58 Infinite Scroll Pagination with Firestore
Infinite Scroll Pagination with Firestore
Fireship
59 Faster Firestore via Data Aggregation
Faster Firestore via Data Aggregation
Fireship
60 Contentful - CMS for Angular Progressive Web Apps
Contentful - CMS for Angular Progressive Web Apps
Fireship

Related Reads

📰
The Oldest Decision in Agriculture, Made With a New Instrument
Learn how to apply curve-implied convenience yield to decide when to sell harvests using economic problems, backtesting, and risk assessment
Medium · AI
📰
Python Excel Automation: Create, Edit, and Format Text Boxes
Automate Excel tasks using Python to create, edit, and format text boxes in spreadsheets
Medium · Programming
📰
From Spreadsheets to Spark: Why Traditional Analytics Tools Reach Their Limits
Learn why traditional analytics tools like spreadsheets reach their limits and how to transition to more scalable solutions like Spark
Medium · Data Science
📰
Skill Verification for Data Roles: What Employers Should Know
Employers can verify data skills through practical assessments to ensure candidates can apply their knowledge in real-world scenarios, making hiring more effective
Dev.to AI
Up next
This could be the most perfect data frontend
Matt Williams
Watch →