Sign in , out ,register.
This commit is contained in:
@@ -10,11 +10,13 @@ using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Windows.UI;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Extensions;
|
||||
using Wino.Mail.WinUI.Activation;
|
||||
using Wino.Mail.WinUI.Extensions;
|
||||
using Wino.Mail.WinUI.Interfaces;
|
||||
using Wino.Mail.WinUI.Views;
|
||||
using Wino.Messaging.Client.Shell;
|
||||
@@ -28,11 +30,15 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
|
||||
IRecipient<InfoBarMessageRequested>,
|
||||
IRecipient<TitleBarShellContentUpdated>,
|
||||
IRecipient<SynchronizationActionsAdded>,
|
||||
IRecipient<SynchronizationActionsCompleted>
|
||||
IRecipient<SynchronizationActionsCompleted>,
|
||||
IRecipient<WinoAccountSignedInMessage>,
|
||||
IRecipient<WinoAccountSignedOutMessage>
|
||||
{
|
||||
public IStatePersistanceService StatePersistanceService { get; } = WinoApplication.Current.Services.GetService<IStatePersistanceService>() ?? throw new Exception("StatePersistanceService not registered in DI container.");
|
||||
public IPreferencesService PreferencesService { get; } = WinoApplication.Current.Services.GetService<IPreferencesService>() ?? throw new Exception("PreferencesService not registered in DI container.");
|
||||
public INavigationService NavigationService { get; } = WinoApplication.Current.Services.GetService<INavigationService>() ?? throw new Exception("NavigationService not registered in DI container.");
|
||||
private IMailDialogService MailDialogService { get; } = WinoApplication.Current.Services.GetRequiredService<IMailDialogService>();
|
||||
private IWinoAccountProfileService WinoAccountProfileService { get; } = WinoApplication.Current.Services.GetRequiredService<IWinoAccountProfileService>();
|
||||
|
||||
public ICommand ShowWinoCommand { get; set; }
|
||||
public ICommand ShowWinoCalendarCommand { get; set; }
|
||||
@@ -180,26 +186,7 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
|
||||
|
||||
public void Receive(InfoBarMessageRequested message)
|
||||
{
|
||||
DispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(message.ActionButtonTitle) || message.Action == null)
|
||||
{
|
||||
ShellInfoBar.ActionButton = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
ShellInfoBar.ActionButton = new Button()
|
||||
{
|
||||
Content = message.ActionButtonTitle,
|
||||
Command = new RelayCommand(message.Action)
|
||||
};
|
||||
}
|
||||
|
||||
ShellInfoBar.Message = message.Message;
|
||||
ShellInfoBar.Title = message.Title;
|
||||
ShellInfoBar.Severity = message.Severity.AsMUXCInfoBarSeverity();
|
||||
ShellInfoBar.IsOpen = true;
|
||||
});
|
||||
ShowInfoBarMessage(message);
|
||||
}
|
||||
|
||||
public void Receive(SynchronizationActionsAdded message)
|
||||
@@ -226,6 +213,16 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
|
||||
});
|
||||
}
|
||||
|
||||
public void Receive(WinoAccountSignedInMessage message)
|
||||
{
|
||||
DispatcherQueue.TryEnqueue(() => UpdateWinoAccountState(message.Account));
|
||||
}
|
||||
|
||||
public void Receive(WinoAccountSignedOutMessage message)
|
||||
{
|
||||
DispatcherQueue.TryEnqueue(() => UpdateWinoAccountState(null));
|
||||
}
|
||||
|
||||
private void UpdateSyncStatusVisibility()
|
||||
{
|
||||
SyncStatusButton.Visibility = SyncActionItems.Any()
|
||||
@@ -329,6 +326,8 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
|
||||
WeakReferenceMessenger.Default.Register<InfoBarMessageRequested>(this);
|
||||
WeakReferenceMessenger.Default.Register<SynchronizationActionsAdded>(this);
|
||||
WeakReferenceMessenger.Default.Register<SynchronizationActionsCompleted>(this);
|
||||
WeakReferenceMessenger.Default.Register<WinoAccountSignedInMessage>(this);
|
||||
WeakReferenceMessenger.Default.Register<WinoAccountSignedOutMessage>(this);
|
||||
}
|
||||
|
||||
private void UnregisterRecipients()
|
||||
@@ -338,6 +337,118 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
|
||||
WeakReferenceMessenger.Default.Unregister<InfoBarMessageRequested>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<SynchronizationActionsAdded>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<SynchronizationActionsCompleted>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<WinoAccountSignedInMessage>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<WinoAccountSignedOutMessage>(this);
|
||||
}
|
||||
|
||||
private void ShowInfoBarMessage(InfoBarMessageRequested message)
|
||||
{
|
||||
DispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(message.ActionButtonTitle) || message.Action == null)
|
||||
{
|
||||
ShellInfoBar.ActionButton = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
ShellInfoBar.ActionButton = new Button()
|
||||
{
|
||||
Content = message.ActionButtonTitle,
|
||||
Command = new RelayCommand(message.Action)
|
||||
};
|
||||
}
|
||||
|
||||
ShellInfoBar.Message = message.Message;
|
||||
ShellInfoBar.Title = message.Title;
|
||||
ShellInfoBar.Severity = message.Severity.AsMUXCInfoBarSeverity();
|
||||
ShellInfoBar.IsOpen = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateWinoAccountState(WinoAccount? account)
|
||||
{
|
||||
var isSignedIn = account != null;
|
||||
|
||||
WinoAccountSignedOutView.Visibility = isSignedIn ? Visibility.Collapsed : Visibility.Visible;
|
||||
WinoAccountSignedInView.Visibility = isSignedIn ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
var initials = GetInitials(account?.Email);
|
||||
|
||||
WinoAccountButtonPicture.Initials = initials;
|
||||
WinoAccountFlyoutPicture.Initials = initials;
|
||||
WinoAccountButtonPicture.DisplayName = account?.Email ?? Translator.WinoAccount_Titlebar_SignedOutTitle;
|
||||
WinoAccountFlyoutPicture.DisplayName = account?.Email ?? Translator.WinoAccount_Titlebar_SignedOutTitle;
|
||||
|
||||
WinoAccountFlyoutEmailText.Text = account?.Email ?? string.Empty;
|
||||
WinoAccountFlyoutStatusText.Text = account == null
|
||||
? string.Empty
|
||||
: string.Format(Translator.WinoAccount_Titlebar_SignedInStatus, account.AccountStatus);
|
||||
}
|
||||
|
||||
private static string GetInitials(string? email)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(email))
|
||||
{
|
||||
return "W";
|
||||
}
|
||||
|
||||
var localPart = email.Split('@')[0];
|
||||
var segments = localPart
|
||||
.Split(['.', '_', '-', ' '], StringSplitOptions.RemoveEmptyEntries)
|
||||
.Where(segment => !string.IsNullOrWhiteSpace(segment))
|
||||
.Take(2)
|
||||
.ToArray();
|
||||
|
||||
if (segments.Length == 0)
|
||||
{
|
||||
return email[..1].ToUpperInvariant();
|
||||
}
|
||||
|
||||
return string.Concat(segments.Select(segment => char.ToUpperInvariant(segment[0])));
|
||||
}
|
||||
|
||||
private async void RegisterWinoAccountClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var account = await MailDialogService.ShowWinoAccountRegistrationDialogAsync();
|
||||
if (account != null)
|
||||
{
|
||||
ShowInfoBarMessage(new InfoBarMessageRequested(
|
||||
InfoBarMessageType.Success,
|
||||
Translator.GeneralTitle_Info,
|
||||
string.Format(Translator.WinoAccount_RegisterSuccessMessage, account.Email)));
|
||||
}
|
||||
}
|
||||
|
||||
private async void LoginWinoAccountClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var account = await MailDialogService.ShowWinoAccountLoginDialogAsync();
|
||||
if (account != null)
|
||||
{
|
||||
ShowInfoBarMessage(new InfoBarMessageRequested(
|
||||
InfoBarMessageType.Success,
|
||||
Translator.GeneralTitle_Info,
|
||||
string.Format(Translator.WinoAccount_LoginSuccessMessage, account.Email)));
|
||||
}
|
||||
}
|
||||
|
||||
private async void SignOutWinoAccountClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var activeAccount = await WinoAccountProfileService.GetActiveAccountAsync();
|
||||
if (activeAccount == null)
|
||||
{
|
||||
ShowInfoBarMessage(new InfoBarMessageRequested(
|
||||
InfoBarMessageType.Warning,
|
||||
Translator.GeneralTitle_Info,
|
||||
Translator.WinoAccount_SignOut_NoAccountMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
await WinoAccountProfileService.SignOutAsync();
|
||||
|
||||
ShowInfoBarMessage(new InfoBarMessageRequested(
|
||||
InfoBarMessageType.Success,
|
||||
Translator.GeneralTitle_Info,
|
||||
string.Format(Translator.WinoAccount_SignOut_SuccessMessage, activeAccount.Email)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user