// @flow
/* global SETTINGS: false */
import React from 'react';
import { connect } from 'react-redux';
import {
  SearchkitManager,
  SearchkitProvider,
} from 'searchkit';
import _ from 'lodash';
import type { Dispatch } from 'redux';

import LearnerSearch from '../components/LearnerSearch';
import { setSearchFilterVisibility } from '../actions/ui';
import type { UIState } from '../reducers/ui';

class LearnerSearchPage extends React.Component {
  props: {
    ui:       UIState,
    dispatch: Dispatch,
  };

  checkFilterVisibility: Function = (filterName: string): boolean => {
    const { ui: { searchFilterVisibility } } = this.props;
    let visibility = searchFilterVisibility[filterName];
    return visibility === undefined ? false : visibility;
  };

  setFilterVisibility: Function = (filterName: string, visibility: boolean): void => {
    const { ui: { searchFilterVisibility }, dispatch } = this.props;
    let clone = _.clone(searchFilterVisibility);
    clone[filterName] = visibility;
    dispatch(setSearchFilterVisibility(clone));
  };

  render () {
    let searchKit = new SearchkitManager(SETTINGS.search_url);
    return (
      <SearchkitProvider searchkit={searchKit}>
        <LearnerSearch
          checkFilterVisibility={this.checkFilterVisibility}
          setFilterVisibility={this.setFilterVisibility}
        />
      </SearchkitProvider>
    );
  }
}

const mapStateToProps = state => {
  return {
    ui: state.ui,
  };
};

export default connect(mapStateToProps)(LearnerSearchPage);

@@ -393,16 +393,57 @@
 ers/ui';
+%0Aimport %7B getCookie %7D from '../util/api';
 %0A%0Aclass 
@@ -1170,16 +1170,100 @@
 arch_url
+, %7B%0A      httpHeaders: %7B%0A        'X-CSRFToken': getCookie('csrftoken')%0A      %7D%0A    %7D
 );%0A    r

Fix CSRF handling