From c85a03b21154cf8a19c7f65581e9b21f804a2f99 Mon Sep 17 00:00:00 2001 From: tree Date: Fri, 5 May 2023 02:29:06 +0200 Subject: [PATCH] basic filtering --- src/app.css | 6 +++ src/lib/components/CollectionList.svelte | 1 + src/routes/[entry]/[type]/+page.svelte | 49 +++++++++++++++++++++--- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/app.css b/src/app.css index c486b35d..cc1cf494 100644 --- a/src/app.css +++ b/src/app.css @@ -77,4 +77,10 @@ .pbw-text-color-secondary { @apply text-gray-500 dark:text-gray-300; } + + .filter-component { @apply grow; } + .filter-component label, .filter-component input { @apply block; } + .filter-component label { @apply uppercase text-black/60; } + .filter-component input { @apply border py-1 px-2 border-black/40 rounded bg-black/5; } + .filter { @apply mt-4 mb-2 text-lg flex; } } diff --git a/src/lib/components/CollectionList.svelte b/src/lib/components/CollectionList.svelte index 7aca8742..4ad216b9 100644 --- a/src/lib/components/CollectionList.svelte +++ b/src/lib/components/CollectionList.svelte @@ -36,6 +36,7 @@ const _url = (col, item) => (item.hidden ? '' : `/${entry}/${col}/${item.id}`); + {#each arr.map((k) => findObject(k)) as item}
{ + const cols = [["name", 50], ["tags", 30], ["caption", 20], ["venueName"], ["venueAddress"], ["org"], ["chains"], ["description"], ["twitter"], ["country"]] + scores[i.id] = 0 + for (const [ c, cs = 20 ] of cols) { + let ctag = typeof i[c] === "array" ? i[c].join(", ") : i[c] + if (typeof ctag === "string" && normalize(ctag).match(new RegExp(normalize(q), "si"))) { + scores[i.id] += cs + } + } + return i + }).filter(i => scores[i.id] > 0).sort((x, y) => scores[x.id] > scores[y.id] ? -1 : 1) + } else { + total = _items.filter((e) => !e.hidden).length + } + return _items; } - $: processedItems = processItems(items); //, Object.fromEntries($page.url.searchParams)) + $: processedItems = processItems(items, {}, q); //, Object.fromEntries($page.url.searchParams)) + $: currentTotal = processedItems.filter((e) => !e.hidden).length onMount(async () => { if (!config.collections[$page.params.type]) { @@ -78,8 +111,14 @@

- {tc.title} ({processedItems.filter((e) => !e.hidden).length}) + {tc.title} ({currentTotal}{#if currentTotal !== total}/{total}{/if})

+
+
+ + +
+
@@ -119,7 +158,7 @@ {#each processedItems as item} - + {#if type === 'events'} {/if} - + {/if} {#if type === 'media-partners'}
{formatItemDate(item)}