Skip to content

Commit

Permalink
all changes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorhelene authored and svrnm committed Nov 11, 2024
1 parent e846f4a commit c1d59d4
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions assets/js/registrySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let pathName = window.location.pathname;
let searchQuery = '';
let selectedLanguage = 'all';
let selectedComponent = 'all';
let selectedFlag = 'all'; // Added selectedFlag
let selectedFlag = 'all'; // Added selectedFlag

parseUrlParams();

Expand All @@ -51,22 +51,30 @@ if (pathName.includes('registry')) {
}

// Set the dropdown values from query params
if (selectedLanguage !== 'all' || selectedComponent !== 'all' || selectedFlag !== 'all') {
if (
selectedLanguage !== 'all' ||
selectedComponent !== 'all' ||
selectedFlag !== 'all'
) {
if (selectedLanguage !== 'all') {
document.getElementById('languageDropdown').textContent =
document.getElementById(`language-item-${selectedLanguage}`).textContent;
document.getElementById(
`language-item-${selectedLanguage}`,
).textContent;
}
if (selectedComponent !== 'all') {
document.getElementById('componentDropdown').textContent =
document.getElementById(`component-item-${selectedComponent}`).textContent;
document.getElementById(
`component-item-${selectedComponent}`,
).textContent;
}
if (selectedFlag !== 'all') {
document.getElementById('flagsDropdown').textContent =
document.getElementById(`flag-item-${selectedFlag}`).textContent;
}
updateFilters();
}

document.addEventListener('DOMContentLoaded', (event) => {
let searchForm = document.getElementById('searchForm');
searchForm.addEventListener('submit', function (evt) {
Expand Down Expand Up @@ -108,22 +116,22 @@ if (pathName.includes('registry')) {
updateFilters();
}),
);
// Flags dropdown event listener
// Flags dropdown event listener

let flagList = document
.getElementById('flagsFilter')
.querySelectorAll('.dropdown-item');
.getElementById('flagsFilter')
.querySelectorAll('.dropdown-item');

flagList.forEach((element) =>
element.addEventListener('click', function (evt) {
let val = evt.target.getAttribute('value');
selectedFlag = val;
document.getElementById('flagsDropdown').textContent = evt.target.textContent;
setInput('flag', val);
updateFilters();
})
element.addEventListener('click', function (evt) {
let val = evt.target.getAttribute('value');
selectedFlag = val;
document.getElementById('flagsDropdown').textContent =
evt.target.textContent;
setInput('flag', val);
updateFilters();
}),
);

});
}

Expand Down Expand Up @@ -229,25 +237,35 @@ function setInput(key, value) {
// Filters items based on language, component and flags
function updateFilters() {
let allItems = [...document.getElementsByClassName('registry-entry')];
if (selectedComponent === 'all' && selectedLanguage === 'all' && selectedFlag === 'all') {
if (
selectedComponent === 'all' &&
selectedLanguage === 'all' &&
selectedFlag === 'all'
) {
// Show all items if all filters are set to 'all'
allItems.forEach((element) => element.classList.remove('d-none'));
} else {
// Apply the filters
allItems.forEach((element) => {
const dc = element.dataset.registrytype;
const dl = element.dataset.registrylanguage;
const df = element.dataset.registryflags ? element.dataset.registryflags.split(' ').map(f => f.toLowerCase()) : [];
const df = element.dataset.registryflags
? element.dataset.registryflags.split(' ').map((f) => f.toLowerCase())
: [];

const componentMatches = (dc === selectedComponent || selectedComponent === 'all');
const languageMatches = (dl === selectedLanguage || selectedLanguage === 'all');
const flagMatches = (selectedFlag === 'all' || df.includes(selectedFlag.toLowerCase()));
const componentMatches =
dc === selectedComponent || selectedComponent === 'all';
const languageMatches =
dl === selectedLanguage || selectedLanguage === 'all';
const flagMatches =
selectedFlag === 'all' || df.includes(selectedFlag.toLowerCase());

if (flagMatches) {
console.log('Flag matches:', df);
}

if (componentMatches && languageMatches && flagMatches) { // Changed
if (componentMatches && languageMatches && flagMatches) {
// Changed
element.classList.remove('d-none');
} else {
element.classList.add('d-none');
Expand Down

0 comments on commit c1d59d4

Please sign in to comment.