Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 367 - Tagger - Added global array to track the tag order #368

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions tools/tagger/tagger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let selectedOrder = [];

function renderItems(items, catId) {
let html = '';
items.forEach((tag) => {
Expand Down Expand Up @@ -66,6 +68,17 @@ function filter() {

function toggleTag(target) {
target.classList.toggle('selected');
const { title } = target.querySelector('.tag').dataset;
const category = target.closest('.category').querySelector('h2').textContent; // Assuming category title is in h2
const tagIdentifier = { title, category };

if (target.classList.contains('selected')) {
selectedOrder.push(tagIdentifier); // Add to the selection order
} else {
selectedOrder = selectedOrder.filter(
(item) => item.title !== title || item.category !== category,
);
}
// eslint-disable-next-line no-use-before-define
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea leaving this comment in here

displaySelected();
}
Expand All @@ -76,20 +89,33 @@ function displaySelected() {
const toCopyBuffer = [];

selTagsEl.innerHTML = '';
const selectedTags = document.querySelectorAll('#results .path.selected');
if (selectedTags.length > 0) {
selectedTags.forEach((path) => {
selectedOrder.forEach(({ title, category }) => {
// Find the category element
const categories = document.querySelectorAll('#results .category');
let path;
categories.forEach((cat) => {
if (cat.querySelector('h2').textContent === category) {
const tag = Array.from(cat.querySelectorAll('.tag')).find((t) => t.dataset.title === title);
if (tag) {
path = tag.closest('.path');
}
}
});

if (path) {
const clone = path.cloneNode(true);
clone.classList.remove('filtered', 'selected');
const tag = clone.querySelector('.tag');
tag.innerHTML = tag.dataset.title;
clone.addEventListener('click', () => {
toggleTag(path);
});
toCopyBuffer.push(tag.dataset.title);
toCopyBuffer.push(`${tag.dataset.title}`);
7r0u8l3 marked this conversation as resolved.
Show resolved Hide resolved
selTagsEl.append(clone);
});
}
});

if (selectedOrder.length > 0) {
helms-charity marked this conversation as resolved.
Show resolved Hide resolved
selEl.classList.remove('hidden');
} else {
selEl.classList.add('hidden');
Expand All @@ -113,11 +139,20 @@ async function init() {
copyButton.disabled = true;
});

selEl.querySelector('button.clear').addEventListener('click', () => {
const selectedTags = document.querySelectorAll('#results .path.selected');
selectedTags.forEach((tag) => {
toggleTag(tag);
const clearButton = selEl.querySelector('button.clear');
clearButton.addEventListener('click', () => {
// Remove the 'filtered' class from all tags
document.querySelectorAll('#results .tag').forEach((tag) => {
tag.closest('.path').classList.remove('filtered');
});

// Remove the 'selected' class from all selected tags
document.querySelectorAll('.selected').forEach((selectedTag) => {
selectedTag.classList.remove('selected');
});

selectedOrder = [];
displaySelected();
copyButton.disabled = false;
});

Expand Down