Jelajahi Sumber

When username is changed in settings, profile link in header is automatically updated

theflametrooper 8 tahun lalu
induk
melakukan
f239de179a
1 mengubah file dengan 7 tambahan dan 5 penghapusan
  1. 7 5
      frontend/components/User/Settings.vue

+ 7 - 5
frontend/components/User/Settings.vue

@@ -56,18 +56,20 @@
 		methods: {
 			changeEmail: function () {
 				if (!this.user.email.address) return Toast.methods.addToast('Email cannot be empty', 8000);
-
 				this.socket.emit('users.updateEmail', this.user.email.address, res => {
 					if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
 					else Toast.methods.addToast('Successfully changed email address', 4000);
 				});
 			},
 			changeUsername: function () {
-				if (!this.user.username) return Toast.methods.addToast('Username cannot be empty', 8000);
-
-				this.socket.emit('users.updateUsername', this.user.username, res => {
+				let _this = this;
+				if (!_this.user.username) return Toast.methods.addToast('Username cannot be empty', 8000);
+				_this.socket.emit('users.updateUsername', _this.user.username, res => {
 					if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
-					else Toast.methods.addToast('Successfully changed username', 4000);
+					else {
+						Toast.methods.addToast('Successfully changed username', 4000);
+						_this.$parent.username = _this.user.username;
+					}
 				});
 			}
 		},