diff --git a/src/Inc.TeamAssistant.Stories/Features/AcceptCookieDialog.stories.razor b/src/Inc.TeamAssistant.Stories/Features/AcceptCookieDialog.stories.razor index cfeb8177..61dbc81b 100644 --- a/src/Inc.TeamAssistant.Stories/Features/AcceptCookieDialog.stories.razor +++ b/src/Inc.TeamAssistant.Stories/Features/AcceptCookieDialog.stories.razor @@ -3,13 +3,13 @@ @code { - private bool _isShow = true; - - private void HideDialog() => _isShow = false; + private AcceptCookieDialog? _dialog; + + protected override Task OnAfterRenderAsync(bool firstRender) => _dialog?.Open() ?? Task.CompletedTask; } \ No newline at end of file diff --git a/src/Inc.TeamAssistant.Stories/Properties/launchSettings.json b/src/Inc.TeamAssistant.Stories/Properties/launchSettings.json index 9ee471c2..3d669f9d 100644 --- a/src/Inc.TeamAssistant.Stories/Properties/launchSettings.json +++ b/src/Inc.TeamAssistant.Stories/Properties/launchSettings.json @@ -5,7 +5,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "http://localhost:5101", + "applicationUrl": "http://localhost:8001", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/src/Inc.TeamAssistant.WebUI/Features/Layouts/AcceptCookieDialog.razor b/src/Inc.TeamAssistant.WebUI/Features/Layouts/AcceptCookieDialog.razor index dcbf8c95..b5f3f9d1 100644 --- a/src/Inc.TeamAssistant.WebUI/Features/Layouts/AcceptCookieDialog.razor +++ b/src/Inc.TeamAssistant.WebUI/Features/Layouts/AcceptCookieDialog.razor @@ -1,6 +1,6 @@ @inject IStringLocalizer Localizer -@if (IsShow) +@if (_isOpen) {
@@ -13,15 +13,22 @@ } @code { - /// - /// Visualizes the dialog. - /// - [Parameter, EditorRequired] - public bool IsShow { get; set; } - - /// - /// Accepted event. - /// - [Parameter, EditorRequired] - public EventCallback Accepted { get; set; } + private bool _isOpen = false; + private readonly TaskCompletionSource _state = new(); + + public Task Open() + { + _isOpen = true; + + StateHasChanged(); + + return _state.Task; + } + + private void Accepted() + { + _isOpen = false; + + _state.SetResult(null!); + } } \ No newline at end of file diff --git a/src/Inc.TeamAssistant.WebUI/Features/Layouts/AcceptCookieDialogContainer.razor b/src/Inc.TeamAssistant.WebUI/Features/Layouts/AcceptCookieDialogContainer.razor index 7ab4e3f5..183def59 100644 --- a/src/Inc.TeamAssistant.WebUI/Features/Layouts/AcceptCookieDialogContainer.razor +++ b/src/Inc.TeamAssistant.WebUI/Features/Layouts/AcceptCookieDialogContainer.razor @@ -3,12 +3,12 @@ @inject IRenderContext RenderContext @inject IJSRuntime JsRuntime - + @code { private IJSObjectReference? _cookieModule; - - private bool _isShow; + + private AcceptCookieDialog _dialog = null!; private readonly string _rightsCookieName = "rights"; private readonly string _rightsCookieValue = "accept"; private readonly int _rightsCookieLifetime = 365; @@ -20,16 +20,18 @@ _cookieModule = await JsRuntime.InvokeAsync( "import", "./Features/Layouts/AcceptCookieDialogContainer.razor.js"); - var rightsValue = await _cookieModule.InvokeAsync("readCookie", _rightsCookieName); + if (!_rightsCookieValue.Equals(rightsValue, StringComparison.InvariantCultureIgnoreCase)) - _isShow = true; + { + await _dialog.Open(); - StateHasChanged(); + await Accepted(); + } } } - private async Task Accept() + private async Task Accepted() { if (_cookieModule is null) return; @@ -39,8 +41,6 @@ _rightsCookieName, _rightsCookieValue, _rightsCookieLifetime); - - _isShow = false; } public async ValueTask DisposeAsync()