fix: merge settings with default
This commit is contained in:
1 parent
b291aeebf8
commit
2b27e99784
4 files changed
+46
-25
No files matched your search
@@ -58,8 +58,8 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let replyReason
|
let replyReason = $state('')
|
||||||
run(() => {
|
$effect(() => {
|
||||||
replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -162,7 +162,6 @@
|
|||||||
|
|
||||||
const resetText = () => {
|
const resetText = () => {
|
||||||
reason = ''
|
reason = ''
|
||||||
replyReason = ''
|
|
||||||
commentReason = false
|
commentReason = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +191,6 @@
|
|||||||
children: [],
|
children: [],
|
||||||
comment_view: item,
|
comment_view: item,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
ui: {},
|
|
||||||
}}
|
}}
|
||||||
postId={item.post.id}
|
postId={item.post.id}
|
||||||
actions={false}
|
actions={false}
|
||||||
@@ -227,7 +225,7 @@
|
|||||||
placeholder={replyReason}
|
placeholder={replyReason}
|
||||||
rows={3}
|
rows={3}
|
||||||
>
|
>
|
||||||
{#snippet label()}
|
{#snippet customLabel()}
|
||||||
<div class="flex justify-between items-end mb-1">
|
<div class="flex justify-between items-end mb-1">
|
||||||
{$t('comment.reply')}
|
{$t('comment.reply')}
|
||||||
<Select bind:value={preset} placeholder="No preset">
|
<Select bind:value={preset} placeholder="No preset">
|
||||||
|
|||||||
@@ -35,8 +35,6 @@
|
|||||||
<Button
|
<Button
|
||||||
color={isPanel ? 'secondary' : 'tertiary'}
|
color={isPanel ? 'secondary' : 'tertiary'}
|
||||||
{...rest}
|
{...rest}
|
||||||
onclick
|
|
||||||
on:contextmenu
|
|
||||||
class="rounded-full w-10 h-10 flex-shrink-0 {adaptive
|
class="rounded-full w-10 h-10 flex-shrink-0 {adaptive
|
||||||
? '@3xl:h-8 @3xl:px-3 @3xl:rounded-[10px] @3xl:w-auto'
|
? '@3xl:h-8 @3xl:px-3 @3xl:rounded-[10px] @3xl:w-auto'
|
||||||
: ''} {isSelected
|
: ''} {isSelected
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
{style}
|
{style}
|
||||||
>
|
>
|
||||||
<NavButton
|
<NavButton
|
||||||
on:contextmenu={(e) => {
|
oncontextmenu={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
promptOpen = true
|
promptOpen = true
|
||||||
return true
|
return true
|
||||||
|
|||||||
+42
-17
@@ -191,31 +191,29 @@ export const defaultSettings: Settings = {
|
|||||||
logoColorMonth: null,
|
logoColorMonth: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSettingsState(initial: Settings) {
|
|
||||||
|
|
||||||
|
function createSettingsState(initial: Settings): Settings {
|
||||||
let settings = $state(initial)
|
let settings = $state(initial)
|
||||||
|
if (browser) {
|
||||||
|
try {
|
||||||
|
const localSettings = JSON.parse(localStorage.getItem('settings') ?? '{}')
|
||||||
|
const merged = mergeDeep(initial, localSettings)
|
||||||
|
|
||||||
|
settings = merged
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
export let settings = createSettingsState(defaultSettings)
|
export let settings = createSettingsState(defaultSettings)
|
||||||
|
|
||||||
|
|
||||||
if (typeof window != 'undefined') {
|
|
||||||
let oldUserSettings = JSON.parse(
|
|
||||||
localStorage.getItem('settings') ?? JSON.stringify(defaultSettings)
|
|
||||||
)
|
|
||||||
|
|
||||||
// settings = {
|
|
||||||
// ...defaultSettings,
|
|
||||||
// ...oldUserSettings,
|
|
||||||
// settingsVer: defaultSettings.settingsVer,
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect.root(() => {
|
$effect.root(() => {
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (typeof window != 'undefined') {
|
localStorage.setItem('settings', JSON.stringify(settings))
|
||||||
localStorage.setItem('settings', JSON.stringify(settings))
|
|
||||||
}
|
|
||||||
if (settings.language) {
|
if (settings.language) {
|
||||||
locale.set(settings.language)
|
locale.set(settings.language)
|
||||||
} else {
|
} else {
|
||||||
@@ -227,3 +225,30 @@ $effect.root(() => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function isObject(item: any) {
|
||||||
|
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deep merge two objects.
|
||||||
|
* @param target
|
||||||
|
* @param ...sources
|
||||||
|
*/
|
||||||
|
function mergeDeep(target: any, ...sources: any[]) {
|
||||||
|
if (!sources.length) return target;
|
||||||
|
const source = sources.shift();
|
||||||
|
|
||||||
|
if (isObject(target) && isObject(source)) {
|
||||||
|
for (const key in source) {
|
||||||
|
if (isObject(source[key])) {
|
||||||
|
if (!target[key]) Object.assign(target, { [key]: {} });
|
||||||
|
mergeDeep(target[key], source[key]);
|
||||||
|
} else {
|
||||||
|
Object.assign(target, { [key]: source[key] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergeDeep(target, ...sources);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user