You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
<script> |
|
import { onMount } from 'svelte'; |
|
import {t} from '../../translations.svelte.js'; |
|
|
|
let key = ""; |
|
let fulltext = false; |
|
let html = ""; |
|
|
|
async function doSearch(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('search.nothing_found'); |
|
} |
|
} |
|
|
|
onMount(() => { |
|
console.log(location.search); |
|
let params = new URLSearchParams(location.search); |
|
key = params.get('key'); |
|
console.log({param:key}); |
|
if (key) doSearch(); |
|
}); |
|
|
|
</script> |
|
|
|
<fieldset class="search"> |
|
<legend>{t('search.search')}</legend> |
|
<form onsubmit={doSearch}> |
|
<label> |
|
{t('search.key')} |
|
<input type="text" bind:value={key} /> |
|
</label> |
|
<label> |
|
<input type="checkbox" bind:checked={fulltext} /> |
|
{t('search.fulltext')} |
|
</label> |
|
<button type="submit">{t('search.go')}</button> |
|
</form> |
|
</fieldset> |
|
{#if html} |
|
<fieldset> |
|
<legend> |
|
{t('search.results')} |
|
</legend> |
|
{@html html} |
|
</fieldset> |
|
{/if} |