<commit_before>
import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
import FlatButton from 'material-ui/FlatButton';
import FontIcon from 'material-ui/FontIcon';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import IconButton from 'material-ui/IconButton';
import RaisedButton from 'material-ui/RaisedButton';
import TextField from 'material-ui/TextField';
import {debounce} from 'throttle-debounce';


Header = React.createClass({

	propTypes: {
		toggleSearchTerm: React.PropTypes.func,
		handleChangeTextsearch: React.PropTypes.func,
		handleChangeLineN: React.PropTypes.func
	},

  getChildContext() {
    return { muiTheme: getMuiTheme(baseTheme) };
  },

  childContextTypes: {
    muiTheme: React.PropTypes.object.isRequired,
  },

  getInitialState(){
    return {
      leftMenuOpen : false,
      searchEnabled : false,
      searchDropdownOpen : "",
			subworks: [],
			lineMin: 0,
			lineMax: 2000,
			activeWork: ""
    };
  },

  mixins: [ReactMeteorData],

  getMeteorData(){
    var query = {};

		return {
			keywords: Keywords.find().fetch(),
			commenters: Commenters.find().fetch(),
			works: Works.find({}, {sort:{order:1}}).fetch(),
			subworks: Subworks.find({}, {sort:{n:1}}).fetch(),
		}
	},

	componentDidMount(){
		if(location.pathname.indexOf("/commentary") === 0){
	    this.setState({
	      searchEnabled : true
	    });

		}else {
	    this.setState({
	      searchEnabled : false
			});

		}

	},

  toggleSearchMode(){

		if(location.pathname.indexOf("/commentary") === 0){
	    this.setState({
	      searchEnabled : !this.state.searchEnabled
	    });

		}else {
			location.href = "/commentary";
		}
  },

  toggleLeftMenu(){
    this.setState({
      leftMenuOpen : !this.state.leftMenuOpen
    });
  },

  closeLeftMenu(){
    this.setState({
      leftMenuOpen : false
    });
  },

  toggleSearchDropdown(targetDropdown){
		if(this.state.searchDropdownOpen === targetDropdown){
	    this.setState({
				searchDropdownOpen : ""
	    });

		}else {
	    this.setState({
				searchDropdownOpen : targetDropdown
	    });

		}
  },

	toggleSearchTerm(key, value){
		this.props.toggleSearchTerm(key, value);

	},

	toggleWorkSearchTerm(key, value){
		var work = value;

		value.subworks.forEach(function(subwork){
			subwork.work = work;
		});

		//console.log("Header.state", this.state);

		if(this.state.activeWork === value.slug){
			this.setState({
				subworks: [],
				activeWork: ""
			});

		}else {
			this.setState({
				subworks: value.subworks,
				activeWork: value.slug
			});

		}

		this.props.toggleSearchTerm(key, value);

	},

  render(){<commit_msg>sort subworks in search tools<commit_after>
import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
import FlatButton from 'material-ui/FlatButton';
import FontIcon from 'material-ui/FontIcon';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import IconButton from 'material-ui/IconButton';
import RaisedButton from 'material-ui/RaisedButton';
import TextField from 'material-ui/TextField';
import {debounce} from 'throttle-debounce';


Header = React.createClass({

	propTypes: {
		toggleSearchTerm: React.PropTypes.func,
		handleChangeTextsearch: React.PropTypes.func,
		handleChangeLineN: React.PropTypes.func
	},

  getChildContext() {
    return { muiTheme: getMuiTheme(baseTheme) };
  },

  childContextTypes: {
    muiTheme: React.PropTypes.object.isRequired,
  },

  getInitialState(){
    return {
      leftMenuOpen : false,
      searchEnabled : false,
      searchDropdownOpen : "",
			subworks: [],
			lineMin: 0,
			lineMax: 2000,
			activeWork: ""
    };
  },

  mixins: [ReactMeteorData],

  getMeteorData(){
    var query = {};

		return {
			keywords: Keywords.find().fetch(),
			commenters: Commenters.find().fetch(),
			works: Works.find({}, {sort:{order:1}}).fetch(),
			subworks: Subworks.find({}, {sort:{n:1}}).fetch(),
		}
	},

	componentDidMount(){
		if(location.pathname.indexOf("/commentary") === 0){
	    this.setState({
	      searchEnabled : true
	    });

		}else {
	    this.setState({
	      searchEnabled : false
			});

		}

	},

  toggleSearchMode(){

		if(location.pathname.indexOf("/commentary") === 0){
	    this.setState({
	      searchEnabled : !this.state.searchEnabled
	    });

		}else {
			location.href = "/commentary";
		}
  },

  toggleLeftMenu(){
    this.setState({
      leftMenuOpen : !this.state.leftMenuOpen
    });
  },

  closeLeftMenu(){
    this.setState({
      leftMenuOpen : false
    });
  },

  toggleSearchDropdown(targetDropdown){
		if(this.state.searchDropdownOpen === targetDropdown){
	    this.setState({
				searchDropdownOpen : ""
	    });

		}else {
	    this.setState({
				searchDropdownOpen : targetDropdown
	    });

		}
  },

	toggleSearchTerm(key, value){
		this.props.toggleSearchTerm(key, value);

	},

	toggleWorkSearchTerm(key, value){
		var work = value;

		value.subworks.forEach(function(subwork){
			subwork.work = work;
		});

		//console.log("Header.state", this.state);

		if(this.state.activeWork === value.slug){
			this.setState({
				subworks: [],
				activeWork: ""
			});

		}else {
			value.subworks.sort(function(a, b){
			  if (a.n < b.n)
			    return -1;
			  if (a.n > b.n)
			    return 1;
			  return 0;

			});
			this.setState({
				subworks: value.subworks,
				activeWork: value.slug
			});

		}

		this.props.toggleSearchTerm(key, value);

	},

  render(){
{'fraction_non_alphanumeric': 0.15089466888028039, 'fraction_numerical': 0.00387382401770891, 'mean_word_length': 3.2592301649646505, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4976805', 'n_tokens_mistral': 2026, 'n_tokens_neox': 1769, 'n_words': 301}