misc: tweak some sort handling

This commit is contained in:
Xylight committed 2024-04-29 17:04:13 -07:00
1 parent 6e3be451b9
commit ff89ec9fb5
8 files changed
+182 -62

No files matched your search

@@ -0,0 +1,51 @@
<script lang="ts">
import { page } from '$app/stores'
import { profile } from '$lib/auth'
import { userSettings } from '$lib/settings'
import { searchParam } from '$lib/util'
import { Select } from 'mono-svelte'
import { GlobeAmericas, Icon } from 'svelte-hero-icons'
import { amModOfAny } from '../moderation/moderation'
export let selected: string
export let navigate: boolean = true
export let changeDefault: boolean = false
export let showLabel: boolean = true
let feed: string = selected
const setSelected = () => (selected = feed)
$: changeDefault
? ($userSettings.defaultSort.feed = selected as
| 'All'
| 'Subscribed'
| 'Local')
: undefined
</script>
<Select
{...$$restProps}
bind:value={feed}
on:change={() => {
if (navigate) searchParam($page.url, 'type', feed, 'page', 'cursor')
}}
>
<svelte:fragment slot="label">
{#if showLabel}
<span class="flex items-center gap-1">
<Icon src={GlobeAmericas} size="16" mini />
Location
</span>
{/if}
</svelte:fragment>
<option value="All">All</option>
<option value="Local">Local</option>
<option value="Subscribed" disabled={$profile?.jwt == undefined}>
Subscribed
</option>
<option
value="ModeratorView"
disabled={!$profile?.jwt || !amModOfAny($profile?.user)}
>
Moderator
</option>
</Select>
+32 -28
View File
@@ -7,7 +7,8 @@
import type { SortType } from 'lemmy-js-client'
import { Select } from 'mono-svelte'
import { ChartBar, Clock, Icon } from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
import { backOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition'
export let selected: string
export let navigate: boolean = true
@@ -20,10 +21,38 @@
: undefined
</script>
<div class="flex flex-row gap-2 {$$props.class}">
<div class="flex flex-row {$$props.class}">
<Select
{...$$restProps}
class={selected?.startsWith('Top') ? 'rounded-r-none' : ''}
bind:value={sort}
on:change={(e) => {
setSelected()
if (navigate) searchParam($page.url, 'sort', selected, 'page', 'cursor')
}}
>
<span slot="label" class="flex items-center gap-1">
<Icon src={ChartBar} size="13" mini />
Sort
</span>
<option value="Active">Active</option>
<option value="Hot">Hot</option>
{#if feature('scaledSort', $site?.version)}
<option value="Scaled">Scaled</option>
{/if}
<option value="TopAll">Top</option>
<option value="New">New</option>
{#if feature('controversialSort', $site?.version)}
<option value="Controversial">Controversial</option>
{/if}
<option value="Old">Old</option>
<option value="MostComments">Comments</option>
<option value="NewComments">New Replies</option>
</Select>
{#if selected?.startsWith('Top')}
<div transition:fly={{ x: 4 }}>
<div transition:fly={{ easing: backOut, x: 2 }}>
<Select
class="border-l-0 rounded-l-none"
bind:value={selected}
on:change={(e) => {
sort = 'TopAll'
@@ -48,29 +77,4 @@
</Select>
</div>
{/if}
<Select
bind:value={sort}
on:change={(e) => {
setSelected()
if (navigate) searchParam($page.url, 'sort', selected, 'page', 'cursor')
}}
>
<span slot="label" class="flex items-center gap-1">
<Icon src={ChartBar} size="13" mini />
Sort
</span>
<option value="Active">Active</option>
<option value="Hot">Hot</option>
{#if feature('scaledSort', $site?.version)}
<option value="Scaled">Scaled</option>
{/if}
<option value="TopAll">Top</option>
<option value="New">New</option>
{#if feature('controversialSort', $site?.version)}
<option value="Controversial">Controversial</option>
{/if}
<option value="Old">Old</option>
<option value="MostComments">Most Comments</option>
<option value="NewComments">New Comments</option>
</Select>
</div>
@@ -6,7 +6,7 @@
export let showLabel = true
</script>
<Select bind:value={$userSettings.view}>
<Select {...$$restProps} bind:value={$userSettings.view}>
<svelte:fragment slot="label">
{#if showLabel}
<span class="flex items-center gap-1">
@@ -108,7 +108,7 @@
</span>
<div
class="flex flex-row items-center place-self-end overflow-auto gap-2 [&>*]:flex-shrink-0"
class="flex flex-row items-center place-self-end overflow-auto gap-2 [&>*]:flex-shrink-0 mx-2"
style="grid-area: badges;"
>
{#if badges.nsfw}
+2 -1
View File
@@ -22,10 +22,11 @@
} from 'svelte-hero-icons'
import Profile from './Profile.svelte'
import NavButton from './NavButton.svelte'
import { scale } from 'svelte/transition'
import { fly, scale } from 'svelte/transition'
import { expoOut, backOut } from 'svelte/easing'
import { flip } from 'svelte/animate'
import SearchBar from '$lib/components/lemmy/util/SearchBar.svelte'
import { swipeGesture } from '$lib/input/swipe'
let searching = false
</script>
+88
View File
@@ -0,0 +1,88 @@
enum SwipeDirection {
Up = 'up',
Down = 'down',
Left = 'left',
Right = 'right',
None = 'none'
}
export function swipeGesture(node: HTMLElement, swipe: (dir: SwipeDirection) => any) {
let touchstartX = 0
let touchstartY = 0
let touchendX = 0
let touchendY = 0
node?.addEventListener(
'touchstart',
function (event) {
// @ts-ignore
touchstartX = event?.screenX
// @ts-ignore
touchstartY = event?.screenY
},
false
)
node?.addEventListener(
'mousedown',
function (event) {
// @ts-ignore
touchstartX = event?.screenX
// @ts-ignore
touchstartY = event?.screenY
},
false
)
node?.addEventListener(
'mouseup',
function (event) {
// @ts-ignore
touchendX = event.screenX
// @ts-ignore
touchendY = event.screenY
return swipe(swipeDir(touchstartX, touchstartY, touchendX, touchendY))
},
false
)
node?.addEventListener(
'touchend',
function (event) {
// @ts-ignore
touchendX = event.screenX
// @ts-ignore
touchendY = event.screenY
return swipe(swipeDir(touchstartX, touchstartY, touchendX, touchendY))
},
false
)
}
function swipeDir(
touchStartX: number,
touchStartY: number,
touchEndX: number,
touchEndY: number
): SwipeDirection {
const deltaX = touchEndX - touchStartX;
const deltaY = touchEndY - touchStartY;
// Define a threshold for the minimum swipe distance
const minSwipeDistance = 10; // Adjust this value as needed
// Check the absolute difference between deltaX and deltaY
if (Math.abs(deltaX) >= Math.abs(deltaY)) {
// Horizontal swipe
if (Math.abs(deltaX) >= minSwipeDistance) {
return deltaX > 0 ? SwipeDirection.Right : SwipeDirection.Left;
}
} else {
// Vertical swipe
if (Math.abs(deltaY) >= minSwipeDistance) {
return deltaY > 0 ? SwipeDirection.Down : SwipeDirection.Up;
}
}
return SwipeDirection.None;
}
+6 -30
View File
@@ -15,6 +15,7 @@
import { feature } from '$lib/version.js'
import { userSettings } from '$lib/settings.js'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
export let data
@@ -48,36 +49,11 @@
</span>
</h1>
</header>
<div class="flex flex-row gap-2 max-w-full justify-between w-full flex-wrap">
<Select
bind:value={data.listingType}
on:change={() => {
// @ts-ignore
$userSettings.defaultSort.feed = data.listingType
searchParam($page.url, 'type', data.listingType, 'page', 'cursor')
}}
>
<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" disabled={!$profile?.jwt}>Subscribed</option>
{#if feature('moderatorView', $site?.version)}
<option
value="ModeratorView"
disabled={!$profile?.jwt || !amModOfAny($profile?.user)}
>
Moderator
</option>
{/if}
</Select>
<div class="flex gap-2 flex-wrap">
<Sort changeDefault selected={data.sort} />
<div class="max-[420px]:hidden">
<ViewSelect />
</div>
<div class="flex items-center gap-2">
<Location changeDefault selected={data.listingType} />
<Sort changeDefault selected={data.sort} />
<div class="max-[420px]:hidden">
<ViewSelect />
</div>
</div>
<PostFeed posts={data.posts.posts} />
+1 -1
View File
@@ -60,7 +60,7 @@ body {
}
#nprogress .bar {
@apply bg-black dark:bg-white !important;
@apply bg-primary-900 dark:bg-primary-100 !important;
z-index: 999 !important;
height: 1px !important;
}