Skip to content

Commit

Permalink
feat: show single package search-nav
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreDemailly committed Jan 6, 2025
1 parent 1c32b69 commit feceeae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
33 changes: 26 additions & 7 deletions public/core/search-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import { createDOMElement, parseNpmSpec } from "../common/utils";
import { SearchBar } from "../components/searchbar/searchbar";

export function initSearchNav(data, options) {
const { initFromZero = true, searchOptions = null } = options;
const { initFromZero = true, searchOptions = null, initSinglePackage } = options;

const searchNavElement = document.getElementById("search-nav");
if (!searchNavElement) {
throw new Error("Unable to found search navigation");
}

if (initFromZero) {
if (initSinglePackage) {
searchNavElement.innerHTML = "";
searchNavElement.appendChild(
initSingleNavigation(initSinglePackage)
);
}
else if (initFromZero) {
searchNavElement.innerHTML = "";
searchNavElement.appendChild(
initPackagesNavigation(data)
Expand Down Expand Up @@ -123,9 +129,22 @@ function renderPackageRemoveButton(packageName, options) {
return removeButton;
}

export function hideSearchNav() {
const searchNavElement = document.getElementById("search-nav");
if (searchNavElement) {
searchNavElement.classList.add("hidden");
}
function initSingleNavigation(packageName) {
const fragment = document.createDocumentFragment();
const container = createDOMElement("div", {
classList: ["packages"]
});

const pkgElement = createDOMElement("div", {
classList: ["package"],
childs: [
createDOMElement("p", { text: packageName })
]
});
pkgElement.dataset.name = packageName;

container.appendChild(pkgElement);
fragment.append(container);

return fragment;
}
14 changes: 11 additions & 3 deletions public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SearchView } from "./components/views/search/search.js";
// Import Core Components
import { NetworkNavigation } from "./core/network-navigation.js";
import { i18n } from "./core/i18n.js";
import { initSearchNav, hideSearchNav } from "./core/search-nav.js";
import { initSearchNav } from "./core/search-nav.js";

// Import Utils
import * as utils from "./common/utils.js";
Expand All @@ -36,7 +36,6 @@ document.addEventListener("DOMContentLoaded", async() => {
if (window.settings.config.standalone) {
console.log(`[INFO] Standalone mode activated`);
window.navigation.hideMenu("search--view", { navigateAway: true });
hideSearchNav();
}
window.i18n = await new i18n().fetch();
window.wiki = new Wiki();
Expand Down Expand Up @@ -114,7 +113,16 @@ async function init(options = {}) {
window.locker = new Locker(nsn);
window.legend = new Legend({ show: window.settings.config.showFriendlyDependencies });
new HomeView(secureDataSet, nsn);
if (window.settings.config.standalone === false) {
if (window.settings.config.standalone) {
window.activePackage = secureDataSet.data.rootDependencyName;
initSearchNav(void 0, {
initSinglePackage: secureDataSet.data.rootDependencyName,
searchOptions: {
nsn, secureDataSet
}
});
}
else {
searchview ??= new SearchView(secureDataSet, nsn);
}

Expand Down

0 comments on commit feceeae

Please sign in to comment.