text: /**
   * Recipe Actions
   *
   * WaziApp
   * https://github.com/Waziup/waziup-mobile
   */
  import { Firebase, FirebaseRef } from '@constants/';
  
  /**
    * Get this User's Favourite Recipes
    */
  export function getFavourites(dispatch) {
    if (Firebase === null) return () => new Promise(resolve => resolve());
  
    const UID = Firebase.auth().currentUser.uid;
    if (!UID) return false;
  
    const ref = FirebaseRef.child(`favourites/${UID}`);
  
    return ref.on('value', (snapshot) => {
      const favs = snapshot.val() || [];
  
      return dispatch({
        type: 'FAVOURITES_REPLACE',
        data: favs,
      });
    });
  }
  
  /**
    * Reset a User's Favourite Recipes in Redux (eg for logou)
    */
  export function resetFavourites(dispatch) {
    return dispatch({
      type: 'FAVOURITES_REPLACE',
      data: [],
    });
  }
  
  /**
    * Update My Favourites Recipes
    */
  export function replaceFavourites(newFavourites) {
    if (Firebase === null) return () => new Promise(resolve => resolve());
  
    const UID = Firebase.auth().currentUser.uid;
    if (!UID) return false;
  
    return () => FirebaseRef.child(`favourites/${UID}`).set(newFavourites);
  }
  
  /**
    * Get Meals
    */
  export function getMeals() {
    if (Firebase === null) return () => new Promise(resolve => resolve());
  
    return dispatch => new Firebase.Promise((resolve) => {
      const ref = FirebaseRef.child('meals');
  
      return ref.once('value').then((snapshot) => {
        const meals = snapshot.val() || {};
  
        return resolve(dispatch({
          type: 'MEALS_REPLACE',
          data: meals,
        }));
      });
    });
  }
  
  /**
    * Get Recipes
    */
  export function getRecipes() {
    if (Firebase === null) return () => new Promise(resolve => resolve());
  
    return dispatch => new Firebase.Promise((resolve) => {
      const ref = FirebaseRef.child('recipes');
  
      return ref.on('value', (snapshot) => {
        const recipes = snapshot.val() || {};
  
        return resolve(dispatch({
          type: 'RECIPES_REPLACE',
          data: recipes,
        }));
      });
    });
  }
  