implemented task search
This commit is contained in:
@@ -9,10 +9,11 @@
|
||||
const router = useTinyRouter();
|
||||
console.log(router);
|
||||
let bookmarks = $state(null);
|
||||
let error = $state(null);
|
||||
let fulltext = false;
|
||||
let key = $state(router.getQueryParam('key'));
|
||||
let input = $state(router.getQueryParam('key'));
|
||||
let error = $state(null);
|
||||
let tasks = $state(null);
|
||||
|
||||
async function setKey(ev){
|
||||
if (ev) ev.preventDefault();
|
||||
@@ -31,17 +32,32 @@
|
||||
window.history.replaceState(history.state, '', url);
|
||||
|
||||
const data = { key : key, fulltext : fulltext };
|
||||
fetch(api('bookmark/search'),{
|
||||
const options = {
|
||||
credentials:'include',
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
}).then(handleBookmarks);
|
||||
};
|
||||
fetch(api('bookmark/search'),options).then(handleBookmarks);
|
||||
fetch(api('task/search'),options).then(handleTasks);
|
||||
}
|
||||
|
||||
function go(path){
|
||||
router.navigate(path);
|
||||
return false;
|
||||
}
|
||||
|
||||
async function handleBookmarks(resp){
|
||||
if (resp.ok){
|
||||
bookmarks = await resp.json();
|
||||
console.log(bookmarks);
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTasks(resp){
|
||||
if (resp.ok){
|
||||
tasks = await resp.json();
|
||||
console.log(tasks);
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
@@ -68,6 +84,20 @@
|
||||
<button type="submit">{t('go')}</button>
|
||||
</form>
|
||||
</fieldset>
|
||||
{#if tasks}
|
||||
<fieldset>
|
||||
<legend>
|
||||
{t('tasks')}
|
||||
</legend>
|
||||
<ul>
|
||||
{#each Object.values(tasks) as task}
|
||||
<li>
|
||||
<a href="#" onclick={e=>go(`/task/${task.id}/view`)} >{task.name}</a>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</fieldset>
|
||||
{/if}
|
||||
{#if bookmarks}
|
||||
<fieldset>
|
||||
<legend>
|
||||
|
||||
Reference in New Issue
Block a user