Skip to content

Commit

Permalink
change filter from OR to AND
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleretters committed May 17, 2023
1 parent 4b8f825 commit 0210fd4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
3 changes: 3 additions & 0 deletions _layouts/explore.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ <h1>{{ project.raw_name }}</h1>
</a>
</div>
{% endfor %}
<div id="no-results">
<h1>no results.</h1>
</div>
</div>
23 changes: 22 additions & 1 deletion assets/javascript/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
}
// explore page tags
let activeTags = [];
const countVisibleProjects = () => {
const projectElements = document.getElementsByClassName('project');
let count = 0;
for (let i = 0; i < projectElements.length; i++) {
const element = projectElements[i];
if (element.classList.contains('show')) {
count++;
}
}
return count;
};
const refresh = () => {
console.log(activeTags);
// if there are no activeTags, show everything
Expand All @@ -73,14 +84,24 @@
return;
}
const projectTags = project.dataset.tags.split(' ');
if (activeTags.some(tag => projectTags.includes(tag))) {
if (activeTags.every(tag => projectTags.includes(tag))) {
project.classList.add('show');
}
else {
project.classList.remove('show');
}
}
});
// display a "no results" message
const noResults = document.getElementById('no-results');
if (noResults != undefined) {
if (countVisibleProjects() == 0) {
noResults.classList.add('show');
}
else {
noResults.classList.remove('show');
}
}
};
const tagClick = (button) => {
const activeClass = 'tag-active';
Expand Down
24 changes: 23 additions & 1 deletion assets/javascript/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@
// explore page tags
let activeTags : string[] = []

const countVisibleProjects = (): number => {
const projectElements = document.getElementsByClassName('project');
let count = 0;
for (let i = 0; i < projectElements.length; i++) {
const element = projectElements[i];
if (element.classList.contains('show')) {
count++;
}
}
return count;
}

const refresh = () => {
console.log(activeTags)
// if there are no activeTags, show everything
Expand All @@ -76,13 +88,23 @@
return
}
const projectTags = project.dataset.tags.split(' ')
if (activeTags.some(tag => projectTags.includes(tag))) {
if (activeTags.every(tag => projectTags.includes(tag))) {
project.classList.add('show')
} else {
project.classList.remove('show')
}
}
})

// display a "no results" message
const noResults = document.getElementById('no-results')
if (noResults != undefined) {
if (countVisibleProjects() == 0) {
noResults.classList.add('show')
} else {
noResults.classList.remove('show')
}
}
}

const tagClick = (button: HTMLElement) => {
Expand Down
4 changes: 4 additions & 0 deletions assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,8 @@ body.explore section {
.projects .project a h1,
.projects .project a p {
margin: 0 0 0.8em 0;
}

#no-results {
display: none;
}

0 comments on commit 0210fd4

Please sign in to comment.