mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
fix warnings; tidy up a bit more
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
namespace CommunityToolkitExample;
|
||||
|
||||
internal enum LoginAction
|
||||
internal enum LoginActions
|
||||
{
|
||||
Clear,
|
||||
Validation,
|
||||
LoginProgress
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Terminal.Gui;
|
||||
|
||||
namespace CommunityToolkitExample;
|
||||
|
||||
internal partial class LoginView : IRecipient<Message<LoginAction>>
|
||||
internal partial class LoginView : IRecipient<Message<LoginActions>>
|
||||
{
|
||||
public LoginView (LoginViewModel viewModel)
|
||||
{
|
||||
@@ -14,12 +14,10 @@ internal partial class LoginView : IRecipient<Message<LoginAction>>
|
||||
usernameInput.TextChanged += (_, _) =>
|
||||
{
|
||||
ViewModel.Username = usernameInput.Text;
|
||||
SetText ();
|
||||
};
|
||||
passwordInput.TextChanged += (_, _) =>
|
||||
{
|
||||
ViewModel.Password = passwordInput.Text;
|
||||
SetText ();
|
||||
};
|
||||
loginButton.Accept += (_, _) =>
|
||||
{
|
||||
@@ -30,7 +28,6 @@ internal partial class LoginView : IRecipient<Message<LoginAction>>
|
||||
clearButton.Accept += (_, _) =>
|
||||
{
|
||||
ViewModel.ClearCommand.Execute (null);
|
||||
SetText ();
|
||||
};
|
||||
|
||||
Initialized += (_, _) => { ViewModel.Initialized (); };
|
||||
@@ -38,16 +35,23 @@ internal partial class LoginView : IRecipient<Message<LoginAction>>
|
||||
|
||||
public LoginViewModel ViewModel { get; set; }
|
||||
|
||||
public void Receive (Message<LoginAction> message)
|
||||
public void Receive (Message<LoginActions> message)
|
||||
{
|
||||
switch (message.Value)
|
||||
{
|
||||
case LoginAction.LoginProgress:
|
||||
case LoginActions.Clear:
|
||||
{
|
||||
loginProgressLabel.Text = ViewModel.LoginProgressMessage;
|
||||
validationLabel.Text = ViewModel.ValidationMessage;
|
||||
validationLabel.ColorScheme = ViewModel.ValidationColorScheme;
|
||||
break;
|
||||
}
|
||||
case LoginActions.LoginProgress:
|
||||
{
|
||||
loginProgressLabel.Text = ViewModel.LoginProgressMessage;
|
||||
break;
|
||||
}
|
||||
case LoginAction.Validation:
|
||||
case LoginActions.Validation:
|
||||
{
|
||||
validationLabel.Text = ViewModel.ValidationMessage;
|
||||
validationLabel.ColorScheme = ViewModel.ValidationColorScheme;
|
||||
|
||||
@@ -11,6 +11,7 @@ internal partial class LoginViewModel : ObservableObject
|
||||
private const string INVALID_LOGIN_MESSAGE = "Please enter a valid user name and password.";
|
||||
private const string LOGGING_IN_PROGRESS_MESSAGE = "Logging in...";
|
||||
private const string VALID_LOGIN_MESSAGE = "The input is valid!";
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _canLogin;
|
||||
|
||||
@@ -26,6 +27,7 @@ internal partial class LoginViewModel : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private string _usernameLengthMessage;
|
||||
|
||||
[ObservableProperty]
|
||||
private ColorScheme? _validationColorScheme;
|
||||
|
||||
@@ -33,6 +35,13 @@ internal partial class LoginViewModel : ObservableObject
|
||||
private string _validationMessage;
|
||||
public LoginViewModel ()
|
||||
{
|
||||
_loginProgressMessage = string.Empty;
|
||||
_password = string.Empty;
|
||||
_passwordLengthMessage = string.Empty;
|
||||
_username = string.Empty;
|
||||
_usernameLengthMessage = string.Empty;
|
||||
_validationMessage = string.Empty;
|
||||
|
||||
Username = string.Empty;
|
||||
Password = string.Empty;
|
||||
|
||||
@@ -81,35 +90,39 @@ internal partial class LoginViewModel : ObservableObject
|
||||
{
|
||||
Username = string.Empty;
|
||||
Password = string.Empty;
|
||||
SendMessage (LoginAction.Validation);
|
||||
SendMessage (LoginAction.LoginProgress, DEFAULT_LOGIN_PROGRESS_MESSAGE);
|
||||
SendMessage (LoginActions.Clear, DEFAULT_LOGIN_PROGRESS_MESSAGE);
|
||||
}
|
||||
|
||||
private async Task Login ()
|
||||
{
|
||||
SendMessage (LoginAction.LoginProgress, LOGGING_IN_PROGRESS_MESSAGE);
|
||||
SendMessage (LoginActions.LoginProgress, LOGGING_IN_PROGRESS_MESSAGE);
|
||||
await Task.Delay (TimeSpan.FromSeconds (1));
|
||||
Clear ();
|
||||
}
|
||||
|
||||
private void SendMessage (LoginAction loginAction, string message = "")
|
||||
private void SendMessage (LoginActions loginAction, string message = "")
|
||||
{
|
||||
switch (loginAction)
|
||||
{
|
||||
case LoginAction.LoginProgress:
|
||||
case LoginActions.Clear:
|
||||
LoginProgressMessage = message;
|
||||
ValidationMessage = INVALID_LOGIN_MESSAGE;
|
||||
ValidationColorScheme = Colors.ColorSchemes ["Error"];
|
||||
break;
|
||||
case LoginActions.LoginProgress:
|
||||
LoginProgressMessage = message;
|
||||
break;
|
||||
case LoginAction.Validation:
|
||||
case LoginActions.Validation:
|
||||
ValidationMessage = CanLogin ? VALID_LOGIN_MESSAGE : INVALID_LOGIN_MESSAGE;
|
||||
ValidationColorScheme = CanLogin ? Colors.ColorSchemes ["Base"] : Colors.ColorSchemes ["Error"];
|
||||
break;
|
||||
}
|
||||
WeakReferenceMessenger.Default.Send (new Message<LoginAction> { Value = loginAction });
|
||||
WeakReferenceMessenger.Default.Send (new Message<LoginActions> { Value = loginAction });
|
||||
}
|
||||
|
||||
private void ValidateLogin ()
|
||||
{
|
||||
CanLogin = !string.IsNullOrEmpty (Username) && !string.IsNullOrEmpty (Password);
|
||||
SendMessage (LoginAction.Validation);
|
||||
SendMessage (LoginActions.Validation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
internal class Message<T>
|
||||
{
|
||||
public T Value { get; set; }
|
||||
public T? Value { get; set; }
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace CommunityToolkitExample;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static IServiceProvider Services { get; private set; }
|
||||
public static IServiceProvider? Services { get; private set; }
|
||||
|
||||
private static void Main (string [] args)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user