Fireship · @fireship

Reddit Inspired Upvoting System with Angular and Firebase NoSQL

Uploaded June 23, 2017 · Length 5:47

Reddit Inspired Upvoting System with Angular and Firebase NoSQL

Summary

build reddit upvoting system with angular and firebase nosql

  • angular
  • firebase
  • nosql
  • upvoting system
  • reddit style voting

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    in this episode we're going to build a

  2. 0:02

    Reddit style up voting down voting

  3. 0:04

    system using angular 4 and

  4. 0:06

    Firebase in this example we have a

  5. 0:09

    collection of items already in the

  6. 0:11

    database and we also have Firebase

  7. 0:14

    authentication set up in our app if

  8. 0:16

    you're new to Firebase authentication

  9. 0:18

    I've added a couple links in the

  10. 0:19

    description with more

  11. 0:21

    details the first thing we need to think

  12. 0:23

    about is modeling our data in the

  13. 0:25

    Firebase no SQL

  14. 0:27

    database our database needs to answer

  15. 0:30

    two fundamental

  16. 0:31

    questions what is the user's vote for a

  17. 0:34

    given item and What's the total vote

  18. 0:37

    count for a given

  19. 0:39

    item we can answer this question by

  20. 0:41

    creating a collection based on the

  21. 0:43

    unique ID of the

  22. 0:46

    items for each item id we save the user

  23. 0:49

    IDs that have voted on that item this

  24. 0:51

    way we can query an item and see if the

  25. 0:53

    users voted on it and we can also tally

  26. 0:56

    up the collection of users under an item

  27. 0:59

    to get the total vote

  28. 1:00

    account let's start by building the

  29. 1:03

    service the first thing we need is the

  30. 1:06

    Firebase object observable for a

  31. 1:08

    specific item

  32. 1:10

    [Music]

  33. 1:18

    id we also need the user to be able to

  34. 1:20

    cast their vote by updating the item

  35. 1:23

    object in the

  36. 1:25

    database the update user vote function

  37. 1:28

    will send a new key value pair to the

  38. 1:29

    the item in the database with the key

  39. 1:31

    being the user's ID and the value being

  40. 1:34

    the value of the boat which can be

  41. 1:36

    either A-1 zero or

  42. 1:41

    one now we can build the upvote button

  43. 1:46

    component our component will accept a

  44. 1:48

    couple of input values since this is

  45. 1:50

    normally going to be a child component

  46. 1:52

    of an item we can go ahead and pass it

  47. 1:55

    the item id as well as the user ID