feat: use select menu for sort

This commit is contained in:
Xyphyn committed 2023-09-03 17:43:45 -07:00
1 parent 79d85cec9e
commit 7358486ee0
3 files changed
+67 -50

No files matched your search

+51 -43
View File
@@ -1,52 +1,60 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/stores' import { page } from '$app/stores'
import { searchParam } from '$lib/util.js' import { searchParam } from '$lib/util.js'
import MultiSelect from '../input/MultiSelect.svelte' import { Select } from 'mono-svelte'
import { ChartBar, Clock, Icon } from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
export let selected: string export let selected: string
export let navigate: boolean = true export let navigate: boolean = true
let sort: string
const setSelected = () => (selected = sort)
</script> </script>
<MultiSelect <div class="flex flex-row gap-4 flex-wrap">
options={[ {#if selected?.startsWith('Top')}
'Active', <div class="w-32" transition:fly={{ x: 4 }}>
'Hot', <Select
'TopAll', bind:value={selected}
'New', on:change={(e) => {
'Old', sort = 'TopAll'
'TopNineMonths', if (navigate) searchParam($page.url, 'sort', selected, 'page')
'TopSixMonths',
'TopThreeMonths',
'TopMonth',
'TopWeek',
'TopDay',
'TopTwelveHour',
'TopSixHour',
'TopHour',
'MostComments',
'NewComments',
]}
optionNames={[
'Active',
'Hot',
'Top',
'New',
'Old',
'Top 9 Months',
'Top 6 Months',
'Top 3 Months',
'Top Month',
'Top Week',
'Top Day',
'Top 12 Hours',
'Top 6 Hours',
'Top Hour',
'Most Comments',
'New Comments',
]}
bind:selected
on:select={(e) => {
if (navigate) searchParam($page.url, 'sort', e.detail, 'page')
}} }}
class="w-full" >
/> <span slot="label" class="flex items-center gap-1">
<Icon src={Clock} size="16" mini />
Time
</span>
<option value="TopAll">All</option>
<option value="TopNineMonths">9 Months</option>
<option value="TopSixMonths">6 Months</option>
<option value="TopThreeMonths">3 Months</option>
<option value="TopMonth">Month</option>
<option value="TopWeek">Week</option>
<option value="TopDay">Day</option>
<option value="TopTwelveHour">12 Hours</option>
<option value="TopSixHour">6 Hours</option>
<option value="TopHour">Hour</option>
</Select>
</div>
{/if}
<Select
bind:value={sort}
on:change={(e) => {
setSelected()
if (navigate) searchParam($page.url, 'sort', selected, 'page')
}}
class="w-32"
>
<span slot="label" class="flex items-center gap-1">
<Icon src={ChartBar} size="14" mini />
Sort
</span>
<option value="Active">Active</option>
<option value="Hot">Hot</option>
<option value="TopAll">Top</option>
<option value="New">New</option>
<option value="Old">Old</option>
</Select>
</div>
+16 -7
View File
@@ -9,7 +9,8 @@
import Sort from '$lib/components/lemmy/Sort.svelte' import Sort from '$lib/components/lemmy/Sort.svelte'
import { searchParam } from '$lib/util.js' import { searchParam } from '$lib/util.js'
import PostFeed from '$lib/components/lemmy/post/PostFeed.svelte' import PostFeed from '$lib/components/lemmy/post/PostFeed.svelte'
import { Button, Modal } from 'mono-svelte' import { Button, Modal, Select } from 'mono-svelte'
import { GlobeAmericas, Icon } from 'svelte-hero-icons'
export let data export let data
@@ -40,12 +41,20 @@
<div <div
class="flex flex-row gap-4 max-w-full w-full justify-between flex-wrap" class="flex flex-row gap-4 max-w-full w-full justify-between flex-wrap"
> >
<MultiSelect <Select
options={['Subscribed', 'Local', 'All']} bind:value={data.listingType}
disabled={[$profile?.jwt == undefined]} on:change={() =>
selected={data.listingType} searchParam($page.url, 'type', data.listingType, 'page')}
on:select={(e) => searchParam($page.url, 'type', e.detail, 'page')} class="w-28"
/> >
<span slot="label" class="flex items-center gap-1">
<Icon src={GlobeAmericas} size="16" mini />
Location
</span>
<option value="All">All</option>
<option value="Local">Local</option>
<option value="Subscribed">Subscribed</option>
</Select>
<Sort selected={data.sort} /> <Sort selected={data.sort} />
</div> </div>
<section class="flex flex-col gap-3 sm:gap-4 h-full"> <section class="flex flex-col gap-3 sm:gap-4 h-full">
Binary file not shown.