From 89fa006ba62881919e59d38216b1ca8da635f1be Mon Sep 17 00:00:00 2001 From: Bram Tweedegolf Date: Tue, 17 Sep 2024 10:24:20 +0200 Subject: [PATCH 1/4] Create simpel sorting filter --- frontend/src/App.svelte | 2 ++ frontend/src/app.css | 8 +++++ frontend/src/lib/CrateList.svelte | 28 +++++++++++---- frontend/src/lib/SortFilter.svelte | 51 +++++++++++++++++++++++++++ frontend/src/store/FilterStore.svelte | 4 +++ 5 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 frontend/src/lib/SortFilter.svelte diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index d8e5668..4f19a7e 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -5,6 +5,7 @@ import CrateList from "./lib/CrateList.svelte"; import type {FullCrate, Indexes} from "./crate-db"; import Filter from "./lib/Filter.svelte"; + import SortFilter from './lib/SortFilter.svelte'; import ForkMe from "./lib/ForkMe.svelte"; export let BUILD_DATE: string; @@ -51,6 +52,7 @@
+ diff --git a/frontend/src/app.css b/frontend/src/app.css index 694adc5..512848d 100644 --- a/frontend/src/app.css +++ b/frontend/src/app.css @@ -154,6 +154,14 @@ label { } .filter { + + &.search { + .filter-box { + border: 1px solid black; + font-weight: bold; + } + } + .filter-box { display: flex; flex-direction: row; diff --git a/frontend/src/lib/CrateList.svelte b/frontend/src/lib/CrateList.svelte index f7bc8b7..f65c3f1 100644 --- a/frontend/src/lib/CrateList.svelte +++ b/frontend/src/lib/CrateList.svelte @@ -1,22 +1,36 @@
    {#each filtered_crates as crate, i} - {#if filter.includes(i)} -
  1. - -
  2. - {/if} +
  3. + +
  4. {/each}
diff --git a/frontend/src/lib/SortFilter.svelte b/frontend/src/lib/SortFilter.svelte new file mode 100644 index 0000000..50b7df3 --- /dev/null +++ b/frontend/src/lib/SortFilter.svelte @@ -0,0 +1,51 @@ + + +
+ + + +
+
+ + + + + +
+
+
diff --git a/frontend/src/store/FilterStore.svelte b/frontend/src/store/FilterStore.svelte index d456442..b8e6df1 100644 --- a/frontend/src/store/FilterStore.svelte +++ b/frontend/src/store/FilterStore.svelte @@ -2,6 +2,10 @@ import {writable} from 'svelte/store'; + // Which filter is currenly opened export let open_filter = writable(""); + // The results are sorted by + export let sort_by = writable("alphanumeric"); + From 79622b8f88d1821c4d4c4edeaa2b3d5184cc4c88 Mon Sep 17 00:00:00 2001 From: Bram Tweedegolf Date: Tue, 17 Sep 2024 10:37:19 +0200 Subject: [PATCH 2/4] Close sorting filter on outside click --- frontend/src/lib/SortFilter.svelte | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/SortFilter.svelte b/frontend/src/lib/SortFilter.svelte index 50b7df3..2a94e7e 100644 --- a/frontend/src/lib/SortFilter.svelte +++ b/frontend/src/lib/SortFilter.svelte @@ -12,6 +12,30 @@ $sort_by = type; } + function clickOutside(node, { enabled: initialEnabled, cb }) { + const handleOutsideClick = ({ target }) => { + if (!node.contains(target)) { + cb(); + } + }; + + function update({enabled}) { + if (enabled) { + window.addEventListener('click', handleOutsideClick); + } else { + window.removeEventListener('click', handleOutsideClick); + } + } + + update({ enabled: initialEnabled }); + return { + update, + destroy() { + window.removeEventListener( 'click', handleOutsideClick ); + } + }; + } + $: open = $open_filter == name; $: alpha_open = $sort_by == 'alphanumeric'; @@ -22,7 +46,7 @@ -
+
open = false }} >