don't recreate top-level file list when changing secondary category
This commit is contained in:
parent
cbae4403a0
commit
034ca5929a
1 changed files with 31 additions and 12 deletions
|
@ -45,16 +45,35 @@ function fetchWithType(url){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let previousCategory = new (function(){
|
let currentCategory = new (function(){
|
||||||
let current = null;
|
const currentPrimaryNode = null;
|
||||||
this.fileNames = null;
|
const currentSecondaryNode = null;
|
||||||
|
// TODO make filenames store ONLY the top level fileNames
|
||||||
|
//
|
||||||
|
|
||||||
|
let currentTopLevelFileNames = null;
|
||||||
|
|
||||||
this.set = function(t,secondary){
|
this.set = function(t,secondary){
|
||||||
current&¤t.classList.remove("currentCategory");
|
let targetNode;
|
||||||
current = t;
|
if(secondary){
|
||||||
current.classList.add("currentCategory");
|
targetNode = currentSecondaryNode;
|
||||||
|
}else{
|
||||||
this.fileNames = DB.query(t.textContent,secondary?this.fileNames:null);
|
targetNode = currentPrimaryNode;
|
||||||
|
}
|
||||||
|
targetNode && targetNode.classList.remove("currentCategory");
|
||||||
|
targetNode = t;
|
||||||
|
targetNode.classList.add("currentCategory");
|
||||||
|
!secondary && currentTopLevelFileNames = DB.query(t.textContent);
|
||||||
|
|
||||||
|
//this.fileNames = DB.query(t.textContent,secondary?this.fileNames:null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getFileNames = function(node,secondary){
|
||||||
|
if(secondary){
|
||||||
|
return DB.query(node.textContent,currentTopLevelFileNames)
|
||||||
|
}
|
||||||
|
return currentTopLevelFileNames
|
||||||
|
}
|
||||||
return this
|
return this
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
@ -82,16 +101,16 @@ function getSecondaryCategories(list){
|
||||||
|
|
||||||
async function onCategoryClicked(categoryNode,isSecondary = false){
|
async function onCategoryClicked(categoryNode,isSecondary = false){
|
||||||
|
|
||||||
previousCategory.set(categoryNode,isSecondary);
|
currentCategory.set(categoryNode,isSecondary);
|
||||||
// Using textContent is bad but meh
|
// Using textContent is bad but meh
|
||||||
//let names = DB.query(categoryNode.textContent);
|
//let names = DB.query(categoryNode.textContent);
|
||||||
|
|
||||||
let secondaryCategoriesNode = document.querySelector("#secondaryCategories");
|
let secondaryCategoriesNode = document.querySelector("#secondaryCategories");
|
||||||
|
|
||||||
if(!isSecondary){
|
if(!isSecondary){
|
||||||
|
let fileNames = currentCategory.getFileNames(categoryNode,false);
|
||||||
if(previousCategory.fileNames.length > 9){
|
if(fileNames.length > 9){
|
||||||
let matchingSecondaries = getSecondaryCategories(previousCategory.fileNames);
|
let matchingSecondaries = getSecondaryCategories(fileNames);
|
||||||
for(let child of Array.from(secondaryCategories.children)){
|
for(let child of Array.from(secondaryCategories.children)){
|
||||||
matchingSecondaries.includes(child.textContent) ? child.classList.remove("hidden") : child.classList.add("hidden")
|
matchingSecondaries.includes(child.textContent) ? child.classList.remove("hidden") : child.classList.add("hidden")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue