Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
458 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const ROOT_FIREBASE_URL = 'https://favorite-movies.firebaseio.com' | ||
const FAVORITE_MOVIES = 'favorite-movies' | ||
const OMDB_URL = 'http://www.omdbapi.com/' | ||
const MOVIE_NOT_FOUND = 'Movie not found!' | ||
|
||
export default { | ||
ROOT_FIREBASE_URL, | ||
FAVORITE_MOVIES, | ||
OMDB_URL, | ||
MOVIE_NOT_FOUND | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const CHILD_ADDED = 'child_added' | ||
const CHILD_REMOVED = 'child_removed' | ||
|
||
export default { | ||
CHILD_ADDED, | ||
CHILD_REMOVED | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import keyMirror from 'react/lib/keyMirror' | ||
|
||
export default keyMirror({ | ||
VIEW_ACTION: null, | ||
SERVER_ACTION: null | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
.search { | ||
margin-bottom: 1em; | ||
} | ||
|
||
.preloader{ | ||
margin: 2em auto; | ||
text-align: center; | ||
width: 100%; | ||
} | ||
|
||
.preloader svg { | ||
width: 20px; | ||
height: 30px; | ||
} | ||
|
||
svg path, | ||
svg rect{ | ||
fill: #158CBA; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Firebase from 'firebase' | ||
import { ROOT_FIREBASE_URL, FAVORITE_MOVIES } from '../constants/constants' | ||
import { CHILD_ADDED } from '../constants/firebaseTypes' | ||
|
||
function firebaseService(actions) { | ||
var rootFirebaseRef = new Firebase(ROOT_FIREBASE_URL) | ||
var favoriteMoviesFirebaseRef = rootFirebaseRef.child(FAVORITE_MOVIES) | ||
|
||
return { | ||
|
||
getRootFirebaseRef() { | ||
return rootFirebaseRef | ||
}, | ||
|
||
getFavoriteMoviesFirebaseRef() { | ||
return favoriteMoviesFirebaseRef | ||
}, | ||
|
||
addToFavoriteMovies(movie) { | ||
return favoriteMoviesFirebaseRef.push(movie, (err) => { | ||
if (err) { | ||
console.error(err.message) | ||
} | ||
}) | ||
}, | ||
|
||
removeFromFavoriteMovies(key) { | ||
let movieRef = favoriteMoviesFirebaseRef.child(key) | ||
let errorHandler = (err) => { | ||
if (err) { | ||
console.error(err) | ||
} else { | ||
console.log(`movie ${ key } was removed`) | ||
actions.childRemoved(key) | ||
} | ||
} | ||
|
||
movieRef.remove(errorHandler) | ||
}, | ||
|
||
on(type) { | ||
switch(type) { | ||
case CHILD_ADDED: | ||
favoriteMoviesFirebaseRef.on(CHILD_ADDED, function childAdded(childSnapshot, prevChildKey) { | ||
let movie = childSnapshot.val() | ||
movie.firebaseKey = childSnapshot.key() | ||
// TODO: how to postpone the actions while dealing with firebase? | ||
setTimeout(() => actions.childAdded(movie), 0) | ||
}) | ||
break; | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
export default firebaseService | ||
// _listenToFavoriteMoviesSvc() { | ||
|
||
// } | ||
|
||
// _removeFromFavoriteMovies(key) { | ||
// this._favoriteMovies = this._favoriteMovies.filter((movie) => movie.firebaseKey !== key) | ||
// // FIXME: should send another action to the system? | ||
// this.emitChange() | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.