feat: add name editing
This commit is contained in:
1 parent
926af69ec5
commit
9c9e5dff76
4 files changed
+44
-6
No files matched your search
@@ -366,7 +366,11 @@
|
||||
"delete": {
|
||||
"title": "Delete Theme",
|
||||
"confirm": "Confirm"
|
||||
}
|
||||
},
|
||||
"default": "Default",
|
||||
"classic": "Classic",
|
||||
"imported": "Your Theme",
|
||||
"new": "New Theme"
|
||||
}
|
||||
},
|
||||
"community": {
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { env } from '$env/dynamic/public'
|
||||
import { getDefaultTheme, presets } from './presets'
|
||||
import { browser } from '$app/environment'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
type ColorScheme = 'system' | 'light' | 'dark'
|
||||
|
||||
@@ -164,9 +165,11 @@ function loadColorScheme() {
|
||||
function loadTheme() {
|
||||
if (!browser) return
|
||||
const localTheme = localStorage.getItem('themeData')
|
||||
|
||||
if (localTheme) {
|
||||
return JSON.parse(localTheme)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -174,4 +177,21 @@ if (browser) {
|
||||
try {
|
||||
loadColorScheme()
|
||||
} catch (e) {}
|
||||
try {
|
||||
const oldColors = localStorage.getItem('colors')
|
||||
if (oldColors) {
|
||||
themeData.update((td) => ({
|
||||
...td,
|
||||
themes: [
|
||||
...td.themes,
|
||||
{
|
||||
id: Math.max(...td.themes.map((t) => t.id)) + 1,
|
||||
colors: JSON.parse(oldColors),
|
||||
name: t.get('routes.theme.preset.imported') ?? 'Your Theme',
|
||||
},
|
||||
],
|
||||
}))
|
||||
localStorage.removeItem('colors')
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
@@ -61,14 +61,14 @@
|
||||
gap-4 overflow-auto max-h-72"
|
||||
>
|
||||
{#each $themeData.themes as theme}
|
||||
<ThemePreset {theme} />
|
||||
<ThemePreset bind:theme />
|
||||
{/each}
|
||||
<button
|
||||
on:click={() => {
|
||||
const newTheme = {
|
||||
id: Math.max(...$themeData.themes.map((t) => t.id)) + 1,
|
||||
colors: getDefaultColors(),
|
||||
name: `New Theme`,
|
||||
name: $t('routes.theme.preset.new'),
|
||||
}
|
||||
|
||||
$themeData.themes = [...$themeData.themes, newTheme]
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/translations'
|
||||
import { calculateVars, themeData, type Theme } from '$lib/ui/colors'
|
||||
import { action, Button, Material, modal } from 'mono-svelte'
|
||||
import { action, Button, Material, modal, TextInput } from 'mono-svelte'
|
||||
import { CheckCircle, Icon, Trash } from 'svelte-hero-icons'
|
||||
|
||||
export let theme: Theme
|
||||
|
||||
let editing
|
||||
let editingName = false
|
||||
</script>
|
||||
|
||||
<button class="h-full" on:click={() => ($themeData.currentTheme = theme.id)}>
|
||||
@@ -40,11 +40,25 @@
|
||||
/>
|
||||
{/if}
|
||||
<div class="px-4 py-2 flex items-center gap-1 justify-between">
|
||||
<span class="font-medium text-lg font-display">{theme.name}</span>
|
||||
{#if editingName}
|
||||
<form on:submit|preventDefault={() => (editingName = false)}>
|
||||
<TextInput bind:value={theme.name}></TextInput>
|
||||
</form>
|
||||
{:else}
|
||||
<button
|
||||
on:click={() => {
|
||||
if (theme.id > 0) editingName = true
|
||||
}}
|
||||
class="text-left font-medium text-lg font-display"
|
||||
>
|
||||
{theme.name}
|
||||
</button>
|
||||
{/if}
|
||||
{#if theme.id > 0}
|
||||
<Button
|
||||
color="ghost"
|
||||
size="square-md"
|
||||
class="flex-shrink-0"
|
||||
on:click={() => {
|
||||
modal({
|
||||
actions: [
|
||||
|
||||
Reference in new issue
Block a user