working on search
This commit is contained in:
44
frontend/src/routes/search/Search.svelte
Normal file
44
frontend/src/routes/search/Search.svelte
Normal file
@@ -0,0 +1,44 @@
|
||||
<script>
|
||||
import {t} from '../../translations.svelte.js';
|
||||
|
||||
let key = "";
|
||||
let fulltext = false;
|
||||
let html = "";
|
||||
|
||||
async function doSearch(ev){
|
||||
ev.preventDefault();
|
||||
const params = new URLSearchParams()
|
||||
params.set('key', key);
|
||||
if (fulltext) params.set('fulltext',true);
|
||||
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/legacy/search?${params.toString()}`;
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
html = await resp.text();
|
||||
if (!html) html = t('search.nothing_found');
|
||||
}
|
||||
}
|
||||
</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}
|
||||
Reference in New Issue
Block a user