cherrypick 4a88f72491 fix the status bar i think idk ai made weird ass shit i have to fix them bugs now

This commit is contained in:
lda
2025-09-04 23:37:55 +07:00 Unverified
parent 68377dcae7
commit 3006bae640
3 changed files with 26 additions and 10 deletions
+12 -2
View File
@@ -1,6 +1,8 @@
import { filter_array } from "./status.js";
export const qs = new URLSearchParams(location.search);
// not real cuh
// $ is normally queryselector are we fr
export const $ = (id) => document.getElementById(id);
export const elName = $("name");
export const elCheck = $("check");
@@ -17,10 +19,18 @@ export function setPill(kind, text) {
pill.textContent = text;
}
export function setLink(name) {
export function setLink(name, clear) {
if (clear) location.search = "";
const url = new URL(location.href);
/* const hasExtraFilters = filter_array.some(
(k) => url.searchParams.getAll(k).length
);
if (hasExtraFilters) {
// jus returns whatever; they are specifying further
} else */ {
if (name) url.searchParams.set("name", name);
else url.searchParams.delete("name");
}
history.replaceState(null, "", url);
link.href = url.toString();
}
+7 -1
View File
@@ -42,7 +42,7 @@ function pickTarget(value) {
elName.value = v;
updatePreview();
saveName(v);
setLink(v);
setLink(v, true);
fetchStatus(v);
fetchLeases();
}
@@ -74,10 +74,16 @@ const initial = loadName(qs);
if (initial) {
elName.value = initial;
updatePreview();
if (qs.has("name")) {
setLink(initial);
fetchStatus(initial);
} else {
fetchStatus();
}
fetchLeases();
} else {
setPill("warn", "unknown");
updatePreview();
fetchStatus();
fetchLeases();
}
+3 -3
View File
@@ -8,8 +8,8 @@ const status_map = {
state: "state",
dev: "interface",
};
const filter_array = ["ip", "dev", "nud", "mac"];
export const status_array = Object.keys(status_map);
export const filter_array = ["ip", "dev", "nud", "mac"];
function buildStatusUrl(name) {
const hasExtraFilters = filter_array.some((k) => qs.getAll(k).length);
@@ -18,7 +18,7 @@ function buildStatusUrl(name) {
}
const u = new URL("/api/status", location.origin);
if (name) u.searchParams.set("name", name);
for (const k of Object.keys(status_map)) {
for (const k of filter_array) {
const vals = qs.getAll(k);
for (const v of vals) u.searchParams.append(k, v);
}