Fireship · @fireship

Facebook-Inspired Reactions System with Angular and Firebase

Uploaded July 6, 2017 · Length 6:26

Facebook-Inspired Reactions System with Angular and Firebase

Summary

Replicate Facebook reactions using Angular and Firebase, including database and front-end implementation.

  • angular
  • firebase
  • facebook reactions
  • reactive system
  • angular firebase tutorial

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 replicate

  2. 0:02

    Facebook reactions using angular for and

  3. 0:05

    firebase first let's head over to

  4. 0:08

    Facebook just to see how it works you

  5. 0:10

    can hover over like button which brings

  6. 0:13

    up a tooltip with all the different

  7. 0:14

    reactions when you click reaction it

  8. 0:17

    updates your own as well as the list of

  9. 0:20

    other users reactions below that first

  10. 0:24

    thing we're going to do is import the

  11. 0:25

    graphics into our project I found some

  12. 0:28

    free Facebook icons on icon finder calm

  13. 0:30

    and then save them under the assets

  14. 0:33

    folder in the angular project now we can

  15. 0:36

    generate the reaction service and import

  16. 0:39

    the angularfire

  17. 0:40

    auth module as well as the database

  18. 0:41

    module we're also going to make heavy

  19. 0:44

    use of lodash to handle the sorting and

  20. 0:46

    counting of reactions we'll keep track

  21. 0:49

    of the user ID on the service and then

  22. 0:51

    we create an array of the actual emoji

  23. 0:54

    graphics we want each emoji to be tied

  24. 0:57

    to a specific index and we'll save that

  25. 0:59

    index in the database in this case light

  26. 1:02

    will be 0 loved one Wow 2 etc so our

  27. 1:06

    database is a collection of item IDs

  28. 1:08

    things that can be reacted to and each

  29. 1:11

    document is the keys of the users and

  30. 1:14

    the number that corresponds to their

  31. 1:16

    reaction the first thing we'll do is get

  32. 1:19

    the associated reaction score and item

  33. 1:22

    as a firebase object observable next we

  34. 1:27

    create a function that allows the user

  35. 1:29

    to update their reaction which has a

  36. 1:31

    default value of 0 for life we format

  37. 1:34

    the data by passing the user ID is the

  38. 1:36

    key and the reaction is the value and

  39. 1:39

    then we just update that object in

  40. 1:41

    firebase following the same idea we

  41. 1:44

    create another function that allows the

  42. 1:46

    user to remove their reaction from the

  43. 1:48

    database now we create a utility

  44. 1:52

    function to counsel reactions to come

  45. 1:54

    back from firebase it returns a

  46. 1:56

    JavaScript object where the key is the

  47. 1:58

    value of the reaction and the value is