Skip to content

Commit 6818ab7

Browse files
committed
Merge branch 'main' into refactor-otp
2 parents 1e0f6aa + 6ca6d5a commit 6818ab7

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.5.11-beta07</Version>
4+
<Version>9.5.11-beta06</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Timer/Timer.razor.cs

+11-28
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public partial class Timer
4343

4444
private CancellationTokenSource CancelTokenSource { get; set; } = new();
4545

46-
private AutoResetEvent ResetEvent { get; } = new(false);
47-
4846
private bool Vibrate { get; set; }
4947

5048
/// <summary>
@@ -185,29 +183,23 @@ private async Task OnStart(TimeSpan val)
185183
CancelTokenSource = new CancellationTokenSource();
186184
}
187185

188-
while (!CancelTokenSource.IsCancellationRequested && CurrentTimespan > TimeSpan.Zero)
186+
while (CancelTokenSource is { IsCancellationRequested: false } && CurrentTimespan > TimeSpan.Zero)
189187
{
190188
try
191189
{
192190
await Task.Delay(1000, CancelTokenSource.Token);
193-
}
194-
catch (TaskCanceledException) { }
195-
196-
if (!CancelTokenSource.IsCancellationRequested)
197-
{
198-
CurrentTimespan = CurrentTimespan.Subtract(TimeSpan.FromSeconds(1));
199-
StateHasChanged();
200-
}
201-
202-
if (IsPause)
203-
{
204-
ResetEvent.WaitOne();
205-
AlertTime = DateTime.Now.Add(CurrentTimespan).ToString("HH:mm:ss");
206191

207-
// 重建 CancelToken
208-
CancelTokenSource.Dispose();
209-
CancelTokenSource = new CancellationTokenSource();
192+
if (IsPause)
193+
{
194+
AlertTime = DateTime.Now.Add(CurrentTimespan).ToString("HH:mm:ss");
195+
}
196+
else
197+
{
198+
CurrentTimespan = CurrentTimespan.Subtract(TimeSpan.FromSeconds(1));
199+
StateHasChanged();
200+
}
210201
}
202+
catch (TaskCanceledException) { }
211203
}
212204

213205
if (CurrentTimespan == TimeSpan.Zero)
@@ -229,14 +221,6 @@ private async Task OnStart(TimeSpan val)
229221
private void OnClickPause()
230222
{
231223
IsPause = !IsPause;
232-
if (!IsPause)
233-
{
234-
ResetEvent.Set();
235-
}
236-
else
237-
{
238-
CancelTokenSource.Cancel();
239-
}
240224
}
241225

242226
private string GetPauseText() => IsPause ? ResumeText : PauseText;
@@ -262,7 +246,6 @@ protected override async ValueTask DisposeAsync(bool disposing)
262246
CancelTokenSource.Cancel();
263247
CancelTokenSource.Dispose();
264248

265-
ResetEvent.Dispose();
266249
if (Module != null)
267250
{
268251
await Module.DisposeAsync();

test/UnitTest/Components/InputTest.cs

+16
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,22 @@ public void InputGroup_Width()
324324
cut.MarkupMatches("<div class=\"input-group\"><div class=\"input-group-text\" required=\"true\" style=\"--bb-input-group-label-width: 120px;\"><span>BootstrapInputGroup</span></div></div>");
325325
}
326326

327+
[Fact]
328+
public void InputGroup_ChildContent()
329+
{
330+
var cut = Context.RenderComponent<BootstrapInputGroup>(builder =>
331+
{
332+
builder.Add(s => s.ChildContent, new RenderFragment(builder =>
333+
{
334+
builder.OpenComponent<BootstrapInputGroupLabel>(0);
335+
builder.AddAttribute(1, nameof(BootstrapInputGroupLabel.ChildContent), new RenderFragment(builder => builder.AddContent(0, "child-content")));
336+
builder.CloseComponent();
337+
}));
338+
});
339+
340+
cut.Contains("child-content");
341+
}
342+
327343
[Theory]
328344
[InlineData(Alignment.Center, "center")]
329345
[InlineData(Alignment.Right, "end")]

test/UnitTest/Components/TimerTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public async Task OnCancel_Ok()
138138
Assert.True(buttons[1].ClassList.Contains("btn-warning"));
139139
Assert.Equal("暂停", buttons[1].GetInnerText());
140140
await cut.InvokeAsync(() => buttons[1].Click());
141+
await Task.Delay(1000);
141142

142143
// resume
143144
buttons = cut.FindAll(".timer-buttons button");

0 commit comments

Comments
 (0)