Skip to content

Commit

Permalink
Add progress spinner to indicate that archivist is working
Browse files Browse the repository at this point in the history
  • Loading branch information
KarmaKamikaze committed Nov 12, 2024
1 parent 169e489 commit 62202d0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
25 changes: 17 additions & 8 deletions ChatRPG/Pages/CampaignPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,10 @@
</button>
</div>
</div>

@if (_hasScrollBar)
{
<button class="btn-scroll-to-top text-xl-center rounded" @onclick='() => ScrollToElement("campaign-title")'>
<i class="bi bi-arrow-bar-up fs-3"></i>
</button>
}
</div>
</div>

<div class="col player-info floating-stats rounded text-white">
<div class="col player-info floating-stats rounded text-white" style="position: relative;">
<div class="sticky">
<div class="mx-4 mt-3">
<h3 class="text-center mb-4">@_mainCharacter?.Name</h3>
Expand All @@ -121,6 +114,22 @@
<HealthBar MaxHealth="_mainCharacter?.MaxHealth" CurrentHealth="_mainCharacter?.CurrentHealth"></HealthBar>
</div>
</div>
<!-- RadzenStack fixed to the bottom of the outer div -->
<div style="position: absolute; bottom: 1rem; left: 0; right: 0; text-align: center;">
@if (_isArchiving)
{
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.Center" Wrap="FlexWrap.Wrap" Class="rz-m-12" Gap="0.5rem">
<span style="font-size: 1.25rem;">Archiving campaign...</span>
<RadzenProgressBarCircular ProgressBarStyle="ProgressBarStyle.Light" Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate" Style="max-height: 28px; max-width: 28px;"/>
</RadzenStack>
}
</div>
@if (_hasScrollBar)
{
<button class="btn-scroll-to-top text-xl-center rounded" @onclick='() => ScrollToElement("campaign-title")'>
<i class="bi bi-arrow-bar-up fs-3"></i>
</button>
}
</div>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion ChatRPG/Pages/CampaignPage.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class CampaignPage
private List<OpenAiGptMessage> _conversation = new();
private string _userInput = "";
private bool _isWaitingForResponse;
private bool _isArchiving;
private const string BottomId = "bottom-id";
private Campaign? _campaign;
private List<Character> _npcList = new();
Expand Down Expand Up @@ -192,6 +193,7 @@ private void OnChatCompletionReceived(object? sender, ChatCompletionReceivedEven
if (eventArgs.Message.Content != string.Empty)
{
_isWaitingForResponse = false;
_isArchiving = true;
StateHasChanged();
}
}
Expand All @@ -207,6 +209,7 @@ private void OnChatCompletionChunkReceived(object? sender, ChatCompletionChunkRe
if (eventArgs.IsStreamingDone)
{
_isWaitingForResponse = false;
_isArchiving = true;
StateHasChanged();
}
else if (eventArgs.Chunk is not null)
Expand All @@ -220,6 +223,7 @@ private void OnChatCompletionChunkReceived(object? sender, ChatCompletionChunkRe

private async void OnCampaignUpdated()
{
_isArchiving = false;
await InvokeAsync(UpdateStatsUi);
}

Expand Down Expand Up @@ -254,4 +258,4 @@ private void UpdateStatsUi()
_mainCharacter = _campaign!.Player;
StateHasChanged();
}
}
}
4 changes: 1 addition & 3 deletions ChatRPG/Services/GameInputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using ChatRPG.Data.Models;
using ChatRPG.Pages;
using ChatRPG.Services.Events;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;

namespace ChatRPG.Services;

Expand Down Expand Up @@ -129,4 +127,4 @@ private async Task SaveInteraction(Campaign campaign, string input, string respo
await _gameStateManager.StoreMessagesInCampaign(campaign, input, response);
await _gameStateManager.SaveCurrentState(campaign);
}
}
}

0 comments on commit 62202d0

Please sign in to comment.