Add MainService for state management and update Index and AuthDialog to utilize it

This commit is contained in:
masoodafar-web
2025-11-20 21:07:05 +03:30
parent 30bac23114
commit 973beb9e2f
5 changed files with 47 additions and 12 deletions

View File

@@ -6,7 +6,7 @@ using System.Security.Cryptography;
namespace FrontOffice.Main.Pages; namespace FrontOffice.Main.Pages;
public partial class Index public partial class Index:IDisposable
{ {
[Inject] private PackageContract.PackageContractClient PackageClient { get; set; } = default!; [Inject] private PackageContract.PackageContractClient PackageClient { get; set; } = default!;
[Inject] private MobileNumberEncryptor Encryptor { get; set; } [Inject] private MobileNumberEncryptor Encryptor { get; set; }
@@ -17,7 +17,25 @@ public partial class Index
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
MainService.OnChangeHandler +=async () =>
{
await InvokeAsync(StateHasChanged);
};
await LoadPackagesAsync(); await LoadPackagesAsync();
//string mobileNumber = "09387342688";
//// انکریپت کردن
//string encrypted = Encryptor.EncryptMobileNumber(mobileNumber);
//Console.WriteLine($"Encrypted: {encrypted}");
//// دیکریپت کردن برای تست
//string decrypted = Encryptor.DecryptMobileNumber(encrypted);
//Console.WriteLine($"Decrypted: {decrypted}");
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (await AuthService.IsAuthenticatedAsync()) if (await AuthService.IsAuthenticatedAsync())
{ {
if ((await AuthService.IsCompleteRegisterAsync())) if ((await AuthService.IsCompleteRegisterAsync()))
@@ -29,16 +47,7 @@ public partial class Index
Navigation.NavigateTo(RouteConstants.Registration.Wizard); Navigation.NavigateTo(RouteConstants.Registration.Wizard);
} }
} }
await base.OnAfterRenderAsync(firstRender);
//string mobileNumber = "09387342688";
//// انکریپت کردن
//string encrypted = Encryptor.EncryptMobileNumber(mobileNumber);
//Console.WriteLine($"Encrypted: {encrypted}");
//// دیکریپت کردن برای تست
//string decrypted = Encryptor.DecryptMobileNumber(encrypted);
//Console.WriteLine($"Decrypted: {decrypted}");
} }
private async Task LoadPackagesAsync() private async Task LoadPackagesAsync()
@@ -108,4 +117,12 @@ public partial class Index
new("چه درگاه‌هایی پشتیبانی می‌شود؟", "Stripe و PayPal یا درگاه اختصاصی از طریق وب‌هوک‌ها."), new("چه درگاه‌هایی پشتیبانی می‌شود؟", "Stripe و PayPal یا درگاه اختصاصی از طریق وب‌هوک‌ها."),
new("می‌توانم داده‌ها را خروجی بگیرم؟", "هر زمان از داشبورد ادمین خروجی CSV/Excel بگیرید."), new("می‌توانم داده‌ها را خروجی بگیرم؟", "هر زمان از داشبورد ادمین خروجی CSV/Excel بگیرید."),
}; };
public void Dispose()
{
MainService.OnChangeHandler -=async () =>
{
await InvokeAsync(StateHasChanged);
};
}
} }

View File

@@ -12,6 +12,7 @@ builder.Services.AddServerSideBlazor();
#region AddCommonServices #region AddCommonServices
builder.Services.AddCommonServices(); builder.Services.AddCommonServices();
builder.Services.AddSingleton<MainService>();
#endregion #endregion
#region AddGrpcServices #region AddGrpcServices

View File

@@ -231,7 +231,10 @@ public partial class AuthDialog : IDisposable
{ {
MudDialog?.Close(); MudDialog?.Close();
} }
await OnLoginSuccess.InvokeAsync(); await OnLoginSuccess.InvokeAsync();
await InvokeAsync(StateHasChanged);
MainService.OnOnChangeHandler();
// await OnLoginSuccessAsync(); // await OnLoginSuccessAsync();
return true; return true;
} }

View File

@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Components;
namespace FrontOffice.Main.Utilities;
public class MainService
{
public event Action OnChangeHandler;
public virtual void OnOnChangeHandler()
{
OnChangeHandler?.Invoke();
}
}

View File

@@ -17,3 +17,4 @@
@inject IDialogService DialogService @inject IDialogService DialogService
@inject IJSRuntime JSRuntime @inject IJSRuntime JSRuntime
@inject ISnackbar Snackbar @inject ISnackbar Snackbar
@inject MainService MainService