From ba592377eac9a93fc71f54300b4e72014e59c5aa Mon Sep 17 00:00:00 2001 From: lzzfnc Date: Wed, 27 Oct 2021 10:50:42 +0200 Subject: [PATCH] filters wip --- cms.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- index.html | 5 +++++ style.css | 34 ++++++++++++++++++++++++++++++++++ updates.json | 11 +++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) diff --git a/cms.js b/cms.js index 7724a55..59c3102 100644 --- a/cms.js +++ b/cms.js @@ -1,6 +1,7 @@ -const updatesContainer = document.getElementById("updates-container"); -let updates = []; +// QUOTES HIGHLIGHT + let quotes = []; +let cards = []; let callback = (entries) => { entries.forEach((entry) => { @@ -11,6 +12,41 @@ let callback = (entries) => { }); }; +const filtersContainer = document.getElementById("filters"); +let filters = new Set(["dev", "daily", "research"]); + +filtersContainer.addEventListener("click", (e) => { + if (e.target.tagName === "LI") { + let category = e.target.getAttribute("data-tag"); + + // if (filters.size == 1) { + // filters = new Set(["dev", "daily", "research"]); + // [...filtersContainer.getElementsByClassName('tag')].forEach(tag =>) + // } else + if (filters.has(category)) { + e.target.classList.remove("active"); + filters.delete(category); + } else { + e.target.classList.add("active"); + filters.add(category); + } + } + showSelectedUpdates(); +}); + +function showSelectedUpdates() { + cards.forEach((card) => { + card.classList.remove("selected"); + let categories = card + .getAttribute("data-tag") + .split(",") + .map((tag) => tag.trim()); + categories.forEach((category) => { + if (filters.has(category)) card.classList.add("selected"); + }); + }); +} + // Threshold Callback let threshold = []; @@ -35,6 +71,8 @@ function highlight(text, offset) { ); } +// UPDATES + // Fetc the updates from the array in updates.json // Each element of the array is structured like this: // @@ -60,11 +98,15 @@ function highlight(text, offset) { // This is for accessibility. It's a really good practice to provide quality alt text // and we must pay attention to this. +const updatesContainer = document.getElementById("updates-container"); +let updates = []; + fetch("./updates.json") .then((response) => response.json()) .then((data) => { updates = [...data.updates.reverse()]; populateContents(); + showSelectedUpdates(); }); function populateContents() { @@ -74,6 +116,7 @@ function populateContents() { function createUpdate(update) { let card = document.createElement("div"); card.classList.add("update"); + card.setAttribute("data-tag", update.tag); // QUOTE @@ -155,4 +198,5 @@ function createUpdate(update) { card.appendChild(log); updatesContainer.appendChild(card); + cards.push(card); } diff --git a/index.html b/index.html index d02a8c0..86410dc 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,11 @@

updates

+