diff --git a/package.json b/package.json index 85a1dee4..4ef34e90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "photon-lemmy", - "version": "0.4.32", + "version": "0.4.33", "private": true, "scripts": { "dev": "vite dev", diff --git a/src/lib/components/input/MultiSelect.svelte b/src/lib/components/input/MultiSelect.svelte index f864c112..bc07765f 100644 --- a/src/lib/components/input/MultiSelect.svelte +++ b/src/lib/components/input/MultiSelect.svelte @@ -1,14 +1,20 @@
- {#each options as option, index} + {#each options.slice(0, 4) as option, index} + {#each options.slice(4) as option, index} + + {/each} + + {/if}
+ + diff --git a/src/lib/components/input/SearchInput.svelte b/src/lib/components/input/SearchInput.svelte index ed7be4e4..c2a641f8 100644 --- a/src/lib/components/input/SearchInput.svelte +++ b/src/lib/components/input/SearchInput.svelte @@ -1,5 +1,4 @@ - -
  • Communities
  • - {#each options as option} + + {#each options as option, index} (selected = option)}> - {optionNames.get(option) || option} + {optionNames[index] || option} {/each}
    diff --git a/src/lib/components/lemmy/Sort.svelte b/src/lib/components/lemmy/Sort.svelte new file mode 100644 index 00000000..2a80b3b7 --- /dev/null +++ b/src/lib/components/lemmy/Sort.svelte @@ -0,0 +1,37 @@ + + + searchParam($page.url, 'sort', e.detail, 'page')} + class="w-full md:max-w-[20rem]" +/> diff --git a/src/lib/util.ts b/src/lib/util.ts index 7beb7847..125db820 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -1,4 +1,19 @@ +import { goto } from '$app/navigation' + export const findClosestNumber = (numbers: number[], target: number): number => numbers.reduce((prev, curr) => Math.abs(curr - target) < Math.abs(prev - target) ? curr : prev ) + +export const searchParam = ( + url: URL, + key: string, + value: string, + ...deleteKeys: string[] +) => { + url.searchParams.set(key, value) + deleteKeys.forEach((k) => url.searchParams.delete(k)) + goto(url, { + invalidateAll: true, + }) +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 79593339..f09a005e 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -12,6 +12,8 @@ import Pageination from '$lib/components/ui/Pageination.svelte' import Modal from '$lib/components/ui/modal/Modal.svelte' import { profile } from '$lib/auth.js' + import Sort from '$lib/components/lemmy/Sort.svelte' + import { searchParam } from '$lib/util.js' export let data @@ -54,20 +56,7 @@ }) }} /> - { - const url = $page.url - url.searchParams.set('sort', e.detail) - url.searchParams.delete('page') - goto(url, { - invalidateAll: true, - }) - }} - class="w-full md:max-w-[20rem]" - /> +
    {#if data.posts.posts.length == 0} @@ -99,12 +88,7 @@
    { - $page.url.searchParams.set('page', p.detail.toString()) - goto($page.url.toString(), { - invalidateAll: true, - }) - }} + on:change={(p) => searchParam($page.url, 'page', p.detail.toString())} />