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

@@ -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'
},
],
},