feat: add settings import/export
This commit is contained in:
1 parent
02912341f8
commit
1db0e0f880
3 files changed
+82
-14
No files matched your search
@@ -529,7 +529,9 @@
|
|||||||
"waitApplication": "Wait for your registration application to be accepted before logging in.",
|
"waitApplication": "Wait for your registration application to be accepted before logging in.",
|
||||||
"blockUser": "Blocked that user.",
|
"blockUser": "Blocked that user.",
|
||||||
"unblockUser": "Unblocked that user.",
|
"unblockUser": "Unblocked that user.",
|
||||||
"purgeUser": "Purged that user."
|
"purgeUser": "Purged that user.",
|
||||||
|
"settingsImport": "Successfully imported settings",
|
||||||
|
"settingsImportWarning": "The imported settings don't seem valid. Are you sure you want to import this?"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"title": "Settings",
|
"title": "Settings",
|
||||||
@@ -537,6 +539,9 @@
|
|||||||
"desktop": "Desktop",
|
"desktop": "Desktop",
|
||||||
"tablet": "Tablet",
|
"tablet": "Tablet",
|
||||||
"mobile": "Mobile",
|
"mobile": "Mobile",
|
||||||
|
"export": "Export",
|
||||||
|
"import": "Import",
|
||||||
|
"reset": "Reset",
|
||||||
"navigation": {
|
"navigation": {
|
||||||
"title": "Navigation",
|
"title": "Navigation",
|
||||||
"dockPos": {
|
"dockPos": {
|
||||||
|
|||||||
+1
-1
@@ -176,7 +176,7 @@ export const defaultSettings: Settings = {
|
|||||||
export const userSettings = writable(defaultSettings)
|
export const userSettings = writable(defaultSettings)
|
||||||
|
|
||||||
const migrate = (settings: any): Settings => {
|
const migrate = (settings: any): Settings => {
|
||||||
if (typeof settings.moderation.removalReasonPreset == 'string') {
|
if (typeof settings?.moderation?.removalReasonPreset == 'string') {
|
||||||
settings.moderation.presets = [
|
settings.moderation.presets = [
|
||||||
{
|
{
|
||||||
title: 'Preset 1',
|
title: 'Preset 1',
|
||||||
|
|||||||
@@ -12,12 +12,17 @@
|
|||||||
TextInput,
|
TextInput,
|
||||||
toast,
|
toast,
|
||||||
Popover,
|
Popover,
|
||||||
|
Modal,
|
||||||
|
TextArea,
|
||||||
} from 'mono-svelte'
|
} from 'mono-svelte'
|
||||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
import {
|
import {
|
||||||
|
ArrowDownTray,
|
||||||
ArrowPath,
|
ArrowPath,
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
|
ArrowUpOnSquare,
|
||||||
|
ArrowUpTray,
|
||||||
ChatBubbleOvalLeftEllipsis,
|
ChatBubbleOvalLeftEllipsis,
|
||||||
CheckCircle,
|
CheckCircle,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
@@ -39,26 +44,84 @@
|
|||||||
import { defaultLinks, iconOfLink } from '$lib/components/ui/navbar/link'
|
import { defaultLinks, iconOfLink } from '$lib/components/ui/navbar/link'
|
||||||
|
|
||||||
let pin: string = ''
|
let pin: string = ''
|
||||||
|
let importing = false
|
||||||
|
let importText = ''
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>{$t('settings.title')}</title>
|
<title>{$t('settings.title')}</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
|
{#if importing}
|
||||||
|
<Modal
|
||||||
|
bind:open={importing}
|
||||||
|
on:action={() => {
|
||||||
|
try {
|
||||||
|
if (importText == '') {
|
||||||
|
throw new Error('Import is empty')
|
||||||
|
}
|
||||||
|
const parsed = JSON.parse(importText)
|
||||||
|
const merged = { ...defaultSettings, ...parsed }
|
||||||
|
|
||||||
|
$userSettings = merged
|
||||||
|
|
||||||
|
toast({ content: $t('toast.settingsImport'), type: 'success' })
|
||||||
|
importing = false
|
||||||
|
} catch (err) {
|
||||||
|
// @ts-ignore
|
||||||
|
toast({ content: err, type: 'error' })
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
title={$t('routes.theme.import')}
|
||||||
|
action={$t('routes.theme.import')}
|
||||||
|
>
|
||||||
|
<TextArea bind:value={importText} style="font-family: monospace;" />
|
||||||
|
</Modal>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<h1 class="text-3xl font-bold flex justify-between">
|
<h1 class="text-3xl font-bold flex justify-between">
|
||||||
{$t('settings.title')}
|
{$t('settings.title')}
|
||||||
<Button
|
<div class="flex items-center">
|
||||||
size="square-md"
|
<Button
|
||||||
on:click={() => {
|
size="square-lg"
|
||||||
toast({
|
on:click={() => {
|
||||||
content: $t('toast.resetSettings'),
|
importText = ''
|
||||||
action: () => ($userSettings = defaultSettings),
|
importing = true
|
||||||
})
|
}}
|
||||||
}}
|
class="font-normal"
|
||||||
class="font-normal"
|
title={$t('settings.import')}
|
||||||
>
|
roundingSide="left"
|
||||||
<Icon src={ArrowPath} mini size="16" slot="prefix" />
|
>
|
||||||
</Button>
|
<Icon src={ArrowDownTray} mini size="18" slot="prefix" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="square-lg"
|
||||||
|
on:click={() => {
|
||||||
|
const json = JSON.stringify($userSettings)
|
||||||
|
navigator?.clipboard?.writeText?.(json)
|
||||||
|
toast({ content: $t('toast.copied') })
|
||||||
|
}}
|
||||||
|
class="font-normal"
|
||||||
|
title={$t('settings.export')}
|
||||||
|
rounding="none"
|
||||||
|
>
|
||||||
|
<Icon src={ArrowUpTray} mini size="18" slot="prefix" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="square-lg"
|
||||||
|
on:click={() => {
|
||||||
|
toast({
|
||||||
|
content: $t('toast.resetSettings'),
|
||||||
|
action: () => ($userSettings = defaultSettings),
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
class="font-normal"
|
||||||
|
title={$t('settings.reset')}
|
||||||
|
roundingSide="right"
|
||||||
|
>
|
||||||
|
<Icon src={ArrowPath} mini size="18" slot="prefix" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div class="flex flex-col gap-4" style="scroll-behavior: smooth;">
|
<div class="flex flex-col gap-4" style="scroll-behavior: smooth;">
|
||||||
|
|||||||
Reference in new issue
Block a user