cleanup: switch to $state for themes
This commit is contained in:
19 files changed
+169
-349
No files matched your search
@@ -6,14 +6,14 @@
|
||||
message: string
|
||||
}
|
||||
|
||||
export let errors = writable<PageScopedError[]>([])
|
||||
let errors = $state<PageScopedError[]>([])
|
||||
|
||||
export function pushError(args: { scope: string; message: string }) {
|
||||
errors.update((e) => [...e, args])
|
||||
errors.push(args)
|
||||
}
|
||||
|
||||
export function clearErrorScope(scope: string | null | undefined) {
|
||||
errors.update((errors) => errors.filter((error) => error.scope != scope))
|
||||
errors = errors.filter((error) => error.scope != scope)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
let { scope = undefined, class: clazz = '' }: Props = $props()
|
||||
|
||||
let scopedErrors = $derived(
|
||||
$errors.filter((e) => e.scope == scope || e.scope == 'global'),
|
||||
errors.filter((e) => e.scope == scope || e.scope == 'global'),
|
||||
)
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { createBubbler } from 'svelte/legacy'
|
||||
|
||||
const bubble = createBubbler()
|
||||
interface Props {
|
||||
value: number
|
||||
min?: number
|
||||
max?: number
|
||||
step?: number
|
||||
}
|
||||
|
||||
let { value = $bindable(), min = 0, max = 100, step = 1 }: Props = $props()
|
||||
</script>
|
||||
|
||||
<input
|
||||
type="range"
|
||||
bind:value
|
||||
{min}
|
||||
{max}
|
||||
{step}
|
||||
onchange={bubble('change')}
|
||||
onclick={bubble('click')}
|
||||
onkeydown={bubble('keydown')}
|
||||
onkeypress={bubble('keypress')}
|
||||
class="w-full appearance-none h-2 cursor-pointer bg-slate-100 dark:bg-zinc-800
|
||||
rounded-full range"
|
||||
/>
|
||||
|
||||
<style lang="postcss">
|
||||
.range::-moz-range-thumb {
|
||||
border-radius: 50%;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
@apply border-4 bg-white dark:bg-zinc-900 border-primary-900 dark:border-primary-100;
|
||||
transition: all 0.25s cubic-bezier(0.075, 0.82, 0.165, 1);
|
||||
}
|
||||
|
||||
.range:hover::-moz-range-thumb {
|
||||
transform: scale(125%);
|
||||
}
|
||||
.range:active::-moz-range-thumb {
|
||||
transform: scale(90%);
|
||||
}
|
||||
</style>
|
||||
@@ -1,8 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { tweened } from 'svelte/motion'
|
||||
import { Tween } from 'svelte/motion'
|
||||
|
||||
interface Props {
|
||||
progress?: number
|
||||
@@ -10,14 +8,14 @@
|
||||
|
||||
let { progress = 0 }: Props = $props()
|
||||
|
||||
let tween = tweened(progress, { easing: expoOut })
|
||||
let tween = new Tween(progress, { easing: expoOut })
|
||||
|
||||
run(() => {
|
||||
$effect(() => {
|
||||
tween.set(progress)
|
||||
})
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="bg-primary-900 dark:bg-primary-100 h-1 rounded-full"
|
||||
style="width: {$tween * 100}%;"
|
||||
style="width: {tween.current * 100}%;"
|
||||
></div>
|
||||
@@ -87,7 +87,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { themeVars } from '$lib/ui/colors'
|
||||
import { theme } from '$lib/ui/colors.svelte'
|
||||
import { writable, type Readable, type Writable } from 'svelte/store'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
<div
|
||||
{...rest}
|
||||
class="shell bg-slate-50 dark:bg-zinc-950 {clazz}"
|
||||
style={$themeVars}
|
||||
style={theme.vars}
|
||||
>
|
||||
{@render children?.()}
|
||||
<div
|
||||
|
||||
@@ -10,14 +10,12 @@
|
||||
import { Button, Menu, MenuButton, MenuDivider, Spinner } from 'mono-svelte'
|
||||
import {
|
||||
GlobeAlt,
|
||||
Home,
|
||||
Icon,
|
||||
MagnifyingGlass,
|
||||
Newspaper,
|
||||
PencilSquare,
|
||||
Plus,
|
||||
ServerStack,
|
||||
XMark,
|
||||
} from 'svelte-hero-icons'
|
||||
import Profile from './Profile.svelte'
|
||||
import NavButton from './NavButton.svelte'
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
import { colorScheme } from '$lib/ui/colors'
|
||||
import { theme } from '$lib/ui/colors.svelte'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { site } from '$lib/lemmy.svelte'
|
||||
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
||||
@@ -149,11 +149,11 @@
|
||||
<MenuButton class="!py-0">
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={$colorScheme == 'system'
|
||||
src={theme.colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
: $colorScheme == 'light'
|
||||
: theme.colorScheme == 'light'
|
||||
? Sun
|
||||
: $colorScheme == 'dark'
|
||||
: theme.colorScheme == 'dark'
|
||||
? Moon
|
||||
: Moon}
|
||||
micro
|
||||
@@ -164,7 +164,11 @@
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="contents" onclick={stopPropagation(() => {})}>
|
||||
<Select bind:value={$colorScheme} class="ml-auto my-auto w-24" size="sm">
|
||||
<Select
|
||||
bind:value={theme.colorScheme}
|
||||
class="ml-auto my-auto w-24"
|
||||
size="sm"
|
||||
>
|
||||
<Option value="system" icon={ComputerDesktop}>
|
||||
{$t('nav.menu.colorscheme.system')}
|
||||
</Option>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { afterNavigate, goto } from '$app/navigation'
|
||||
import { profile, profileData } from '$lib/auth.svelte'
|
||||
import { getGroups, type Action, type Group } from './actions.svelte'
|
||||
import { themeData } from '$lib/ui/colors'
|
||||
import { theme } from '$lib/ui/colors.svelte'
|
||||
import { page } from '$app/state'
|
||||
|
||||
interface Props {
|
||||
@@ -26,7 +26,7 @@
|
||||
$resumables,
|
||||
profile.data,
|
||||
profileData.profiles,
|
||||
$themeData,
|
||||
theme.data,
|
||||
page.data.contextual?.actions,
|
||||
)
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { resumables, type ResumableItem } from '$lib/lemmy/item'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { colorScheme, theme, themeData, type ThemeData } from '$lib/ui/colors'
|
||||
import { theme, type ThemeData } from '$lib/ui/colors.svelte'
|
||||
import { fullCommunityName } from '$lib/util.svelte'
|
||||
import {
|
||||
ArrowRightOnRectangle,
|
||||
@@ -357,21 +357,21 @@ export function getGroups(
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.system'),
|
||||
}),
|
||||
handle: () => colorScheme.set('system'),
|
||||
handle: () => (theme.colorScheme = 'system'),
|
||||
icon: ComputerDesktop,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.light'),
|
||||
}),
|
||||
handle: () => colorScheme.set('light'),
|
||||
handle: () => (theme.colorScheme = 'light'),
|
||||
icon: Sun,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.dark'),
|
||||
}),
|
||||
handle: () => colorScheme.set('dark'),
|
||||
handle: () => (theme.colorScheme = 'dark'),
|
||||
icon: Moon,
|
||||
},
|
||||
],
|
||||
@@ -382,11 +382,7 @@ export function getGroups(
|
||||
subActions: td.themes.map((th) => ({
|
||||
name: t.get('nav.commands.setThemeTo', { default: th.name }),
|
||||
icon: Swatch,
|
||||
handle: () =>
|
||||
themeData.update((td) => ({
|
||||
...td,
|
||||
currentTheme: th.id,
|
||||
})),
|
||||
handle: () => (theme.data.currentTheme = th.id),
|
||||
})),
|
||||
},
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user