|
|
|
|
@ -1,40 +1,60 @@
@@ -1,40 +1,60 @@
|
|
|
|
|
<script> |
|
|
|
|
import { onMount } from 'svelte'; |
|
|
|
|
|
|
|
|
|
import { t } from '../../translations.svelte.js'; |
|
|
|
|
import { onMount } from 'svelte'; |
|
|
|
|
import { useTinyRouter } from 'svelte-tiny-router'; |
|
|
|
|
import { api } from '../../urls.svelte.js'; |
|
|
|
|
import { t } from '../../translations.svelte.js'; |
|
|
|
|
|
|
|
|
|
const router = useTinyRouter(); |
|
|
|
|
console.log(router); |
|
|
|
|
let fulltext = false; |
|
|
|
|
let html = ""; |
|
|
|
|
let key = ""; |
|
|
|
|
let key = $state(router.getQueryParam('key')); |
|
|
|
|
let input = $state(router.getQueryParam('key')); |
|
|
|
|
let error = $state(null); |
|
|
|
|
|
|
|
|
|
async function doSearch(ev){ |
|
|
|
|
async function setKey(ev){ |
|
|
|
|
if (ev) ev.preventDefault(); |
|
|
|
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/legacy/search`; |
|
|
|
|
const resp = await fetch(url,{ |
|
|
|
|
credentials : 'include', |
|
|
|
|
method : 'POST', |
|
|
|
|
body : JSON.stringify({key:key,fulltext:fulltext?'on':'off'}) |
|
|
|
|
}); |
|
|
|
|
if (resp.ok){ |
|
|
|
|
html = await resp.text(); |
|
|
|
|
if (!html) html = t('nothing_found'); |
|
|
|
|
} |
|
|
|
|
key = input; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMount(() => { |
|
|
|
|
let params = new URLSearchParams(location.search); |
|
|
|
|
key = params.get('key'); |
|
|
|
|
if (key) doSearch(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function doSearch(ignored){ |
|
|
|
|
let url = window.location.origin + window.location.pathname; |
|
|
|
|
if (key) url += '?key=' + encodeURI(key); |
|
|
|
|
window.history.replaceState(history.state, '', url); |
|
|
|
|
|
|
|
|
|
const data = { key : key, fulltext : fulltext }; |
|
|
|
|
fetch(api('bookmark/search'),{ |
|
|
|
|
credentials:'include', |
|
|
|
|
method: 'POST', |
|
|
|
|
body: JSON.stringify(data) |
|
|
|
|
}).then(handleBookmarks); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function handleBookmarks(resp){ |
|
|
|
|
if (resp.ok){ |
|
|
|
|
} else { |
|
|
|
|
error = await resp.text(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$effect(() => doSearch(key)) |
|
|
|
|
|
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<fieldset class="search"> |
|
|
|
|
<legend>{t('search')}</legend> |
|
|
|
|
<form onsubmit={doSearch}> |
|
|
|
|
{#if error} |
|
|
|
|
<span class="error">{error}</span> |
|
|
|
|
{/if} |
|
|
|
|
<form onsubmit={setKey}> |
|
|
|
|
<label> |
|
|
|
|
{t('key')} |
|
|
|
|
<input type="text" bind:value={key} /> |
|
|
|
|
<input type="text" bind:value={input} /> |
|
|
|
|
</label> |
|
|
|
|
<label> |
|
|
|
|
<input type="checkbox" bind:checked={fulltext} /> |
|
|
|
|
@ -43,11 +63,11 @@
@@ -43,11 +63,11 @@
|
|
|
|
|
<button type="submit">{t('go')}</button> |
|
|
|
|
</form> |
|
|
|
|
</fieldset> |
|
|
|
|
{#if html} |
|
|
|
|
{#if key} |
|
|
|
|
<fieldset> |
|
|
|
|
<legend> |
|
|
|
|
{t('results')} |
|
|
|
|
</legend> |
|
|
|
|
{@html html} |
|
|
|
|
{key} |
|
|
|
|
</fieldset> |
|
|
|
|
{/if} |