diff --git a/src/AliasVault.Client/Main/Components/Email/EmailModal.razor b/src/AliasVault.Client/Main/Components/Email/EmailModal.razor
index cb9e3a55d..e8c04e147 100644
--- a/src/AliasVault.Client/Main/Components/Email/EmailModal.razor
+++ b/src/AliasVault.Client/Main/Components/Email/EmailModal.razor
@@ -62,6 +62,15 @@
///
private string EmailBody = string.Empty;
+ ///
+ /// Close the modal.
+ ///
+ [JSInvokable]
+ public Task Close()
+ {
+ return OnClose.InvokeAsync(false);
+ }
+
///
protected override async Task OnInitializedAsync()
{
@@ -88,13 +97,4 @@
}
}
}
-
- ///
- /// Close the modal.
- ///
- [JSInvokable]
- private Task Close()
- {
- return OnClose.InvokeAsync(false);
- }
}
diff --git a/src/AliasVault.Client/Main/Components/Layout/ClickOutsideHandler.razor b/src/AliasVault.Client/Main/Components/Layout/ClickOutsideHandler.razor
index 6d3046cca..60644e7f1 100644
--- a/src/AliasVault.Client/Main/Components/Layout/ClickOutsideHandler.razor
+++ b/src/AliasVault.Client/Main/Components/Layout/ClickOutsideHandler.razor
@@ -10,57 +10,69 @@
[Parameter]
public EventCallback OnClose { get; set; }
- [Parameter] public string ContentId { get; set; } = "modal-content";
+ ///
+ /// The content id of the modal which is used to identity if a click is inside or outside the modal.
+ ///
+ [Parameter]
+ public string ContentId { get; set; } = "modal-content";
- [Parameter] public RenderFragment ChildContent { get; set; } = null!;
+ ///
+ /// The child content of the component.
+ ///
+ [Parameter]
+ public RenderFragment ChildContent { get; set; } = null!;
private DotNetObjectReference? ObjRef { get; set; }
- private IJSObjectReference module { get; set; } = null!;
- private bool IsModuleLoaded { get;set; } = false;
+ private IJSObjectReference? Module { get; set; } = null!;
+ ///
protected override async Task OnInitializedAsync()
{
await LoadModuleAsync();
}
- private async Task LoadModuleAsync()
- {
- if (!IsModuleLoaded)
- {
- Console.WriteLine("Loading module clckoutside");
-
- module = await JSRuntime.InvokeAsync("import", "./js/clickOutsideHandler.js");
- ObjRef = DotNetObjectReference.Create(this);
- IsModuleLoaded = true;
- }
- }
-
+ ///
protected override async Task OnParametersSetAsync()
{
await LoadModuleAsync();
- if (IsModuleLoaded)
+ if (Module != null)
{
- await module.InvokeVoidAsync("registerClickOutsideHandler", ObjRef, ContentId, nameof(CloseHandler));
+ await Module.InvokeVoidAsync("registerClickOutsideHandler", ObjRef, ContentId, nameof(CloseHandler));
}
}
+ ///
+ /// Call close handler on parent component.
+ ///
[JSInvokable]
public async Task CloseHandler()
{
- Console.WriteLine("Click outisde handler invoked");
await OnClose.InvokeAsync();
StateHasChanged();
}
+ ///
public async ValueTask DisposeAsync()
{
- if (module != null)
+ if (Module != null)
{
- await module.InvokeVoidAsync("unregisterClickOutsideHandler");
- await module.DisposeAsync();
+ await Module.InvokeVoidAsync("unregisterClickOutsideHandler");
+ await Module.DisposeAsync();
}
ObjRef?.Dispose();
}
+
+ ///
+ /// Load the JavaScript module.
+ ///
+ private async Task LoadModuleAsync()
+ {
+ if (Module == null)
+ {
+ Module = await JSRuntime.InvokeAsync("import", "./js/clickOutsideHandler.js");
+ ObjRef = DotNetObjectReference.Create(this);
+ }
+ }
}