]> Untitled Git - lemmy.git/commitdiff
Remove button for avatars. Fixes #755 (#924)
authorDessalines <dessalines@users.noreply.github.com>
Fri, 10 Jul 2020 00:04:09 +0000 (20:04 -0400)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 00:04:09 +0000 (20:04 -0400)
server/src/api/user.rs
ui/src/components/user.tsx

index 9b72a91997dec6d6287b5dbcb9b40e73cda801cb..1284c6608089d723a7580a3957881f09d639be5d 100644 (file)
@@ -451,6 +451,11 @@ impl Perform for Oper<SaveUserSettings> {
       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 {
       Some(new_password) => {
         match &data.new_password_verify {
@@ -488,7 +493,7 @@ impl Perform for Oper<SaveUserSettings> {
       name: read_user.name,
       email,
       matrix_user_id: data.matrix_user_id.to_owned(),
-      avatar: data.avatar.to_owned(),
+      avatar,
       password_encrypted,
       preferred_username: read_user.preferred_username,
       updated: Some(naive_now()),
index af72a3974f347acde0c3ee1bd1525d638c2ca642..0e1073635c01118c9a8596d7fc32453d5d6d5d6b 100644 (file)
@@ -535,7 +535,7 @@ export class User extends Component<any, UserState> {
                     htmlFor="file-upload"
                     class="pointer ml-4 text-muted small font-weight-bold"
                   >
-                    {!this.state.userSettingsForm.avatar ? (
+                    {!this.checkSettingsAvatar ? (
                       <span class="btn btn-sm btn-secondary">
                         {i18n.t('upload_avatar')}
                       </span>
@@ -559,6 +559,18 @@ export class User extends Component<any, UserState> {
                   />
                 </form>
               </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">
                 <label>{i18n.t('language')}</label>
                 <select
@@ -1073,6 +1085,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) {
     event.preventDefault();
     i.state.userSettingsLoading = true;
@@ -1190,7 +1218,6 @@ export class User extends Component<any, UserState> {
       this.setState(this.state);
     } else if (res.op == UserOperation.SaveUserSettings) {
       let data = res.data as LoginResponse;
-      this.state = this.emptyState;
       this.state.userSettingsLoading = false;
       this.setState(this.state);
       UserService.Instance.login(data);