|
|
|
@ -17,7 +17,7 @@
|
|
|
|
|
import {
|
|
|
|
|
dom, COLUMN, COLUMN_LITERAL, COMPARISON, ATTRIBUTES,
|
|
|
|
|
columnAscendingByDefault, columnIsSortable, COLUMN_TRANSFORMATION,
|
|
|
|
|
element, JOIN_URL_PASTE, communityQRCodeURL, STAFF_ID_PASTE, IDENTIFIER_PASTE, DETAILS_LINK_PASTE, CLASSES
|
|
|
|
|
element, JOIN_URL_PASTE, communityQRCodeURL, STAFF_ID_PASTE, IDENTIFIER_PASTE, DETAILS_LINK_PASTE, CLASSES, flagToLanguageAscii
|
|
|
|
|
} from './js/constants.js';
|
|
|
|
|
|
|
|
|
|
// Hidden communities for transparency.
|
|
|
|
@ -450,6 +450,7 @@ function addServerIconInteractions() {
|
|
|
|
|
|
|
|
|
|
function addSearchInteractions() {
|
|
|
|
|
dom.btn_toggle_search()?.addEventListener('click', function (ev) {
|
|
|
|
|
location.hash="#";
|
|
|
|
|
const container = dom.search_container();
|
|
|
|
|
container?.classList.toggle(CLASSES.COMPONENTS.COLLAPSED);
|
|
|
|
|
if (!container?.classList.contains(CLASSES.COMPONENTS.COLLAPSED)) {
|
|
|
|
@ -479,6 +480,12 @@ function addSearchInteractions() {
|
|
|
|
|
searchBar?.focus();
|
|
|
|
|
searchBar.value = "";
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Array.from(dom.sample_searches()).forEach(button => button.addEventListener('click', function() {
|
|
|
|
|
const targetSearch = button.getAttribute(ATTRIBUTES.SEARCH.TARGET_SEARCH);
|
|
|
|
|
useSearchTerm(targetSearch);
|
|
|
|
|
dom.search_bar().value = targetSearch;
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -613,7 +620,6 @@ const communityFullRowCache = [];
|
|
|
|
|
function initializeSearch() {
|
|
|
|
|
communityFullRowCache.push(...dom.tbl_communities_content_rows());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} [rawTerm]
|
|
|
|
@ -623,15 +629,27 @@ function useSearchTerm(rawTerm) {
|
|
|
|
|
replaceRowsWith(communityFullRowCache);
|
|
|
|
|
dom.search_bar()?.classList.remove(CLASSES.SEARCH.NO_RESULTS);
|
|
|
|
|
} else {
|
|
|
|
|
const term = rawTerm.toLowerCase();
|
|
|
|
|
const term = rawTerm.toLowerCase().replace(/lang:(\S+)/g, "").trim();
|
|
|
|
|
const termTags = Array.from(rawTerm.matchAll(/#[^#\s]+/g)).map(match => match[0].slice(1).toLowerCase());
|
|
|
|
|
const termLanguage = rawTerm.match(/lang:(\S+)/)?.[1];
|
|
|
|
|
console.log(termLanguage);
|
|
|
|
|
const newRows = communityFullRowCache.filter(
|
|
|
|
|
row => {
|
|
|
|
|
const rowInfo = dom.row_info(row);
|
|
|
|
|
const langAscii = rowInfo.language_flag && flagToLanguageAscii(rowInfo.language_flag).toLowerCase();
|
|
|
|
|
const rowName = rowInfo.name.toLowerCase();
|
|
|
|
|
const rowDesc = rowInfo.description.toLowerCase();
|
|
|
|
|
const rowTags = rowInfo.tags.map(({text}) => text);
|
|
|
|
|
return rowInfo.name.toLowerCase().includes(term) ||
|
|
|
|
|
rowInfo.description.toLowerCase().includes(term) ||
|
|
|
|
|
(termTags.length >= 1 && termTags.some(tag => rowTags.some(rowTag => rowTag.includes(tag))))
|
|
|
|
|
if (termLanguage && !langAscii.includes(termLanguage.toLowerCase())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (termTags.length >= 1) {
|
|
|
|
|
if (termTags.some(tag => rowTags.some(rowTag => rowTag.includes(tag)))) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rowName.includes(term) || rowDesc.includes(term);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
if (newRows.length === 0) {
|
|
|
|
|