implemented dynamic theme loading, working on user edit

This commit is contained in:
2025-07-01 22:24:23 +02:00
parent 691c317a57
commit 684e0b00dd
12 changed files with 178 additions and 61 deletions

View File

@@ -0,0 +1,27 @@
<script>
import { t } from '../../translations.svelte.js';
import { checkUser } from '../../user.svelte.js';
let { key, onUpdate, value } = $props();
let input = $state(false);
function edit(){
input = true;
}
function check_key(evt){
if (evt.key === 'Enter'){
input = false;
let obj = {};
obj[key] = value;
onUpdate(obj);
}
}
</script>
{#if input}
<input type="text" bind:value onkeyup={check_key} />
{:else}
<span onclick={edit}>{value}</span>
{/if}

View File

@@ -2,15 +2,20 @@
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import EditableField from './EditableField.svelte';
import ClickInput from './ClickInput.svelte';
async function patch(changeset){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/${user.id}`;
await fetch(url,{
const response = await fetch(url,{
method: 'PATCH',
credentials: 'include',
body: JSON.stringify(changeset)
})
});
if (response.ok) {
const json = await response.json();
for (let key of Object.keys(json)) user[key] = json[key];
}
}
</script>
<h1>{t('user.user_module')}</h1>
@@ -25,13 +30,22 @@
<th>{t('user.id')}</th>
<td>{user.id}</td>
</tr>
<EditableField key='user.name' value={user.name} onUpdate={patch} />
<tr>
<th>{t('user.name')}</th>
<td><ClickInput key='name' value={user.name} onUpdate={patch} /></td>
</tr>
<tr>
<th>{t('user.login')}</th>
<td>{user.login}</td>
</tr>
<EditableField key='user.email' value={user.email} onUpdate={patch} />
<EditableField key='user.language' value={user.language} onUpdate={patch} />
<tr>
<th>{t('user.email')}</th>
<td><ClickInput key='email' value={user.email} onUpdate={patch} /></td>
</tr>
<tr>
<th>{t('user.language')}</th>
<td><ClickInput key='language' value={user.language} onUpdate={patch} /></td>
</tr>
<tr>
<th>{t('user.theme')}</th>
<td>{user.theme}</td>