Skip to content

Commit

Permalink
Merge pull request #28 from AmarOk1412/query_param
Browse files Browse the repository at this point in the history
accept query parameters (for tags and categories)
  • Loading branch information
captainbrosset committed Oct 14, 2016
2 parents 88d4bef + 5a791ae commit e2dab05
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions app.js
Expand Up @@ -13,6 +13,40 @@ function hasFilter(name, filters) {
return false;
}

function getParameterByName(name) {
var params = new URL(window.location).searchParams;
var value = params.get(name);

if (value) {
return decodeURIComponent(value.replace(/\+/g, " "));
}

if (params.has(name)) {
return "";
}

return null;
}

function setFiltersFromUrlParams() {
var easy = getParameterByName("easy");
var mentored = getParameterByName("mentored");

if (easy === "") {
document.getElementById("good-first").checked = true;
if (mentored === null) {
document.getElementById("mentored").checked = false;
}
}

if (mentored === "") {
document.getElementById("mentored").checked = true;
if (easy === null) {
document.getElementById("good-first").checked = false;
}
}
}

function getSearchParams(options) {
options = options || {};

Expand Down Expand Up @@ -134,6 +168,7 @@ function getToolTooltip(id) {

function createToolListMarkup(parentEl) {
var keys = Object.keys(COMPONENT_MAPPING);
var toolInUrl = getParameterByName("tool");
for (var i = 0; i < keys.length; i++) {
var el = createNode({tagName: "li"});

Expand All @@ -147,6 +182,10 @@ function createToolListMarkup(parentEl) {
}
});

if (toolInUrl === keys[i]) {
input.checked = true;
}

var label = createNode({
tagName: "label",
textContent: COMPONENT_MAPPING[keys[i]].label,
Expand Down Expand Up @@ -260,8 +299,8 @@ function createBugMarkup(bug) {
"title": "This bug is mentored, even if you have never contributed before, someone will help you"
},
textContent: bug.mentors ? "Mentor: " + bug.mentors_detail.map(function(m) {
return m.real_name;
})[0] : "",
return m.real_name;
})[0] : "",
}));
}

Expand Down Expand Up @@ -487,6 +526,8 @@ function displayContributor(contributor, rootEl) {
}

function init() {
setFiltersFromUrlParams();

// Start by generating the list of filters for tools.
createToolListMarkup(document.querySelector(".tools-list"));

Expand Down

0 comments on commit e2dab05

Please sign in to comment.