Skip to content

Commit 3ef4f67

Browse files
committed
updates
1 parent f59ebd4 commit 3ef4f67

File tree

8 files changed

+105
-18
lines changed

8 files changed

+105
-18
lines changed

Directory.Packages.props

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
<PackageVersion Include="Bogus" Version="35.6.4" />
99
<PackageVersion Include="bunit" Version="1.40.0" />
1010
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
11-
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="9.0.9" />
12-
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.9" />
13-
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.9" />
14-
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.9" />
15-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
11+
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="9.0.10" />
12+
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.10" />
13+
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.10" />
14+
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.10" />
15+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
1616
<PackageVersion Include="MinVer" Version="6.0.0" />
17-
<PackageVersion Include="PublicApiGenerator" Version="11.4.6" />
18-
<PackageVersion Include="System.Linq.Dynamic.Core" Version="1.6.8" />
19-
<PackageVersion Include="System.Net.Http.Json" Version="9.0.9" />
20-
<PackageVersion Include="Verify.Xunit" Version="30.19.1" />
17+
<PackageVersion Include="PublicApiGenerator" Version="11.5.0" />
18+
<PackageVersion Include="System.Linq.Dynamic.Core" Version="1.6.9" />
19+
<PackageVersion Include="System.Net.Http.Json" Version="9.0.10" />
20+
<PackageVersion Include="Verify.Xunit" Version="31.0.2" />
2121
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
2222
<PackageVersion Include="xunit" Version="2.9.3" />
2323
</ItemGroup>
24-
</Project>
24+
</Project>

src/LoreSoft.Blazor.Controls/LoreSoft.Blazor.Controls.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</ItemGroup>
1919

2020
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
21-
<PackageReference Include="Microsoft.AspNetCore.Components.Web" VersionOverride="8.0.20" />
21+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" VersionOverride="8.0.21" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

src/LoreSoft.Blazor.Controls/Modals/ModalComponentBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public abstract class ModalComponentBase : ComponentBase
3636
public string Message { get; set; } = "";
3737

3838
/// <summary>
39-
/// Gets or sets the text for the primary action button.
39+
/// Gets or sets the text for the primary action button. The primary action typically represents a confirmation or acceptance action.
4040
/// </summary>
4141
/// <value>The primary action button text. Defaults to "OK".</value>
4242
[Parameter]
4343
public string PrimaryAction { get; set; } = "OK";
4444

4545
/// <summary>
46-
/// Gets or sets the text for the secondary action button.
46+
/// Gets or sets the text for the secondary action button. The secondary action is typically used for canceling or dismissing the modal.
4747
/// </summary>
4848
/// <value>The secondary action button text. Defaults to "Cancel".</value>
4949
[Parameter]

src/LoreSoft.Blazor.Controls/Modals/ModalDialog.razor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ namespace LoreSoft.Blazor.Controls;
1414
/// </remarks>
1515
public partial class ModalDialog : ComponentBase, IAsyncDisposable
1616
{
17+
// Special return value indicating the dialog was closed programmatically, used to prevent duplicate close notifications.
18+
private const string ProgrammaticCloseValue = "--closed--";
19+
1720
private readonly Messenger _messenger;
1821

1922
private IJSObjectReference? _module;
@@ -80,7 +83,7 @@ public async Task OnDialogClosed(string? returnValue)
8083
return;
8184

8285
// If the dialog was closed programmatically, do not send another close message
83-
if (returnValue == "--closed--")
86+
if (returnValue == ProgrammaticCloseValue)
8487
return;
8588

8689
await Modal.CloseAsync(ModalResult.Cancel());
@@ -145,7 +148,7 @@ private async Task HandleModalClose(ModalClose close)
145148
return;
146149

147150
// close with special value to indicate programmatic close
148-
await _dialog.InvokeVoidAsync("close", "--closed--");
151+
await _dialog.InvokeVoidAsync("close", ProgrammaticCloseValue);
149152
}
150153

151154
/// <summary>

src/LoreSoft.Blazor.Controls/Modals/ModalParameters.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public ModalParameters Variant(ModalVariant variant)
143143
}
144144

145145
/// <summary>
146-
/// Sets the text for the primary action button.
146+
/// Sets the text for the primary action button. The primary action is typically used for confirming or proceeding with an action.
147147
/// </summary>
148148
/// <param name="primaryAction">The text to display on the primary action button.</param>
149149
/// <returns>The current <see cref="ModalParameters"/> instance for method chaining.</returns>
@@ -161,7 +161,7 @@ public ModalParameters PrimaryAction(string primaryAction)
161161
}
162162

