feat: Add default sorts
This commit is contained in:
1 parent
75a7e87110
commit
123336871d
6 files changed
+49
-8
No files matched your search
@@ -7,6 +7,10 @@ interface Settings {
|
|||||||
instance?: string
|
instance?: string
|
||||||
revertColors: boolean
|
revertColors: boolean
|
||||||
showInstance: boolean
|
showInstance: boolean
|
||||||
|
defaultSort: {
|
||||||
|
sort: 'Hot' | 'TopAll' | 'Active' | 'New'
|
||||||
|
feed: 'All' | 'Subscribed' | 'Local'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultSettings: Settings = {
|
const defaultSettings: Settings = {
|
||||||
@@ -15,6 +19,10 @@ const defaultSettings: Settings = {
|
|||||||
markReadPosts: true,
|
markReadPosts: true,
|
||||||
revertColors: false,
|
revertColors: false,
|
||||||
showInstance: false,
|
showInstance: false,
|
||||||
|
defaultSort: {
|
||||||
|
sort: 'Active',
|
||||||
|
feed: 'Local',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export const userSettings = writable(defaultSettings)
|
export const userSettings = writable(defaultSettings)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
import { fly, scale } from 'svelte/transition'
|
import { fly, scale } from 'svelte/transition'
|
||||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||||
import { authData } from '$lib/lemmy.js'
|
import { authData } from '$lib/lemmy.js'
|
||||||
|
import { userSettings } from '$lib/settings.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
</script>
|
</script>
|
||||||
@@ -27,7 +28,8 @@
|
|||||||
<MultiSelect
|
<MultiSelect
|
||||||
options={['Subscribed', 'Local', 'All']}
|
options={['Subscribed', 'Local', 'All']}
|
||||||
disabled={[$authData?.token == undefined]}
|
disabled={[$authData?.token == undefined]}
|
||||||
selected={$page.url.searchParams.get('type') ?? 'Local'}
|
selected={$page.url.searchParams.get('type') ??
|
||||||
|
$userSettings.defaultSort.feed}
|
||||||
on:select={(e) => {
|
on:select={(e) => {
|
||||||
const url = $page.url
|
const url = $page.url
|
||||||
url.searchParams.set('type', e.detail)
|
url.searchParams.set('type', e.detail)
|
||||||
@@ -38,9 +40,10 @@
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
options={['Active', 'Hot', 'TopDay', 'New']}
|
options={['Active', 'Hot', 'TopAll', 'New']}
|
||||||
optionNames={['Active', 'Hot', 'Top', 'New']}
|
optionNames={['Active', 'Hot', 'Top', 'New']}
|
||||||
selected={$page.url.searchParams.get('sort') ?? 'Active'}
|
selected={$page.url.searchParams.get('sort') ??
|
||||||
|
$userSettings.defaultSort.sort}
|
||||||
on:select={(e) => {
|
on:select={(e) => {
|
||||||
const url = $page.url
|
const url = $page.url
|
||||||
url.searchParams.set('sort', e.detail)
|
url.searchParams.set('sort', e.detail)
|
||||||
|
|||||||
+6
-2
@@ -1,13 +1,17 @@
|
|||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { authData, getClient } from '$lib/lemmy.js'
|
||||||
|
import { userSettings } from '$lib/settings.js'
|
||||||
import type { ListingType, SortType } from 'lemmy-js-client'
|
import type { ListingType, SortType } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export async function load({ url }) {
|
export async function load({ url }) {
|
||||||
const page = Number(url.searchParams.get('page') || 1) || 1
|
const page = Number(url.searchParams.get('page') || 1) || 1
|
||||||
|
|
||||||
const sort: SortType = (url.searchParams.get('sort') as SortType) || 'Active'
|
const sort: SortType =
|
||||||
|
(url.searchParams.get('sort') as SortType) ||
|
||||||
|
get(userSettings).defaultSort.sort
|
||||||
const listingType: ListingType =
|
const listingType: ListingType =
|
||||||
(url.searchParams.get('type') as ListingType) || 'Local'
|
(url.searchParams.get('type') as ListingType) ||
|
||||||
|
get(userSettings).defaultSort.feed
|
||||||
|
|
||||||
return {
|
return {
|
||||||
posts: getClient().getPosts({
|
posts: getClient().getPosts({
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import { Color } from '$lib/ui/colors'
|
import { Color } from '$lib/ui/colors'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
import { userSettings } from '$lib/settings.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
</script>
|
</script>
|
||||||
@@ -50,7 +51,8 @@
|
|||||||
<MultiSelect
|
<MultiSelect
|
||||||
options={['Active', 'Hot', 'TopAll', 'New']}
|
options={['Active', 'Hot', 'TopAll', 'New']}
|
||||||
optionNames={['Active', 'Hot', 'Top', 'New']}
|
optionNames={['Active', 'Hot', 'Top', 'New']}
|
||||||
selected={$page.url.searchParams.get('sort') ?? 'Active'}
|
selected={$page.url.searchParams.get('sort') ??
|
||||||
|
$userSettings.defaultSort.sort}
|
||||||
on:select={(e) => {
|
on:select={(e) => {
|
||||||
const url = $page.url
|
const url = $page.url
|
||||||
url.searchParams.set('sort', e.detail)
|
url.searchParams.set('sort', e.detail)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { authData, getClient } from '$lib/lemmy.js'
|
||||||
|
import { userSettings } from '$lib/settings.js'
|
||||||
import type { ListingType, SortType } from 'lemmy-js-client'
|
import type { ListingType, SortType } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
@@ -6,7 +7,8 @@ export async function load(req: any) {
|
|||||||
const page = Number(req.url.searchParams.get('page') || 1) || 1
|
const page = Number(req.url.searchParams.get('page') || 1) || 1
|
||||||
|
|
||||||
const sort: SortType =
|
const sort: SortType =
|
||||||
(req.url.searchParams.get('sort') as SortType) || 'Active'
|
(req.url.searchParams.get('sort') as SortType) ||
|
||||||
|
get(userSettings).defaultSort.sort
|
||||||
|
|
||||||
return {
|
return {
|
||||||
posts: getClient().getPosts({
|
posts: getClient().getPosts({
|
||||||
@@ -18,7 +20,7 @@ export async function load(req: any) {
|
|||||||
}),
|
}),
|
||||||
community: getClient().getCommunity({
|
community: getClient().getCommunity({
|
||||||
name: req.params.name,
|
name: req.params.name,
|
||||||
auth: get(authData)?.token
|
auth: get(authData)?.token,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import Setting from './Setting.svelte'
|
import Setting from './Setting.svelte'
|
||||||
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
newInstance: $instance,
|
newInstance: $instance,
|
||||||
@@ -70,6 +71,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting>
|
||||||
|
<span slot="title">Default sort</span>
|
||||||
|
<span slot="description">The default sort to use for feeds.</span>
|
||||||
|
<div class="flex flex-wrap flex-row gap-4">
|
||||||
|
<div>
|
||||||
|
<span class="block my-1 font-bold">Feed</span>
|
||||||
|
<MultiSelect
|
||||||
|
options={['Subscribed', 'Local', 'All']}
|
||||||
|
bind:selected={$userSettings.defaultSort.feed}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="block my-1 font-bold">Sort</span>
|
||||||
|
<MultiSelect
|
||||||
|
options={['Active', 'Hot', 'TopAll', 'New']}
|
||||||
|
optionNames={['Active', 'Hot', 'Top', 'New']}
|
||||||
|
bind:selected={$userSettings.defaultSort.sort}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Setting>
|
||||||
<h2 class="uppercase font-bold opacity-80 text-sm mt-4">UI</h2>
|
<h2 class="uppercase font-bold opacity-80 text-sm mt-4">UI</h2>
|
||||||
<Setting>
|
<Setting>
|
||||||
<span slot="title">Mark read posts</span>
|
<span slot="title">Mark read posts</span>
|
||||||
|
|||||||
Reference in new issue
Block a user