move global search input to a general location

- create a global search store
- create a half-baked context menu store
-
This commit is contained in:
geoffrey45
2022-03-12 08:56:38 +03:00
parent 39fba364d3
commit 658e7cdbb7
21 changed files with 538 additions and 245 deletions
+34
View File
@@ -0,0 +1,34 @@
import perks from "./perks";
export default function normalizeContextMenu(x, y) {
const app_dom = perks.getElem("app", "id");
const context_menu = perks.getElem("context-menu-visible", "class");
const { left: scopeOffsetX, top: scopeOffsetY } =
app_dom.getBoundingClientRect();
const scopeX = x - scopeOffsetX;
const scopeY = y - scopeOffsetY;
const outOfBoundsX = scopeX + context_menu.clientHeight > app_dom.clientWidth;
const outOfBoundsY =
scopeY + context_menu.clientHeight > app_dom.clientHeight;
let normalizedX = x;
let normalizedY = y;
if (outOfBoundsX) {
normalizedX =
scopeOffsetX + app_dom.clientWidth - context_menu.clientHeight;
}
if (outOfBoundsY) {
normalizedY =
scopeOffsetY + app_dom.clientHeight - context_menu.clientHeight;
}
return {
normalizedX,
normalizedY,
};
}
+3
View File
@@ -212,6 +212,8 @@ window.addEventListener("keyup", () => {
key_down_fired = false;
});
function formatSeconds(seconds) {
// check if there are arguments
@@ -258,6 +260,7 @@ export default {
focusCurrent,
updateQueue,
formatSeconds,
getElem,
current,
queue,
next,
+2 -2
View File
@@ -1,10 +1,10 @@
import state from "./state.js";
const base_url = "http://0.0.0.0:9876/search?q=";
const base_url = `${state.settings.uri}/search?q=`;
async function search(query) {
state.loading.value = true;
const url = base_url + encodeURIComponent(query);
const url = base_url + encodeURIComponent(query.trim());
const res = await fetch(url);