Shioriko/web/app/src/routes/Home.svelte

56 lines
1.5 KiB
Svelte
Raw Normal View History

2021-05-09 15:07:23 +00:00
<script>
2022-04-14 20:38:53 +00:00
import Tags from "svelte-tags-input";
import { getTagAutocomplete } from "../api.js";
import { navigate } from "svelte-routing";
let searchTerms = [];
const onTagChange = (value) => {
searchTerms = value.detail.tags;
};
2022-04-16 12:23:19 +00:00
const onAutocomplete = async (tag) => {
const list = await getTagAutocomplete({ tag });
return list;
};
2022-04-14 20:38:53 +00:00
const onSearch = (i) => {
if (searchTerms.length > 0) {
navigate(`/posts?tags=${searchTerms.join("+")}`);
} else {
navigate(`/posts`);
}
};
2021-05-09 15:07:23 +00:00
</script>
2022-04-14 20:38:53 +00:00
<section class="hero is-small">
2021-05-10 15:47:35 +00:00
<div class="hero-body">
2022-04-14 20:38:53 +00:00
<div class="container has-text-centered">
<p class="title">Shioriko</p>
<p class="subtitle">Booru-style gallery written in Go and Svelte</p>
</div>
</div>
<div class="hero-foot">
<div class="container has-text-centered">
<form on:submit|preventDefault={onSearch}>
<div class="field has-addons">
2022-04-16 10:41:50 +00:00
<div class="control has-text-left is-expanded">
2022-04-14 20:38:53 +00:00
<div class="control" id="tags">
<Tags
tags={searchTerms}
addKeys={[9, 32]}
on:tags={onTagChange}
autoComplete={onAutocomplete}
2022-04-16 12:23:19 +00:00
autoCompleteFilter={false}
2022-04-14 20:38:53 +00:00
/>
</div>
</div>
<div class="control">
<button type="submit" class="button is-primary"> Search </button>
</div>
</div>
</form>
</div>
2021-05-10 15:47:35 +00:00
</div>
</section>