diff --git a/trade-hub/frontend/src/app.js b/trade-hub/frontend/src/app.js index d4a9244..2d9f78e 100644 --- a/trade-hub/frontend/src/app.js +++ b/trade-hub/frontend/src/app.js @@ -17,7 +17,7 @@ const state = { totalPages: 1, view: "catalog", user: null, - inventory: { search: "", category: "" }, + inventory: { search: "", category: "", sort: "name" }, }; let authMode = "login"; @@ -32,7 +32,7 @@ function cacheElements() { "error-banner", "loading", "empty-state", "results-grid", "pagination", "prev-page", "next-page", "page-info", "modal-backdrop", "modal-close", "modal-title", "modal-body", - "catalog-view", "inventory-view", "inv-search", "inv-category", + "catalog-view", "inventory-view", "inv-search", "inv-category", "inv-sort", "inv-summary", "inv-empty", "inv-table-wrap", "inv-tbody", "tab-mine", "auth-backdrop", "auth-close", "auth-title", "auth-form", "auth-username", "auth-password", "auth-error", "auth-submit", @@ -394,8 +394,10 @@ function showCatalogView() { function resetInventoryView() { state.inventory.search = ""; state.inventory.category = ""; + state.inventory.sort = "name"; els["inv-search"].value = ""; els["inv-category"].value = ""; + els["inv-sort"].value = "name"; els["inv-summary"].textContent = ""; renderInventory({ total: 0, items: [] }); } @@ -404,6 +406,7 @@ async function loadInventory() { const params = new URLSearchParams(); if (state.inventory.search) params.set("search", state.inventory.search); if (state.inventory.category) params.set("category", state.inventory.category); + params.set("sort", state.inventory.sort); params.set("page", "1"); params.set("page_size", String(INVENTORY_PAGE_SIZE)); @@ -674,6 +677,10 @@ function bindInventoryEvents() { state.inventory.category = els["inv-category"].value; loadInventory(); }); + els["inv-sort"].addEventListener("change", () => { + state.inventory.sort = els["inv-sort"].value; + loadInventory(); + }); } /* ---------- boot ---------- */ diff --git a/trade-hub/frontend/src/index.html b/trade-hub/frontend/src/index.html index 8d769b7..5fac2af 100644 --- a/trade-hub/frontend/src/index.html +++ b/trade-hub/frontend/src/index.html @@ -68,6 +68,12 @@ +