Reddit Inspired Upvoting System with Angular and Firebase NoSQL

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

Key Takeaways

This video demonstrates how to build a Reddit-style upvoting system using Angular 4 and Firebase NoSQL database, including data modeling, service creation, and component development.

Full Transcript

in this episode we're going to build a Reddit style up voting down voting system using angular 4 and Firebase in this example we have a collection of items already in the database and we also have Firebase authentication set up in our app if you're new to Firebase authentication I've added a couple links in the description with more details the first thing we need to think about is modeling our data in the Firebase no SQL database our database needs to answer two fundamental questions what is the user's vote for a given item and What's the total vote count for a given item we can answer this question by creating a collection based on the unique ID of the items for each item id we save the user IDs that have voted on that item this way we can query an item and see if the users voted on it and we can also tally up the collection of users under an item to get the total vote account let's start by building the service the first thing we need is the Firebase object observable for a specific item [Music] id we also need the user to be able to cast their vote by updating the item object in the database the update user vote function will send a new key value pair to the the item in the database with the key being the user's ID and the value being the value of the boat which can be either A-1 zero or one now we can build the upvote button component our component will accept a couple of input values since this is normally going to be a child component of an item we can go ahead and pass it the item id as well as the user ID in the component typescript we have just a generic component but we're also going to be using the input decorator and we've also imported low Dash as well to help us facilitate the vote count which you'll see later on so we have input variables for the item ID and the user ID and we have a couple number variables one that represents the total vote count and one that represents the current user's vote during the NG on AIT life cycle hook we can subscribe to the Firebase object observable from our service the observable itself is going to emit the up votes and we can use that to figure out what the user's vote is and also get the total vote count for an item and we add a conditional statement when checking the user vote because it's possible the user is not logged in when viewing an item an added feature you might consider is redirecting the user to a loog Lo in page when they click the up vote button and they're not logged in in this example I'm using the low Dash library to put all the object values into an array and then get the sum of that array doing the same thing in JavaScript would require a lot more code so we're going to keep it concise and readable so now we can build two separate functions one for up boting and one for down boting these functions are identical the only difference being a positive one for an up vote and a netive one for a down vote we also want the user to be able to cancel their vote by just clicking the same button again so we do this by checking to see if the user vote is already an up Vote or a down vote and if it is then we set the vote value to zero which will essentially reverse their vote we can do this in one line using a JavaScript turn are operator to replace a multi-line if El statement the final step is to end the subscription once the component's destroyed to avoid introducing memory leaks into the app we can do this with the on destroy life cycle [Music] [Music] hook in the template we create two Arrow icons that handle up boating and down boating we simply find the up vote and down vote functions to The Click event on these buttons [Music] in order to show the user whether or not they've up voted or down voted for an item we color the up votes green and the down votes red we can do this with the NG class directive which will add an active class to the item if it's up vat is either greater than zero or less than zero now if we go into our app we can see that we have a fully functional upboat downb system on the left we have the app itself and on the right we can see it's updating the Firebase database in real [Music] time 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.com for just a few bucks a month you'll get access to exclusive content as well as free one-on-one project Consulting thanks for watching and I'll see you next time audio jum

Original Description

https://angularfirebase.com/lessons/reddit-style-upvoting-in-angular-4-and-firebase-nosql/ Learn how to build a Reddit-style upvote/downvote system with Angular 4 and Firebase Realtime NoSQL database.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Fireship · Fireship · 13 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
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
21 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

This video teaches how to build a Reddit-style upvoting system using Angular 4 and Firebase NoSQL database, covering data modeling, service creation, and component development. The system allows users to upvote or downvote items, and updates the vote count in real-time. The video provides a comprehensive guide on how to implement this system, including handling user authentication and optimizing frontend performance.

Key Takeaways
  1. Model data for upvoting system in NoSQL database
  2. Create service to interact with Firebase database
  3. Develop component for upvoting and downvoting
  4. Implement user authentication using Firebase
  5. Optimize frontend performance for upvoting system
  6. Test and deploy the upvoting system
💡 Using a NoSQL database like Firebase allows for flexible and scalable data modeling, making it ideal for real-time applications like upvoting systems.

Related AI Lessons

Up next
Spreadsheet Guy Meets the CFO: "Define How Much"
Digital Transformation with Eric Kimberling
Watch →