diff --git a/frontend/src/routes/search/Search.svelte b/frontend/src/routes/search/Search.svelte
index 39e5a680..9b49868f 100644
--- a/frontend/src/routes/search/Search.svelte
+++ b/frontend/src/routes/search/Search.svelte
@@ -8,11 +8,11 @@
import Bookmark from '../bookmark/Template.svelte';
- const router = useTinyRouter();
let fulltext = false;
- search.key = router.getQueryParam('key');
-
let counter = 0;
+ const router = useTinyRouter();
+ let key = $derived(router.getQueryParam('key'));
+ search.key = key;
let bookmarks = $state(null);
let companies = $state(null);
let documents = $state(null);
@@ -26,10 +26,20 @@
function doSearch(){
if (counter > 0) return;
- counter = 10;
warn(t('searching…'));
- console.log("doSearch");
- let data = { key : search.key, fulltext : fulltext };
+ counter = 10;
+ bookmarks = null;
+ companies = null;
+ documents = null;
+ notes = null;
+ pages = null;
+ projects = null;
+ stock = null;
+ tags = null;
+ tasks = null;
+ times = null;
+
+ let data = { key, fulltext : fulltext };
post(api('bookmark/search'),data).then(handleBookmarks);
post(api('company/search '),data).then(handleCompanies);
post(api('document/search'),data).then(handleDocuments);
@@ -113,28 +123,15 @@
}
}
- async function fetchMissing(module, id){
- }
async function handleTags(resp){
- quitOne();
if (resp.ok){
const json = await resp.json();
let map = {};
for (let [module, ids] of Object.entries(json)){
let list = {};
+ let path = module;
map[module] = {};
-/*
- let bookmarks = $state(null);
- let companies = $state(null);
- let documents = $state(null);
- let notes = $state(null);
- let pages = $state(null);
- let projects = $state(null);
- let stock = $state(null);
- let tags = $state(null);
- let tasks = $state(null);
- let times = $state(null);*/
switch(module){
case 'bookmark': {
if (!bookmarks) bookmarks = {};
@@ -167,9 +164,10 @@
break;
}
case 'stock': {
- if (!stock) stock = {};
- list = stock;
- break;
+ if (!stock) stock = { items : {}};
+ list = stock.items;
+ path = 'stock/item';
+ break;
}
case 'task': {
if (!tasks) tasks = {};
@@ -182,15 +180,13 @@
break;
}
default:{
- console.warn("no handler for "+module+" with tag "+search.key);
+ console.warn("no handler for "+module+" with tag "+key);
continue;
}
}
for (let id of ids){
- console.log("Trying to access "+module+"s:",list);
if (!list[id]) {
- const url = api(`${module}/${id}`);
- console.log("fetching from "+url);
+ const url = api(`${path}/${id}`);
const resp = await get(url);
if (resp.ok) {
list[id] = await resp.json();
@@ -205,6 +201,7 @@
} else {
error(resp);
}
+ quitOne();
}
async function handleTasks(resp){
@@ -239,10 +236,12 @@
function onclick(e){
e.preventDefault();
- var target = e.target;
- while (target && !target.href) target=target.parentNode;
+ let target = e.target;
let href = target.getAttribute('href');
- if (href) router.navigate(href);
+ target = target.getAttribute('target');
+ if (target == '_blank') {
+ window.open(href);
+ } else if (href) router.navigate(href);
return false;
}
@@ -267,8 +266,7 @@
if (counter > 0) {
warn(t('searching…')+" "+counter);
if (counter == 1) {
- console.log("search for tags: "+search.key);
- let data = { key : search.key, fulltext : fulltext };
+ let data = { key, fulltext : fulltext };
post(api('tags/search'),data).then(handleTags);
}
} else yikes();
@@ -276,16 +274,11 @@
function updateUrl(ev){
ev.preventDefault();
- console.log('updateUrl');
- let url = window.location.origin + window.location.pathname;
- if (search.key) {
- url += '?key=' + encodeURI(search.key);
- window.history.replaceState(history.state, '', url);
- doSearch();
- }
+ if (search.key) router.navigate(window.location.pathname + '?key=' + encodeURI(search.key));
}
$effect(() => {
+ key = router.getQueryParam('key');
doSearch();
});
@@ -293,7 +286,7 @@