Commit 8229b545 authored by Clement Ho's avatar Clement Ho

Refactor to use class name to determine state

parent 75e0ec0f
...@@ -78,42 +78,36 @@ class FilteredSearchManager { ...@@ -78,42 +78,36 @@ class FilteredSearchManager {
} }
bindStateEvents() { bindStateEvents() {
const stateFilters = document.querySelector('.container-fluid .issues-state-filters'); this.stateFilters = document.querySelector('.container-fluid .issues-state-filters');
if (stateFilters) { if (this.stateFilters) {
this.searchStateOpened = this.search.bind(this, 'opened'); this.searchStateWrapper = this.searchState.bind(this);
this.searchStateMerged = this.search.bind(this, 'merged');
this.searchStateClosed = this.search.bind(this, 'closed'); this.stateFilters.querySelector('.state-opened')
this.searchStateAll = this.search.bind(this, 'all'); .addEventListener('click', this.searchStateWrapper);
this.stateFilters.querySelector('.state-closed')
stateFilters.querySelector('.state-opened') .addEventListener('click', this.searchStateWrapper);
.addEventListener('click', this.searchStateOpened); this.stateFilters.querySelector('.state-all')
stateFilters.querySelector('.state-closed') .addEventListener('click', this.searchStateWrapper);
.addEventListener('click', this.searchStateClosed);
stateFilters.querySelector('.state-all') this.mergedState = this.stateFilters.querySelector('.state-merged');
.addEventListener('click', this.searchStateAll); if (this.mergedState) {
this.mergedState.addEventListener('click', this.searchStateWrapper);
const mergedState = stateFilters.querySelector('.state-merged');
if (mergedState) {
mergedState.addEventListener('click', this.searchStateMerged);
} }
} }
} }
unbindStateEvents() { unbindStateEvents() {
const stateFilters = document.querySelector('.container-fluid .issues-state-filters'); if (this.stateFilters) {
this.stateFilters.querySelector('.state-opened')
if (stateFilters) { .removeEventListener('click', this.searchStateWrapper);
stateFilters.querySelector('.state-opened') this.stateFilters.querySelector('.state-closed')
.removeEventListener('click', this.searchStateOpened); .removeEventListener('click', this.searchStateWrapper);
stateFilters.querySelector('.state-closed') this.stateFilters.querySelector('.state-all')
.removeEventListener('click', this.searchStateClosed); .removeEventListener('click', this.searchStateWrapper);
stateFilters.querySelector('.state-all')
.removeEventListener('click', this.searchStateAll); if (this.mergedState) {
this.mergedState.removeEventListener('click', this.searchStateWrapper);
const mergedState = stateFilters.querySelector('.state-merged');
if (mergedState) {
mergedState.removeEventListener('click', this.searchStateMerged);
} }
} }
} }
...@@ -504,6 +498,15 @@ class FilteredSearchManager { ...@@ -504,6 +498,15 @@ class FilteredSearchManager {
} }
} }
searchState(e) {
const target = e.currentTarget;
// return class name that has a prefix of `state-`
const stateClassName = [].find.call(target.classList, name => name.match(/(state-)(\w+)/g));
const state = stateClassName.replace('state-', '');
this.search(state);
}
search(state = null) { search(state = null) {
const paths = []; const paths = [];
const searchQuery = gl.DropdownUtils.getSearchQuery(); const searchQuery = gl.DropdownUtils.getSearchQuery();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment