Remove button for avatars. Fixes #755
This commit is contained in:
parent
20f9bde88f
commit
2d776d3e01
2 changed files with 35 additions and 3 deletions
|
@ -451,6 +451,11 @@ impl Perform for Oper<SaveUserSettings> {
|
||||||
None => read_user.email,
|
None => read_user.email,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let avatar = match &data.avatar {
|
||||||
|
Some(avatar) => Some(avatar.to_owned()),
|
||||||
|
None => read_user.avatar,
|
||||||
|
};
|
||||||
|
|
||||||
let password_encrypted = match &data.new_password {
|
let password_encrypted = match &data.new_password {
|
||||||
Some(new_password) => {
|
Some(new_password) => {
|
||||||
match &data.new_password_verify {
|
match &data.new_password_verify {
|
||||||
|
@ -488,7 +493,7 @@ impl Perform for Oper<SaveUserSettings> {
|
||||||
name: read_user.name,
|
name: read_user.name,
|
||||||
email,
|
email,
|
||||||
matrix_user_id: data.matrix_user_id.to_owned(),
|
matrix_user_id: data.matrix_user_id.to_owned(),
|
||||||
avatar: data.avatar.to_owned(),
|
avatar,
|
||||||
password_encrypted,
|
password_encrypted,
|
||||||
preferred_username: read_user.preferred_username,
|
preferred_username: read_user.preferred_username,
|
||||||
updated: Some(naive_now()),
|
updated: Some(naive_now()),
|
||||||
|
|
31
ui/src/components/user.tsx
vendored
31
ui/src/components/user.tsx
vendored
|
@ -525,7 +525,7 @@ export class User extends Component<any, UserState> {
|
||||||
htmlFor="file-upload"
|
htmlFor="file-upload"
|
||||||
class="pointer ml-4 text-muted small font-weight-bold"
|
class="pointer ml-4 text-muted small font-weight-bold"
|
||||||
>
|
>
|
||||||
{!this.state.userSettingsForm.avatar ? (
|
{!this.checkSettingsAvatar ? (
|
||||||
<span class="btn btn-sm btn-secondary">
|
<span class="btn btn-sm btn-secondary">
|
||||||
{i18n.t('upload_avatar')}
|
{i18n.t('upload_avatar')}
|
||||||
</span>
|
</span>
|
||||||
|
@ -549,6 +549,18 @@ export class User extends Component<any, UserState> {
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
{this.checkSettingsAvatar && (
|
||||||
|
<div class="form-group">
|
||||||
|
<button
|
||||||
|
class="btn btn-secondary btn-block"
|
||||||
|
onClick={linkEvent(this, this.removeAvatar)}
|
||||||
|
>
|
||||||
|
{`${capitalizeFirstLetter(i18n.t('remove'))} ${i18n.t(
|
||||||
|
'avatar'
|
||||||
|
)}`}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>{i18n.t('language')}</label>
|
<label>{i18n.t('language')}</label>
|
||||||
<select
|
<select
|
||||||
|
@ -1061,6 +1073,22 @@ export class User extends Component<any, UserState> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeAvatar(i: User, event: any) {
|
||||||
|
event.preventDefault();
|
||||||
|
i.state.userSettingsLoading = true;
|
||||||
|
i.state.userSettingsForm.avatar = '';
|
||||||
|
i.setState(i.state);
|
||||||
|
|
||||||
|
WebSocketService.Instance.saveUserSettings(i.state.userSettingsForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
get checkSettingsAvatar(): boolean {
|
||||||
|
return (
|
||||||
|
this.state.userSettingsForm.avatar &&
|
||||||
|
this.state.userSettingsForm.avatar != ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
handleUserSettingsSubmit(i: User, event: any) {
|
handleUserSettingsSubmit(i: User, event: any) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.state.userSettingsLoading = true;
|
i.state.userSettingsLoading = true;
|
||||||
|
@ -1178,7 +1206,6 @@ export class User extends Component<any, UserState> {
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
} else if (res.op == UserOperation.SaveUserSettings) {
|
} else if (res.op == UserOperation.SaveUserSettings) {
|
||||||
let data = res.data as LoginResponse;
|
let data = res.data as LoginResponse;
|
||||||
this.state = this.emptyState;
|
|
||||||
this.state.userSettingsLoading = false;
|
this.state.userSettingsLoading = false;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
UserService.Instance.login(data);
|
UserService.Instance.login(data);
|
||||||
|
|
Loading…
Reference in a new issue