Skip to content

Commit

Permalink
fix(UI): prevent toggling forward toggle when an error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Arvidsson committed Sep 1, 2021
1 parent 0384575 commit 2a50c14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/Client/Pages/PortForward.razor
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ else
<MatTextField TValue="int?" @bind-Value="@portForward.Model.LocalPort" />
</td>
<td>
<MatSlideToggle TValue="bool" Value="@portForward.Model.Forwarding" ValueChanged="@(enable => ChangePortForwardAsync(portForward, enable))" />
@{
// This forward ref makes no sense, but for some reason
// it prevents toggling when rendering an error
}
<ForwardRefContext TRef="MatSlideToggle<bool>">
<MatSlideToggle TValue="bool" Value="@portForward.Model.Forwarding" ValueChanged="@(enable => ChangePortForwardAsync(portForward, enable))" />
</ForwardRefContext>
</td>
</tr>
renderPod = false;
Expand Down Expand Up @@ -123,7 +129,7 @@ else
{
using (await _gate.WaitAsync(CancellationToken))
{
if (Error.HasError())
if (Error.HasError)
{
return;
}
Expand Down Expand Up @@ -186,15 +192,14 @@ else
PortForwardService portForward,
bool forward)
{
// The bounded value have to be set or the toggle component will potentially be
// rendered toggled without being toggled which causes untoggling not to work
portForward.Model.Forwarding = forward;
try
{
if (forward)
await portForward.ForwardAsync();
else
await portForward.StopAsync();

portForward.Model.Forwarding = forward;
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Shared/Contexts.razor
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ else
{
using (await _gate.WaitAsync(CancellationToken))
{
if (Error.HasError())
if (Error.HasError)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Shared/Error.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

private string? _error;

public bool HasError() => _error != null;
public bool HasError => _error != null;

public Task ProcessErrorAsync(Exception ex)
{
Expand Down

0 comments on commit 2a50c14

Please sign in to comment.