Skip to content

Commit

Permalink
Merge pull request #142 from tjheffner/fix-search-params
Browse files Browse the repository at this point in the history
clean up list length logic
  • Loading branch information
tjheffner authored Mar 22, 2024
2 parents 3456ff1 + 50c968a commit d67d5f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/routes/(main)/blog/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
encode: (arr) => arr?.toString(),
decode: (str) => str?.split(',')?.filter((e) => e) ?? []
},
{ debounceHistory: 500 }
{ debounceHistory: 100 }
);
let search = queryParam('filter', ssp.string(), {
debounceHistory: 500
Expand All @@ -37,7 +37,7 @@
let list
$: fuzzySearch(items, $selectedCategories, $search).then(_items => {
list = _items.slice(0, isTruncated ? LIST_DISPLAY_LENGTH : items.length)
list = _items
})
</script>
Expand Down Expand Up @@ -68,7 +68,7 @@
aria-label="Search articles"
type="text"
bind:value={$search}
bind:this={inputEl}
bind:this={inputEl}
placeholder="Hit / to search"
class="block w-full rounded-md border border-zinc-400 bg-gray-200
px-4 py-2 text-gray-900 placeholder:text-zinc-700
Expand Down Expand Up @@ -121,15 +121,23 @@
<ul
class="w-full divide-y divide-dashed divide-sky-600 md:mx-auto md:w-4/5 dark:divide-blue-300"
>
{#each list as item}
<li class="mb-4 sm:mb-0">
<PostItem {item} href={item.slug}>
{item.description}
</PostItem>
</li>
{#each list as item, i}
{#if isTruncated && (i+1 < LIST_DISPLAY_LENGTH)}
<li class="mb-4 sm:mb-0">
<PostItem {item} href={item.slug}>
{item.description}
</PostItem>
</li>
{:else if !isTruncated}
<li class="mb-4 sm:mb-0">
<PostItem {item} href={item.slug}>
{item.description}
</PostItem>
</li>
{/if}
{/each}
</ul>
{#if isTruncated}
{#if isTruncated && list.length > LIST_DISPLAY_LENGTH}
<div class="flex justify-center mx-auto">
<button
on:click={() => (isTruncated = false)}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(main)/blog/fuzzySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function _fuzzySearch(items, selectedCategories, search) {
[
v.title,
v.subtitle,
v.tags.map((tag) => 'hashtag-' + tag), // add #tag so as to enable tag search
v.tags,
v.content,
v.description,
].join(' ')
Expand Down

0 comments on commit d67d5f2

Please sign in to comment.