Fireship · @fireship
Facebook-Inspired Reactions System with Angular and Firebase
Uploaded July 6, 2017 · Length 6:26
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.
- 0:00
in this episode we're going to replicate
- 0:02
Facebook reactions using angular for and
- 0:05
firebase first let's head over to
- 0:08
Facebook just to see how it works you
- 0:10
can hover over like button which brings
- 0:13
up a tooltip with all the different
- 0:14
reactions when you click reaction it
- 0:17
updates your own as well as the list of
- 0:20
other users reactions below that first
- 0:24
thing we're going to do is import the
- 0:25
graphics into our project I found some
- 0:28
free Facebook icons on icon finder calm
- 0:30
and then save them under the assets
- 0:33
folder in the angular project now we can
- 0:36
generate the reaction service and import
- 0:39
the angularfire
- 0:40
auth module as well as the database
- 0:41
module we're also going to make heavy
- 0:44
use of lodash to handle the sorting and
- 0:46
counting of reactions we'll keep track
- 0:49
of the user ID on the service and then
- 0:51
we create an array of the actual emoji
- 0:54
graphics we want each emoji to be tied
- 0:57
to a specific index and we'll save that
- 0:59
index in the database in this case light
- 1:02
will be 0 loved one Wow 2 etc so our
- 1:06
database is a collection of item IDs
- 1:08
things that can be reacted to and each
- 1:11
document is the keys of the users and
- 1:14
the number that corresponds to their
- 1:16
reaction the first thing we'll do is get
- 1:19
the associated reaction score and item
- 1:22
as a firebase object observable next we
- 1:27
create a function that allows the user
- 1:29
to update their reaction which has a
- 1:31
default value of 0 for life we format
- 1:34
the data by passing the user ID is the
- 1:36
key and the reaction is the value and
- 1:39
then we just update that object in
- 1:41
firebase following the same idea we
- 1:44
create another function that allows the
- 1:46
user to remove their reaction from the
- 1:48
database now we create a utility
- 1:52
function to counsel reactions to come
- 1:54
back from firebase it returns a
- 1:56
JavaScript object where the key is the
- 1:58
value of the reaction and the value is


