Skip to content

Commit

Permalink
refactor: BarConnectionStatus.razor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyakunin committed Aug 19, 2023
1 parent d71cd03 commit cd32696
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
@using Stl
@using Stl.DependencyInjection
@using Stl.Fusion.Internal
@using Stl.Rpc
@inherits ComputedStateComponent<RpcPeerState?>
@inject Session Session
@inject RpcClientPeerReconnectDelayer RpcClientPeerReconnectDelayer

@{
var state = State.ValueOrDefault;
var isDisconnected = !(state?.IsConnected ?? true);
var message = state == null
? "Connecting..."
: isDisconnected
? state.Error?.Message ?? "Unknown error."
: "Connected.";
var iconName = isDisconnected
var m = State.ValueOrDefault ?? new RpcPeerState(true);
var isReconnecting = !m.IsConnected
&& m.ReconnectsAt <= RpcClientPeerReconnectDelayer.Clock.Now;
var message = m.IsConnected
? "Connected."
: m.Error?.Message.Trim() ?? "Unknown error.";
if (!message.EndsWith(".") && !message.EndsWith("!") && !message.EndsWith("?"))
message += ".";
var iconName = m.IsConnected == false
? FontAwesomeIcons.ExclamationTriangle
: FontAwesomeIcons.Cloud;
var textColor = isDisconnected
var textColor = m.IsConnected == false
? TextColor.Warning
: TextColor.Default;
}
Expand All @@ -29,9 +27,14 @@
<BarDropdownMenu>
<BarDropdownItem TextColor="@textColor">
<span>@message</span>
@if (state?.ReconnectsAt is { } reconnectsAt) {
<span> Will reconnect <TimerBadge ExpiresAt="reconnectsAt"/>. </span>
<Button Color="Color.Success" Clicked="@TryReconnect">Reconnect</Button>
@if (!m.IsConnected) {
if (isReconnecting) {
<span> Reconnecting... </span>
}
else {
<span> Will reconnect <TimerBadge ExpiresAt="m.ReconnectsAt"/>. </span>
<Button Color="Color.Success" Clicked="@TryReconnect">Reconnect</Button>
}
}
</BarDropdownItem>
</BarDropdownMenu>
Expand Down
2 changes: 1 addition & 1 deletion samples/TodoApp/UI/Shared/TopBar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</BarBrand>
<BarMenu>
<BarEnd>
<BarBackendStatus/>
<BarConnectionStatus/>
<BarItem>
<BarAccount/>
</BarItem>
Expand Down

0 comments on commit cd32696

Please sign in to comment.