migrate: change settings from a store to a state

This commit is contained in:
Xylight committed 2024-10-25 21:09:32 -07:00
1 parent ffcd9faa96
commit d597349887
128 files changed
+1010 -1144

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { findClosestNumber } from '$lib/util.js'
import { findClosestNumber } from '$lib/util.svelte.js'
import { createAvatar } from '@dicebear/core'
import * as initials from '@dicebear/initials'
+1 -1
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { userSettings } from '$lib/settings'
import { settings } from '$lib/settings.svelte'
interface Props {
width?: number
+6 -9
View File
@@ -65,12 +65,9 @@
export let screenWidth = writable(1000)
export let dockProps: Readable<ReturnType<typeof calculateDockProperties>> =
derivedStore(
[userSettings, screenWidth],
([$settings, $screenWidth], set) => {
set(calculateDockProperties($settings.dock, $screenWidth))
},
)
derivedStore([screenWidth], ([$screenWidth], set) => {
set(calculateDockProperties(settings.dock, $screenWidth))
})
export let contentPadding: Readable<ReturnType<typeof calculatePadding>> =
derivedStore(dockProps, ($dockProps, set) =>
set(calculatePadding($dockProps.noGap, $dockProps.top, true)),
@@ -78,9 +75,9 @@
</script>
<script lang="ts">
import { userSettings } from '$lib/settings.js'
import { settings } from '$lib/settings.svelte.js'
import { themeVars } from '$lib/ui/colors'
import { routes } from '$lib/util.js'
import { routes } from '$lib/util.svelte.js'
import { writable, type Readable, type Writable } from 'svelte/store'
interface Props {
@@ -155,7 +152,7 @@
})}
</div>
<div
class="content divide-x divide-slate-100 dark:divide-zinc-900 min-h-screen {$userSettings.newWidth
class="content divide-x divide-slate-100 dark:divide-zinc-900 min-h-screen {settings.newWidth
? 'limit-width'
: ''}"
>
@@ -1,5 +1,5 @@
<script lang="ts">
import { userSettings } from '$lib/settings'
import { settings } from '$lib/settings.svelte'
import { contentPadding } from '../Shell.svelte'
interface Props {
@@ -35,7 +35,7 @@
>
<h1
class="text-3xl font-medium flex gap-2 w-full
{$userSettings.font == 'satoshi/nunito' ? 'font-display' : ''} {clazz ?? ''}"
{settings.font == 'satoshi/nunito' ? 'font-display' : ''} {clazz ?? ''}"
>
{@render children?.()}
</h1>
+3 -3
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { notifications, profile } from '$lib/auth.js'
import { notifications, profile } from '$lib/auth.svelte.js'
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
import {
amModOfAny,
@@ -36,7 +36,7 @@
import { t } from '$lib/translations'
import CommandsWrapper from './commands/CommandsWrapper.svelte'
import { optimizeImageURL } from '$lib/components/lemmy/post/helpers'
import { userSettings } from '$lib/settings'
import { settings } from '$lib/settings.svelte'
import { dockProps } from '../layout/Shell.svelte'
let promptOpen: boolean = $state(false)
@@ -67,7 +67,7 @@
class="ml-2 logo"
adaptive={false}
>
{#snippet icon()}
{#snippet customIcon()}
{#if LINKED_INSTANCE_URL}
{#if $site}
<Avatar
+3 -3
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import { stopPropagation } from 'svelte/legacy'
import { notifications, profile } from '$lib/auth'
import { notifications, profile } from '$lib/auth.svelte'
import {
Badge,
@@ -34,7 +34,7 @@
UserGroup,
} from 'svelte-hero-icons'
import { colorScheme } from '$lib/ui/colors'
import { userSettings } from '$lib/settings'
import { settings } from '$lib/settings.svelte'
import { site } from '$lib/lemmy'
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
import { t } from '$lib/translations'
@@ -185,7 +185,7 @@
{/snippet}
{$t('nav.menu.theme')}
</MenuButton>
{#if $userSettings.debugInfo}
{#if settings.debugInfo}
<MenuButton link href="/util">
{#snippet prefix()}
<Icon src={BugAnt} mini width={16} />
@@ -7,16 +7,15 @@
type IconSource,
} from 'svelte-hero-icons'
import Avatar from '../../Avatar.svelte'
import type { Action } from './actions'
import type { Action } from './actions.svelte'
interface Props {
action: Action;
class?: string;
children?: import('svelte').Snippet;
action: Action
class?: string
children?: import('svelte').Snippet
}
let { action, class: clazz = '', children }: Props = $props();
let { action, class: clazz = '', children }: Props = $props()
</script>
<Button
@@ -1,5 +1,5 @@
<script lang="ts">
import { run } from 'svelte/legacy';
import { run } from 'svelte/legacy'
import { resumables } from '$lib/lemmy/item'
import { TextInput } from 'mono-svelte'
@@ -9,19 +9,17 @@
import CommandItem from './CommandItem.svelte'
import { browser } from '$app/environment'
import { afterNavigate, goto } from '$app/navigation'
import { profile, profileData } from '$lib/auth'
import { getGroups, type Action, type Group } from './actions'
import { profile, profileData } from '$lib/auth.svelte'
import { getGroups, type Action, type Group } from './actions.svelte'
import { themeData } from '$lib/ui/colors'
import { page } from '$app/stores'
interface Props {
open?: boolean;
groups?: Group[];
open?: boolean
groups?: Group[]
}
let { open = $bindable(false), groups = $bindable([]) }: Props = $props();
let { open = $bindable(false), groups = $bindable([]) }: Props = $props()
let search = $state('')
let container: HTMLElement = $state()
@@ -87,7 +85,7 @@
score: Math.max(
fuzzySearch(action.name, term),
fuzzySearch(group.name, term),
action.detail ? fuzzySearch(action.detail, term) : -1
action.detail ? fuzzySearch(action.detail, term) : -1,
),
}))
.filter((action) => action.score > 0)
@@ -98,7 +96,7 @@
actions: scoredActions,
score: Math.max(
fuzzySearch(group.name, term),
...scoredActions.map((a) => a.score)
...scoredActions.map((a) => a.score),
),
}
})
@@ -130,10 +128,9 @@
updateFilteredGroups()
}
function flattenActions(
actions: Action[],
subaction: boolean = true
subaction: boolean = true,
): Action[] {
return actions.flatMap((action) => [
action,
@@ -230,20 +227,22 @@
})
run(() => {
if (open) search = ''
});
})
run(() => {
groups = getGroups(
$resumables,
$profile,
$profileData.profiles,
$themeData,
$page.data.contextual?.actions
$page.data.contextual?.actions,
)
});
let flattenedActions = $derived(filteredGroups.flatMap((group) => group.actions))
})
let flattenedActions = $derived(
filteredGroups.flatMap((group) => group.actions),
)
run(() => {
debouncedSearch(search)
});
})
</script>
<svelte:window onkeydown={handleKeydown} />
@@ -5,10 +5,10 @@
import { CommandLine, Icon } from 'svelte-hero-icons'
interface Props {
open?: boolean;
open?: boolean
}
let { open = $bindable(false) }: Props = $props();
let { open = $bindable(false) }: Props = $props()
function handleKeydown(event: KeyboardEvent) {
if (
@@ -25,8 +25,8 @@
{#if open}
<Modal bind:open>
{#snippet title()}
<span class="flex items-center gap-1">
{#snippet customTitle()}
<span class="flex items-center gap-1">
<svg
width="24"
height="24"
@@ -40,7 +40,7 @@
</svg>
{$t('nav.commands.prompt')}
</span>
{/snippet}
{/snippet}
{#await import('./Commands.svelte')}
<div class="h-96 flex flex-col gap-2 items-center justify-center">
<Spinner width={32} />
@@ -1,15 +1,15 @@
import { goto } from '$app/navigation'
import { page } from '$app/stores'
import { setUserID, type Profile } from '$lib/auth'
import { setUserID, type Profile } from '$lib/auth.svelte'
import {
amModOfAny,
isAdmin,
} from '$lib/components/lemmy/moderation/moderation'
import { resumables, type ResumableItem } from '$lib/lemmy/item'
import { userSettings } from '$lib/settings.svelte'
import { settings } from '$lib/settings.svelte'
import { t } from '$lib/translations'
import { colorScheme, theme, themeData, type ThemeData } from '$lib/ui/colors'
import { fullCommunityName } from '$lib/util'
import { fullCommunityName } from '$lib/util.svelte'
import {
ArrowRightOnRectangle,
Bookmark,
@@ -339,10 +339,7 @@ export function getGroups(
}),
icon: ViewColumns,
handle: () =>
userSettings.update((s) => ({
...s,
view: 'compact',
})),
settings.view = 'compact'
},
{
name: t.get('nav.commands.setViewTo', {
@@ -350,10 +347,7 @@ export function getGroups(
}),
icon: ViewColumns,
handle: () =>
userSettings.update((s) => ({
...s,
view: 'cozy',
})),
settings.view = 'cozy'
},
{
name: t.get('nav.commands.setViewTo', {
@@ -361,21 +355,7 @@ export function getGroups(
}),
icon: ViewColumns,
handle: () =>
userSettings.update((s) => ({
...s,
view: 'list',
})),
},
{
name: t.get('nav.commands.setViewTo', {
default: t.get('filter.view.legacy'),
}),
icon: ViewColumns,
handle: () =>
userSettings.update((s) => ({
...s,
view: 'card',
})),
settings.view = 'list'
},
],
},
@@ -1,5 +1,5 @@
<script lang="ts">
import { profile } from '$lib/auth'
import { profile } from '$lib/auth.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import { addFavorite } from '$lib/lemmy/item'
@@ -11,11 +11,11 @@
import { expoOut } from 'svelte/easing'
interface Props {
items: Community[];
isFavorites?: boolean;
items: Community[]
isFavorites?: boolean
}
let { items, isFavorites = false }: Props = $props();
let { items, isFavorites = false }: Props = $props()
</script>
{#each items.sort( (a, b) => a.title.localeCompare(b.title), ) as follow (follow.id)}
@@ -65,13 +65,13 @@
href="/c/{follow.name}@{new URL(follow.actor_id).hostname}"
>
{#snippet label()}
<div class="flex flex-col max-w-full break-words" >
<div class="flex flex-col max-w-full break-words">
<span>{follow.title}</span>
<span class="text-xs text-slate-600 dark:text-zinc-400">
{new URL(follow.actor_id).hostname}
</span>
</div>
{/snippet}
{/snippet}
</SidebarButton>
</div>
{/each}
@@ -1,22 +1,21 @@
<script lang="ts">
import { goto } from '$app/navigation'
import { page } from '$app/stores'
import { profile, setUserID, type Profile } from '$lib/auth.js'
import { profile, setUserID, type Profile } from '$lib/auth.svelte.js'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import { LINKED_INSTANCE_URL } from '$lib/instance'
import ProfileAvatar from '$lib/lemmy/ProfileAvatar.svelte'
import { Button } from 'mono-svelte'
import { Icon, QuestionMarkCircle } from 'svelte-hero-icons'
let switching: boolean = $state(false)
interface Props {
prof: Profile;
index: number;
guest?: boolean;
prof: Profile
index: number
guest?: boolean
}
let { prof, index, guest = false }: Props = $props();
let { prof, index, guest = false }: Props = $props()
</script>
<SidebarButton
@@ -48,7 +47,6 @@
{index}
{guest}
selected={$profile?.id == prof.id}
/>
{/snippet}
<span
+13 -13
View File
@@ -8,8 +8,8 @@
UserCircle,
UserGroup,
} from 'svelte-hero-icons'
import { notifications, profile, profileData } from '$lib/auth.js'
import { userSettings } from '$lib/settings.js'
import { notifications, profile, profileData } from '$lib/auth.svelte.js'
import { settings } from '$lib/settings.svelte.js'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import CommunityList from '$lib/components/ui/sidebar/CommunityList.svelte'
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
@@ -36,9 +36,9 @@
gap-1 h-fit max-h-screen {clazz}"
{style}
>
{#if $userSettings.dock.pins?.length ?? 0 > 0}
{#if settings.dock.pins?.length ?? 0 > 0}
<div class="flex items-center flex-wrap gap-2 pl-1.5">
{#each $userSettings.dock.pins as pin}
{#each settings.dock.pins as pin}
<SidebarButton
icon={iconOfLink(pin.url)}
on:click={() => goto(pin.url)}
@@ -46,8 +46,8 @@
selected={`${$page.url.pathname}${$page.url.search}` == pin.url}
on:contextmenu={(e) => {
e.preventDefault()
$userSettings.dock.pins = $userSettings.dock.pins.toSpliced(
$userSettings.dock.pins.findLastIndex((p) => pin.url == p.url),
settings.dock.pins = settings.dock.pins.toSpliced(
settings.dock.pins.findLastIndex((p) => pin.url == p.url),
1,
)
return false
@@ -120,7 +120,7 @@
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={$userSettings.expand.accounts}
bind:open={settings.expand.accounts}
>
{#snippet title()}
<span class="px-2 py-1 w-full">
@@ -148,11 +148,11 @@
{#if $profile?.favorites && $profile?.favorites.length > 0}
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={$userSettings.expand.favorites}
bind:open={settings.expand.favorites}
>
{#snippet title()}
<span
class="px-2 py-1 w-full {$userSettings.expandSidebar
class="px-2 py-1 w-full {settings.expandSidebar
? ''
: '//max-lg:hidden'}"
>
@@ -174,11 +174,11 @@
{#if $profile?.user.moderates.length > 0}
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={$userSettings.expand.moderates}
bind:open={settings.expand.moderates}
>
{#snippet title()}
<span
class="px-2 py-1 w-full {$userSettings.expandSidebar
class="px-2 py-1 w-full {settings.expandSidebar
? ''
: '//max-lg:hidden'}"
>
@@ -201,11 +201,11 @@
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={$userSettings.expand.communities}
bind:open={settings.expand.communities}
>
{#snippet title()}
<span
class="px-2 py-1 w-full {$userSettings.expandSidebar
class="px-2 py-1 w-full {settings.expandSidebar
? ''
: '//max-lg:hidden'}"
>
@@ -2,7 +2,7 @@
import { run } from 'svelte/legacy'
import { page } from '$app/stores'
import { userSettings } from '$lib/settings.js'
import { settings } from '$lib/settings.svelte.js'
import { Button } from 'mono-svelte'
import { Icon, type IconSource } from 'svelte-hero-icons'