import { call, put, takeLatest } from 'redux-saga/effects';
// import { schema, normalize } from 'normalizr';
import * as Api from '../../services/api';
import * as types from './constants';

// Individual exports for testing
export function* getSidebar() {
  try {
    const result = yield call(Api.getSidebar);
    const sidebar = result.response.sidebar;
    yield put({ type: types.GET_SIDEBAR_SUCCESS, sidebar });
  } catch (error) {
    yield put({ type: types.GET_SIDEBAR_FAILURE, error });
  }
}


function* watchgetSidebar() {
  yield takeLatest(types.GET_SIDEBAR_REQUEST, getSidebar);
}

// All sagas to be loaded
export default [
  watchgetSidebar,
];
