From d17fab17bacea796e022182155f2f7ff16c6880c Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Mon, 16 Aug 2021 09:40:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=96=E8=BE=91=E8=B5=84?= =?UTF-8?q?=E6=96=99=E7=9B=91=E5=90=AC=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E6=97=B6=E6=9B=B4=E6=94=B9=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E6=AF=94=E8=BE=83=E7=9A=84=E5=8E=9F=E5=A7=8B=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Windows/UserProfileWindowViewModel.shared.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/UserProfileWindowViewModel.shared.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/UserProfileWindowViewModel.shared.cs index 92f9b1976..556e7f86a 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/UserProfileWindowViewModel.shared.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/UserProfileWindowViewModel.shared.cs @@ -1,3 +1,4 @@ +using DynamicData.Binding; using ReactiveUI; using System.Application.Entities; using System.Application.Models; @@ -46,6 +47,12 @@ namespace System.Application.UI.ViewModels userInfoSource = await userManager.GetCurrentUserInfoAsync() ?? new UserInfoDTO(); userInfoValue = Serializable.SMP(userInfoSource); + UserService.Current.User?.WhenValueChanged(x => x, false).Subscribe(x => + { + if (x == null || isSubmited) return; + userInfoValue = Serializable.SMP(x); + }).AddTo(this); + // (SetFields)DTO => VM _NickName = userInfoSource.NickName; _Gender = userInfoSource.Gender; @@ -55,7 +62,7 @@ namespace System.Application.UI.ViewModels userInfoSource = Serializable.DMP(userInfoValue) ?? throw new ArgumentNullException(nameof(userInfoSource)); // IsModifySubscribe - void SubscribeOnNext(T value, Action onNext) + void SubscribeOnNext(T? value, Action onNext) { onNext(value); var currentUserInfoValue = Serializable.SMP(userInfoSource); @@ -67,7 +74,7 @@ namespace System.Application.UI.ViewModels #else UserProfileWindowViewModel #endif - , T>> expression, Action onNext) => this.WhenAnyValue(expression).Subscribe(value => SubscribeOnNext(value, onNext)).AddTo(this); + , T?>> expression, Action onNext) => this.WhenAnyValue(expression).Subscribe(value => SubscribeOnNext(value, onNext)).AddTo(this); SubscribeFormItem(x => x.NickName, x => userInfoSource.NickName = x ?? string.Empty); SubscribeFormItem(x => x.Gender, x => userInfoSource.Gender = x); SubscribeFormItem(x => x.BirthDate, x => userInfoSource.SetBirthDate(x)); @@ -140,6 +147,7 @@ namespace System.Application.UI.ViewModels public bool IsComplete { get; set; } + bool isSubmited; public async void Submit() { if (!IsModify || IsLoading) return; @@ -161,6 +169,7 @@ namespace System.Application.UI.ViewModels var response = await ICloudServiceClient.Instance.Manage.EditUserProfile(request); if (response.IsSuccess) { + isSubmited = true; await userManager.SetCurrentUserInfoAsync(userInfoSource, true); await UserService.Current.RefreshUserAsync();