Skip to content

Commit

Permalink
Refactor createURL methods
Browse files Browse the repository at this point in the history
Removed createURLFromX method, as the previous commit solved most of the issues in #6.
Refactored createURL to remove change argument.
  • Loading branch information
MrSpiffyClean authored May 10, 2020
1 parent e40a3f4 commit 8d32eb8
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions vue-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ window.app = new Vue({
}

this.firstLoad = false;
this.createURLFromChange();
this.createURL();
},

preprocessNYTData(data, type) {
Expand Down Expand Up @@ -545,27 +545,19 @@ window.app = new Vue({

selectAll() {
this.selectedCountries = this.countries;
this.createURL(true);
this.createURL();
},

deselectAll() {
this.selectedCountries = [];
this.createURL(true);
this.createURL();
},

toggleHide() {
this.isHidden = !this.isHidden;
},

createURLFromChange() {
this.createURL(true);
},

createURLFromRegion() {
this.createURL(false);
},

createURL(change) {
createURL() {

let baseUrl = window.location.href.split('?')[0];

Expand Down Expand Up @@ -596,20 +588,19 @@ window.app = new Vue({

// check if the list of countries has all or none of the countries
// if all or none of the countries have been selected, then the later checks don't need to be done
if (change) {
if (this.selectedCountries.length === this.countries.length) {
queryUrl.append('select', 'all');
let url = baseUrl + '?' + queryUrl.toString();
window.history.replaceState({}, 'Covid Trends', '?' + queryUrl.toString());
return;
} else if (this.selectedCountries.length === 0) {
queryUrl.append('select', 'none');
let url = baseUrl + '?' + queryUrl.toString();
window.history.replaceState({}, 'Covid Trends', '?' + queryUrl.toString());
return;
}
if (this.selectedCountries.length === this.countries.length) {
queryUrl.append('select', 'all');
let url = baseUrl + '?' + queryUrl.toString();
window.history.replaceState({}, 'Covid Trends', '?' + queryUrl.toString());
return;
} else if (this.selectedCountries.length === 0) {
queryUrl.append('select', 'none');
let url = baseUrl + '?' + queryUrl.toString();
window.history.replaceState({}, 'Covid Trends', '?' + queryUrl.toString());
return;
}


// check if the list of countries is identical to the current default
let defaultTag;
if (this.selectedCountries.length === this.defaultCountries.length) {
Expand All @@ -627,7 +618,7 @@ window.app = new Vue({
}

// only list all countries if a checkbox was changed and if the list of countries isn't in default
if (change && !defaultTag) {
if (!defaultTag) {
for (let country of this.countries) {
if (this.selectedCountries.includes(country)) {
if (Object.keys(renames).includes(country)) {
Expand Down

0 comments on commit 8d32eb8

Please sign in to comment.