diff --git a/src/lib/settings.ts b/src/lib/settings.ts index 86a39acc..bdafd185 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -7,6 +7,10 @@ interface Settings { instance?: string revertColors: boolean showInstance: boolean + defaultSort: { + sort: 'Hot' | 'TopAll' | 'Active' | 'New' + feed: 'All' | 'Subscribed' | 'Local' + } } const defaultSettings: Settings = { @@ -15,6 +19,10 @@ const defaultSettings: Settings = { markReadPosts: true, revertColors: false, showInstance: false, + defaultSort: { + sort: 'Active', + feed: 'Local', + }, } export const userSettings = writable(defaultSettings) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 4b645b32..9f7b0e8e 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -9,6 +9,7 @@ import { fly, scale } from 'svelte/transition' import Spinner from '$lib/components/ui/loader/Spinner.svelte' import { authData } from '$lib/lemmy.js' + import { userSettings } from '$lib/settings.js' export let data @@ -27,7 +28,8 @@ { const url = $page.url url.searchParams.set('type', e.detail) @@ -38,9 +40,10 @@ }} /> { const url = $page.url url.searchParams.set('sort', e.detail) diff --git a/src/routes/+page.ts b/src/routes/+page.ts index b92ce71b..732c9718 100644 --- a/src/routes/+page.ts +++ b/src/routes/+page.ts @@ -1,13 +1,17 @@ import { authData, getClient } from '$lib/lemmy.js' +import { userSettings } from '$lib/settings.js' import type { ListingType, SortType } from 'lemmy-js-client' import { get } from 'svelte/store' export async function load({ url }) { 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 = - (url.searchParams.get('type') as ListingType) || 'Local' + (url.searchParams.get('type') as ListingType) || + get(userSettings).defaultSort.feed return { posts: getClient().getPosts({ diff --git a/src/routes/c/[name]/+page.svelte b/src/routes/c/[name]/+page.svelte index b0b11c6f..9bb8dec1 100644 --- a/src/routes/c/[name]/+page.svelte +++ b/src/routes/c/[name]/+page.svelte @@ -9,6 +9,7 @@ import Button from '$lib/components/input/Button.svelte' import { Color } from '$lib/ui/colors' import { fly } from 'svelte/transition' + import { userSettings } from '$lib/settings.js' export let data @@ -50,7 +51,8 @@ { const url = $page.url url.searchParams.set('sort', e.detail) diff --git a/src/routes/c/[name]/+page.ts b/src/routes/c/[name]/+page.ts index e2e36a97..53ce82f1 100644 --- a/src/routes/c/[name]/+page.ts +++ b/src/routes/c/[name]/+page.ts @@ -1,4 +1,5 @@ import { authData, getClient } from '$lib/lemmy.js' +import { userSettings } from '$lib/settings.js' import type { ListingType, SortType } from 'lemmy-js-client' 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 sort: SortType = - (req.url.searchParams.get('sort') as SortType) || 'Active' + (req.url.searchParams.get('sort') as SortType) || + get(userSettings).defaultSort.sort return { posts: getClient().getPosts({ @@ -18,7 +20,7 @@ export async function load(req: any) { }), community: getClient().getCommunity({ name: req.params.name, - auth: get(authData)?.token + auth: get(authData)?.token, }), } } diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte index 4af2c0af..126b3435 100644 --- a/src/routes/settings/+page.svelte +++ b/src/routes/settings/+page.svelte @@ -8,6 +8,7 @@ import Button from '$lib/components/input/Button.svelte' import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' import Setting from './Setting.svelte' + import MultiSelect from '$lib/components/input/MultiSelect.svelte' let data = { newInstance: $instance, @@ -70,6 +71,27 @@ + + Default sort + The default sort to use for feeds. +
+
+ Feed + +
+
+ Sort + +
+
+

UI

Mark read posts