-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.svelte
72 lines (62 loc) · 1.83 KB
/
App.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<script lang="ts">
import Fuse from 'fuse.js'
import Sidebar from './components/sidebar/Sidebar.svelte'
import SnippetCard from './components/SnippetCard.svelte'
import Snippet from './components/Snippet.svelte'
import {
languageFilter,
openSnippetId,
snippets,
tagFilters,
} from './store/appState'
import { createSnippet, type TaggedSnippet } from './store/snippets'
import Settings from './components/settings/Settings.svelte'
let search = ''
const fuseFilter = (snippets: TaggedSnippet[], search: string) =>
search != ''
? new Fuse(snippets, {
keys: ['title', 'language', 'tags.name', 'code'],
includeScore: true,
useExtendedSearch: true,
})
.search(search)
.map((res) => ({ ...res, ...res.item }))
: snippets
$: filteredSnippets = fuseFilter(
$snippets.filter(
(snippet) =>
($languageFilter == null || snippet.language == $languageFilter) &&
($tagFilters.length == 0 ||
$tagFilters.every((fTag) =>
snippet.tags.some((tag) => tag.id == fTag.id),
)),
),
search,
)
</script>
<div class="flex h-screen bg-slate-800">
<Sidebar />
<div class="flex border-r border-r-slate-700 flex-col">
<div class="p-2 flex gap-2 border-b border-b-slate-700">
<input
type="search"
class="bg-slate-700 rounded px-2"
bind:value={search}
/>
<button class="bg-slate-700 rounded px-2" on:click={() => createSnippet()}
>+</button
>
</div>
<div class="grow">
{#each filteredSnippets as snippet (snippet.id)}
<SnippetCard {snippet} />
{/each}
</div>
</div>
<div class="grow p-4 flex flex-col">
{#if $openSnippetId != null}
<Snippet snippetId={$openSnippetId} />
{/if}
</div>
</div>
<Settings />