Skip to content

Commit

Permalink
Use OnDialogClosing instead of OnDialogResult to remove dialog refere…
Browse files Browse the repository at this point in the history
…nce in MainLayout (#2476)

* Use OnDialogClosing instead of OnDialogResult

* Remove redundant event listener

---------

Co-authored-by: Adam Ratzman <[email protected]>
  • Loading branch information
adamint and Adam Ratzman committed Feb 27, 2024
1 parent 4f355a8 commit 1434b99
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
_shortcutManagerReference = DotNetObjectReference.Create(ShortcutManager);
_keyboardHandlers = await JS.InvokeAsync<IJSObjectReference>("window.registerGlobalKeydownListener", _shortcutManagerReference);
ShortcutManager.AddGlobalKeydownListener(this);

}
}

Expand All @@ -100,7 +101,7 @@ private async Task LaunchHelpAsync()
Width = "700px",
Height = "auto",
Id = HelpDialogId,
OnDialogResult = EventCallback.Factory.Create<DialogResult>(this, HandleDialogResult)
OnDialogClosing = EventCallback.Factory.Create<DialogInstance>(this, HandleDialogClose)
};

if (_openPageDialog is not null)
Expand All @@ -116,7 +117,7 @@ private async Task LaunchHelpAsync()
_openPageDialog = await DialogService.ShowDialogAsync<HelpDialog>(parameters).ConfigureAwait(true);
}

private void HandleDialogResult(DialogResult dialogResult)
private void HandleDialogClose(DialogInstance dialogResult)
{
_openPageDialog = null;
}
Expand All @@ -135,7 +136,7 @@ public async Task LaunchSettingsAsync()
Width = "300px",
Height = "auto",
Id = SettingsDialogId,
OnDialogResult = EventCallback.Factory.Create<DialogResult>(this, HandleDialogResult)
OnDialogClosing = EventCallback.Factory.Create<DialogInstance>(this, HandleDialogClose)
};

if (_openPageDialog is not null)
Expand Down Expand Up @@ -189,7 +190,7 @@ public async ValueTask DisposeAsync()
_themeChangedSubscription?.Dispose();
_locationChangingRegistration?.Dispose();
ShortcutManager.RemoveGlobalKeydownListener(this);

try
{
await JS.InvokeVoidAsync("window.unregisterGlobalKeydownListener", _keyboardHandlers);
Expand Down

0 comments on commit 1434b99

Please sign in to comment.