upend/webui/src/components/layout/Header.svelte

113 lines
2.5 KiB
Svelte
Raw Normal View History

2021-11-11 23:37:42 +01:00
<script lang="ts">
2022-01-30 16:50:23 +01:00
import { Link, useLocation, useNavigate } from "svelte-navigator";
2021-12-21 14:32:47 +01:00
import { useMatch } from "svelte-navigator";
import { refreshVault } from "../../lib/api";
2022-01-16 22:58:05 +01:00
import { addEmitter } from "../AddModal.svelte";
import Icon from "../utils/Icon.svelte";
import Input from "../utils/Input.svelte";
2022-01-30 15:39:19 +01:00
import { jobsEmitter } from "./Jobs.svelte";
2021-12-21 14:32:47 +01:00
const navigate = useNavigate();
const location = useLocation();
const searchMatch = useMatch("/search/:query");
2022-02-04 22:26:31 +01:00
let searchQuery = $searchMatch?.params.query
? decodeURIComponent($searchMatch?.params.query)
: "";
2021-12-21 14:32:47 +01:00
$: if (!$location.pathname.includes("search")) searchQuery = "";
2022-01-10 22:28:46 +01:00
function onInput(event: CustomEvent<string>) {
searchQuery = event.detail;
2021-12-21 16:27:35 +01:00
if (searchQuery.length > 0) {
navigate(`/search/${encodeURIComponent(searchQuery)}`, {
replace: $location.pathname.includes("search"),
});
2021-12-21 16:27:35 +01:00
} else {
navigate("/");
}
}
2022-01-16 22:58:05 +01:00
let fileInput: HTMLInputElement;
function onFileChange() {
if (fileInput.files.length > 0) {
addEmitter.emit("files", Array.from(fileInput.files));
}
}
2022-01-30 15:32:59 +01:00
2022-01-30 15:39:19 +01:00
async function rescan() {
await refreshVault();
2022-01-30 15:39:19 +01:00
jobsEmitter.emit("reload");
2022-01-30 15:32:59 +01:00
}
2021-11-11 23:37:42 +01:00
</script>
<div class="header">
<h1>
<Link to="/">
2022-02-06 23:43:04 +01:00
<img class="logo" src="assets/upend.svg" alt="UpEnd logo" />
2021-11-11 23:37:42 +01:00
UpEnd
</Link>
</h1>
<div class="input">
2022-01-10 22:03:41 +01:00
<Input
placeholder="Search or add..."
value={searchQuery}
on:input={onInput}
>
<Icon name="search" slot="prefix" />
</Input>
</div>
2022-01-30 15:32:59 +01:00
<button class="button" on:click={() => fileInput.click()}>
2022-02-07 00:02:53 +01:00
<Icon name="upload" />
<input
type="file"
multiple
bind:this={fileInput}
on:change={onFileChange}
/>
2022-01-10 22:03:41 +01:00
</button>
2022-01-30 15:32:59 +01:00
<button class="button" on:click={() => rescan()} title="Rescan vault">
<Icon name="refresh" />
</button>
2021-11-11 23:37:42 +01:00
</div>
<style lang="scss">
.header {
display: flex;
align-items: center;
2022-01-30 15:39:19 +01:00
gap: 0.5rem;
2021-11-30 00:29:27 +01:00
padding: 0 0.5rem;
height: 3.5rem;
2021-11-11 23:37:42 +01:00
border-bottom: 1px solid var(--foreground);
background: var(--background);
h1 {
font-size: 16pt;
font-weight: normal;
margin: 0;
:global(a) {
display: flex;
align-items: center;
2021-12-30 23:24:38 +01:00
color: var(--foreground-lightest);
2021-11-11 23:37:42 +01:00
text-decoration: none;
font-weight: normal;
}
img {
margin-right: 0.5em;
}
}
.logo {
display: inline-block;
height: 1.5em;
}
.input {
2021-11-11 23:37:42 +01:00
flex-grow: 1;
}
}
</style>