Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
scobru committed Oct 15, 2024
1 parent bcda520 commit dab1cf4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 49 deletions.
1 change: 0 additions & 1 deletion packages/svelte/src/app.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ p {
body {
background-color: var(--background-color);
color: var(--text-color);
font-family: var(--font-family);
}

h1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<div class="card w-90 bg-ableton-light-blue text-black rounded-none p-4 font-sans">
<div class="card-body">
<h2 class="card-title text-black font-medium text-2xl">Account Information</h2>
<AccountAvatar pub={pub} />
{#if globalAccount}
<AccountAvatar pub={pub || $user?.pub} />
{#if $globalAccount}
{#each accountFields as { key, label }}
<div class="form-control gap-2">
<label class="label ">
Expand Down Expand Up @@ -73,18 +73,6 @@
<p class="text-center">Caricamento account...</p>
{/if}

<h2 class="card-title text-black font-medium text-2xl mt-6">Profile Information</h2>
{#if profileFields.length > 0}
{#each profileFields as { key, label, value }}
<div class="form-control gap-2">
<label class="label">
<span class="label-text text-black font-medium">{label}</span>
</label>
<span readonly class="w-full text-left text-xs">{value}</span>
</div>
{/each}
{:else}
<p class="text-center">Nessuna informazione di profilo disponibile</p>
{/if}

</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let newFieldName = "";
let newFieldValue = "";
let editMode: { [key: string]: boolean } = {};
let editFields: { [key: string]: { label: string, value: string } } = {};
let editFields: { [key: string]: string } = {};
$: profileFields = $user.profile ?
Object.entries($user.profile)
Expand All @@ -19,41 +19,33 @@
value !== null &&
value !== undefined
)
.map(([key, value]) => ({ key, label: key.charAt(0).toUpperCase() + key.slice(1), value }))
.reduce((acc, [key, value]) => {
if (!acc.some(item => item.key.toLowerCase() === key.toLowerCase())) {
acc.push({ key, label: key.charAt(0).toUpperCase() + key.slice(1), value });
}
return acc;
}, [])
: [];
function handleUpdate(oldKey: string) {
const newKey = editFields[oldKey].label.toLowerCase();
const newValue = editFields[oldKey].value;
if (oldKey !== newKey) {
removeProfileField(oldKey);
addProfileField(newKey);
}
updateProfileField(newKey, newValue);
editMode[oldKey] = false;
delete editFields[oldKey];
// Forza l'aggiornamento dello store user
user.update(u => ({ ...u }));
function handleUpdate(key: string) {
const newValue = editFields[key];
updateProfileField(key, newValue);
editMode[key] = false;
delete editFields[key];
}
function handleAddField() {
if (newFieldName && newFieldValue) {
addProfileField(newFieldName.toLowerCase());
updateProfileField(newFieldName.toLowerCase(), newFieldValue);
addProfileField(newFieldName.toLowerCase(), newFieldValue);
newFieldName = "";
newFieldValue = "";
// Forza l'aggiornamento dello store user
user.update(u => ({ ...u }));
}
}
function toggleEditMode(key: string, label: string, value: string) {
function toggleEditMode(key: string, value: string) {
editMode[key] = !editMode[key];
if (editMode[key]) {
editFields[key] = { label, value };
editFields[key] = value;
} else {
delete editFields[key];
}
Expand All @@ -72,16 +64,11 @@
<div class="form-control gap-2 mb-4">
{#if editMode[key]}
<div class="flex gap-2">
<span class="text-black font-medium flex-grow">{label}</span>
<input
type="text"
class="input input-bordered flex-grow"
bind:value={editFields[key].label}
placeholder="Field Name"
/>
<input
type="text"
class="input input-bordered flex-grow"
bind:value={editFields[key].value}
bind:value={editFields[key]}
placeholder="Field Value"
/>
<button
Expand All @@ -95,7 +82,7 @@
<div class="flex justify-between items-center">
<span class="text-black font-medium">{label}</span>
<span class="text-sm">{value}</span>
<button class="btn btn-sm btn-outline" on:click={() => toggleEditMode(key, label, value)}>
<button class="btn btn-sm btn-outline" on:click={() => toggleEditMode(key, value)}>
Edit
</button>
</div>
Expand All @@ -110,10 +97,10 @@
<label class="label">
<span class="label-text text-black font-medium">Add New Field</span>
</label>
<div class="flex gap-2">
<div class="flex flex-col gap-2">
<input
type="text"
class="input input-bordered flex-grow"
class="input input-bordered flex-grow "
placeholder="Field Name"
bind:value={newFieldName}
/>
Expand Down

0 comments on commit dab1cf4

Please sign in to comment.