diff --git a/ecc/components/profile/profile.js b/ecc/components/profile/profile.js
index 4e83e701..930265ca 100644
--- a/ecc/components/profile/profile.js
+++ b/ecc/components/profile/profile.js
@@ -28,7 +28,6 @@ export class Profile extends LitElement {
seriesId: { type: String },
fieldlabels: { type: Object, reflect: true },
profile: { type: Object, reflect: true },
- profileCopy: { type: Object, reflect: true },
firstnamesearch: { type: Array },
lastnamesearch: { type: Array },
};
@@ -42,25 +41,29 @@ export class Profile extends LitElement {
this.profile = this.profile ?? { socialMedia: [{ link: '' }], isPlaceholder: true };
this.profileCopy = {};
- this.pendingSocialIndexes = [];
}
- addSocialMedia() {
+ addSocialMedia(shallow = false) {
const socialMedia = { link: '' };
- if (this.profile?.socialMedia) {
- this.profile.socialMedia.push(socialMedia);
+ const profile = shallow ? this.profileCopy : this.profile;
+ if (profile?.socialMedia) {
+ profile.socialMedia.push(socialMedia);
} else {
- this.profile.socialMedia = [socialMedia];
+ profile.socialMedia = [socialMedia];
}
this.requestUpdate();
}
- updateProfile(profile) {
- const updatedProfile = { ...this.profile, ...profile };
- this.dispatchEvent(new CustomEvent('update-profile', { detail: { profile: updatedProfile } }));
+ updateProfile(profile, shallow = false) {
+ if (shallow) {
+ this.profileCopy = { ...this.profileCopy, ...profile };
+ } else {
+ const updatedProfile = { ...this.profile, ...profile };
+ this.dispatchEvent(new CustomEvent('update-profile', { detail: { profile: updatedProfile } }));
+ }
}
- updateSocialMedia(index, value) {
+ updateSocialMedia(index, value, shallow = false) {
const tempServiceName = getServiceName(value);
// eslint-disable-next-line max-len
let serviceName = SUPPORTED_SOCIAL.find((service) => service.toLowerCase() === tempServiceName.toLowerCase());
@@ -68,18 +71,22 @@ export class Profile extends LitElement {
serviceName = 'Web';
}
// eslint-disable-next-line max-len
+ if (shallow) {
+ this.profileCopy.socialMedia[index] = { link: value, serviceName };
+ return;
+ }
+
this.profile.socialMedia[index] = { link: value, serviceName };
- this.pendingSocialIndexes.push(index);
this.requestUpdate();
}
- renderProfileTypePicker() {
+ renderProfileTypePicker(shallow = false) {
// eslint-disable-next-line max-len
- const fieldLabel = this.getRequiredProps().fieldLabelsJSON.chooseType ?? DEFAULT_FIELD_LABELS.chooseType;
+ const fieldLabel = this.getRequiredProps(shallow).fieldLabelsJSON.chooseType ?? DEFAULT_FIELD_LABELS.chooseType;
return html`
${fieldLabel} *
-
this.updateProfile({ type: event.target.value })}>
+ this.updateProfile({ type: event.target.value }, shallow)}>
${repeat(SPEAKER_TYPE, (type) => html`
${type}
`)}
@@ -87,17 +94,16 @@ export class Profile extends LitElement {
`;
}
- async saveProfile(e) {
+ async saveProfile(e, edited = false) {
const imageDropzone = this.shadowRoot.querySelector('image-dropzone');
const saveButton = e.target;
saveButton.pending = true;
try {
- const profile = { ...this.profile };
+ const profile = edited ? structuredClone(this.profileCopy) : structuredClone(this.profile);
profile.isPlaceholder = false;
- profile.socialMedia = this.profile.socialMedia.filter((sm) => sm.link !== '');
- this.profileCopy = {};
+ profile.socialMedia = profile.socialMedia.filter((sm) => sm.link !== '');
let respJson;
if (this.profile.speakerId) {
respJson = await updateSpeaker(profile, this.seriesId);
@@ -173,57 +179,58 @@ export class Profile extends LitElement {
return !this.profile.firstName || !this.profile.lastName || !this.profile.title;
}
- renderNameFieldWithSearchIntegrated() {
+ renderNameFieldWithSearchIntegrated(shallow = false) {
const {
firstNameData,
quietTextfieldConfig,
lastNameData,
firstNameSearchMap,
lastNameSearchMap,
- } = this.getRequiredProps();
+ } = this.getRequiredProps(shallow);
const searchFieldConfig = { ...quietTextfieldConfig, showImage: true, thumbnailType: 'circle' };
return html`
- this.updateProfile({ firstName: event.detail.value })} @entry-selected=${this.handleProfileSelection} searchdata=${JSON.stringify(this.firstnamesearch)} identifier='speakerId'>
- this.updateProfile({ lastName: event.detail.value })} @entry-selected=${this.handleProfileSelection} searchdata=${JSON.stringify(this.lastnamesearch)} identifier='speakerId'>
+ this.updateProfile({ firstName: event.detail.value }, shallow)} @entry-selected=${this.handleProfileSelection} searchdata=${JSON.stringify(this.firstnamesearch)} identifier='speakerId'>
+ this.updateProfile({ lastName: event.detail.value }, shallow)} @entry-selected=${this.handleProfileSelection} searchdata=${JSON.stringify(this.lastnamesearch)} identifier='speakerId'>
`;
}
- renderRemainingFormBody() {
+ renderRemainingFormBody(shallow = false) {
const {
// eslint-disable-next-line max-len
fieldLabelsJSON, quietTextfieldConfig, titleData, bioData, textareaConfig, socialMediaData, socialMediaConfig,
- } = this.getRequiredProps();
+ } = this.getRequiredProps(shallow);
+ const profile = shallow ? this.profileCopy : this.profile;
// eslint-disable-next-line max-len
- const imagefile = this.profile?.photo ? { ...this.profile.photo, url: this.profile.photo.imageUrl } : {};
+ const imagefile = profile?.photo ? { ...profile.photo, url: profile.photo.imageUrl } : {};
return html`
- this.updateProfile({ title: event.detail.value })}>
- this.updateProfile({ bio: event.detail.value })}>
+ this.updateProfile({ title: event.detail.value }, shallow)}>
+ this.updateProfile({ bio: event.detail.value }, shallow)}>
- { this.addSocialMedia(); }}>
+ { this.addSocialMedia(shallow); }}>
`;
}
@@ -234,49 +241,49 @@ export class Profile extends LitElement {
${this.renderRemainingFormBody()}`;
}
- renderNameFields() {
- const { firstNameData, quietTextfieldConfig, lastNameData } = this.getRequiredProps();
+ renderNameFields(shallow = false) {
+ const { firstNameData, quietTextfieldConfig, lastNameData } = this.getRequiredProps(shallow);
return html`
- this.updateProfile({ firstName: event.detail.value })}>
- this.updateProfile({ lastName: event.detail.value })}>
+ this.updateProfile({ firstName: event.detail.value }, shallow)}>
+ this.updateProfile({ lastName: event.detail.value }, shallow)}>
`;
}
renderProfileEditForm() {
return html`
- ${this.renderProfileTypePicker()}
- ${this.renderNameFields()}
- ${this.renderRemainingFormBody()}
+ ${this.renderProfileTypePicker(true)}
+ ${this.renderNameFields(true)}
+ ${this.renderRemainingFormBody(true)}
`;
}
- getRequiredProps() {
+ getRequiredProps(shallow = false) {
const fieldLabelsJSON = {
...DEFAULT_FIELD_LABELS,
...(this.fieldlabels ?? {}),
};
const firstNameData = {
- value: this.profile?.firstName,
+ value: shallow ? this.profileCopy?.firstName : this.profile?.firstName,
placeholder: fieldLabelsJSON.firstName,
helperText: fieldLabelsJSON.firstNameSubText,
};
const lastNameData = {
- value: this.profile?.lastName,
+ value: shallow ? this.profileCopy?.lastName : this.profile?.lastName,
placeholder: fieldLabelsJSON.lastName,
helperText: fieldLabelsJSON.lastNameSubText,
};
const bioData = {
- value: this.profile?.bio ?? '',
+ value: shallow ? this.profileCopy?.bio : this.profile?.bio || '',
placeholder: fieldLabelsJSON.bio,
helperText: fieldLabelsJSON.bioSubText,
};
const titleData = {
- value: this.profile?.title,
+ value: shallow ? this.profileCopy?.title : this.profile?.title,
placeholder: fieldLabelsJSON.title,
helperText: fieldLabelsJSON.titleSubText,
};
@@ -333,17 +340,8 @@ export class Profile extends LitElement {
`;
}
- revertProfile() {
- this.profileCopy.socialMedia = this.profileCopy.socialMedia.filter(
- (_, index) => !this.pendingSocialIndexes.includes(index),
- );
- this.pendingSocialIndexes = [];
- this.profile = { ...this.profileCopy };
- this.requestUpdate();
- }
-
initializeProfileCopy() {
- this.profileCopy = { ...this.profile };
+ this.profileCopy = structuredClone(this.profile);
this.requestUpdate();
}
@@ -355,11 +353,12 @@ export class Profile extends LitElement {
- ${this.renderProfileTypePicker(fieldLabelsJSON.chooseType)}
+ ${this.renderProfileTypePicker()}
${this.profile.firstName} ${this.profile.lastName}
${this.profile.photo?.imageUrl ? html`