// @flow
import React from 'react';
import { compose } from 'redux';
import prepare from 'app/utils/prepare';
import { fetchRandomQuote } from 'app/actions/QuoteActions';
import { connect } from 'react-redux';
import RandomQuote from './RandomQuote';
import { addReaction, deleteReaction } from 'app/actions/ReactionActions';
import { selectEmojis } from 'app/reducers/emojis';
import { selectRandomQuote } from 'app/reducers/quotes';
import { fetchEmojis } from 'app/actions/EmojiActions';
import loadingIndicator from 'app/utils/loadingIndicator';
import replaceUnlessLoggedIn from 'app/utils/replaceUnlessLoggedIn';

function mapStateToProps(state, props) {
  const emojis = selectEmojis(state);
  const currentQuote = selectRandomQuote(state);
  return {
    loggedIn: props.loggedIn,
    emojis,
    fetchingEmojis: state.emojis.fetching,
    fetching: state.quotes.fetching,
    currentQuote
  };
}

const mapDispatchToProps = {
  fetchRandomQuote,
  addReaction,
  deleteReaction,
  fetchEmojis
};

const LoginToSeeQuotes = () => <div>Logg inn for å se sitater.</div>;

export default compose(
  replaceUnlessLoggedIn(LoginToSeeQuotes),
  prepare((props, dispatch) =>
    Promise.all([dispatch(fetchRandomQuote()), dispatch(fetchEmojis())])
  ),
  connect(
    mapStateToProps,
    mapDispatchToProps
  ),
  loadingIndicator(['currentQuote.id'])
)(RandomQuote);

@@ -58,24 +58,58 @@
 om 'redux';%0A
+import %7B isEmpty %7D from 'lodash';%0A
 import prepa
@@ -1171,16 +1171,76 @@
 uotes),%0A
+  connect(%0A    mapStateToProps,%0A    mapDispatchToProps%0A  ),%0A
   prepar
@@ -1279,16 +1279,54 @@
 se.all(%5B
+%0A      isEmpty(props.currentQuote) && 
 dispatch
@@ -1346,16 +1346,22 @@
 uote()),
+%0A     
  dispatc
@@ -1380,70 +1380,15 @@
 s())
-%5D)
 %0A  
-),%0A  connect(%0A    mapStateToProps,%0A    mapDispatchToProps
+  %5D)
 %0A  )

Fix double/triple fetching of random quote