163163
/// <summary>
164-
/// Sets the text for the secondary action button.
164+
/// Sets the text for the secondary action button. The secondary action is typically used for canceling or dismissing the modal.
165165
/// </summary>
166166
/// <param name="secondaryAction">The text to display on the secondary action button.</param>
167167
/// <returns>The current <see cref="ModalParameters"/> instance for method chaining.</returns>

src/LoreSoft.Blazor.Controls/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static IServiceCollection AddBlazorControls(this IServiceCollection servi
1818
{
1919
services.TryAddSingleton<Messenger>();
2020
services.TryAddScoped<DownloadService>();
21+
services.TryAddScoped<StorageService>();
2122
services.TryAddScoped<BrowserCultureProvider>();
2223

2324
services.AddProgressBar();
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System.Text.Json;
2+
3+
using Microsoft.Extensions.Logging;
4+
using Microsoft.Extensions.Options;
5+
using Microsoft.JSInterop;
6+
7+
namespace LoreSoft.Blazor.Controls;
8+
9+
public class StorageService
10+
{
11+
public const string LocalStorage = "localStorage";
12+
public const string SessionStorage = "sessionStorage";
13+
14+
private readonly IJSRuntime _javaScript;
15+
private readonly JsonSerializerOptions _options;
16+
private readonly ILogger<StorageService> _logger;
17+
18+
public StorageService(
19+
IJSRuntime javaScript,
20+
IOptions<JsonSerializerOptions> options,
21+
ILogger<StorageService> logger)
22+
{
23+
_javaScript = javaScript;
24+
_options = options.Value;
25+
_logger = logger;
26+
}
27+
28+
29+
public async ValueTask<T?> GetItemAsync<T>(string key, StoreType storeType = StoreType.Session)
30+
{
31+
ArgumentException.ThrowIfNullOrEmpty(key);
32+
33+
var module = storeType == StoreType.Local ? LocalStorage : SessionStorage;
34+
var method = $"{module}.getItem";
35+
36+
var json = await _javaScript.InvokeAsync<string?>(method, key);
37+
if (string.IsNullOrWhiteSpace(json))
38+
return default;
39+
40+
_logger.LogInformation("Retrieved {StoreType} storage item {Key} with value {Value}", storeType, key, json);
41+
42+
return JsonSerializer.Deserialize<T>(json, _options);
43+
}
44+
45+
public async ValueTask SetItemAsync<T>(string key, T value, StoreType storeType = StoreType.Session)
46+
{
47+
ArgumentException.ThrowIfNullOrEmpty(key);
48+
49+
var module = storeType == StoreType.Local ? LocalStorage : SessionStorage;
50+
var method = $"{module}.setItem";
51+
52+
var json = value is null ? string.Empty : JsonSerializer.Serialize(value, _options);
53+
54+
_logger.LogInformation("Setting {StoreType} storage item {Key} to {Value}", storeType, key, json);
55+
56+
await _javaScript.InvokeVoidAsync(method, key, json);
57+
}
58+
59+
public async ValueTask RemoveItemAsync(string key, StoreType storeType = StoreType.Session)
60+
{
61+
ArgumentException.ThrowIfNullOrEmpty(key);
62+
63+
var module = storeType == StoreType.Local ? LocalStorage : SessionStorage;
64+
var method = $"{module}.removeItem";
65+
66+
await _javaScript.InvokeVoidAsync(method, key);
67+
}
68+
69+
public async ValueTask ClearAsync(StoreType storeType = StoreType.Session)
70+
{
71+
var module = storeType == StoreType.Local ? LocalStorage : SessionStorage;
72+
var method = $"{module}.clear";
73+
74+
await _javaScript.InvokeVoidAsync(method);
75+
}
76+
}
77+
78+
public enum StoreType
79+
{
80+
Local,
81+
Session
82+
}
83+

test/LoreSoft.Blazor.Controls.Tests/Utilities/MessengerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public async Task Subscribe_ReturnedDisposable_UnsubscribesHandler()
179179
}
180180

181181
[Fact]
182-
public async Task Subscribe_DisposeTwice_DoesNotThrow()
182+
public void Subscribe_DisposeTwice_DoesNotThrow()
183183
{
184184
// Arrange
185185
var messenger = new Messenger();

0 commit comments

Comments
 (0)