import { 
  START_LOADING_ALL_TOPICS,
  LOADED_ALL_TOPICS,
  START_LOADING_RANDOM_TOPIC,
  LOADED_RANDOM_TOPIC 
} from '../actions/action_types';

export default function(state={}, action) {
  switch (action.type) {

    case START_LOADING_ALL_TOPICS:
      return Object.assign({}, state, { loadingAllTopics: true });

    case LOADED_ALL_TOPICS:
      return Object.assign({}, state, {
        loadingAllTopics: false,
        allTopics: action.payload
      });

    case START_LOADING_RANDOM_TOPIC:
      return Object.assign({}, state, {
        loadingRandomTopic: true
      });

    case LOADED_RANDOM_TOPIC:
      return Object.assign({}, state, {
        loadingRandomTopic: false,
        randomTopic: action.payload.topic.name,
        randomTopicCount: action.payload.topic.items,
        randomTopicVideos: action.payload.videos
      });

    default:
      return state;
  }
};