66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using RpgRoller.Contracts;
|
|
|
|
namespace RpgRoller.Components.Pages.HomeControls;
|
|
|
|
[ExcludeFromCodeCoverage]
|
|
public partial class CampaignLogPanel
|
|
{
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (IsCampaignDataLoading || CampaignLog.Count == 0)
|
|
{
|
|
LastRenderedLogCount = CampaignLog.Count;
|
|
return;
|
|
}
|
|
|
|
if (firstRender || CampaignLog.Count > LastRenderedLogCount)
|
|
{
|
|
try
|
|
{
|
|
await JS.InvokeVoidAsync("rpgRollerApi.scrollElementToBottom", LogPanelRef);
|
|
}
|
|
catch (JSDisconnectedException)
|
|
{
|
|
}
|
|
catch (InvalidOperationException ex) when (ex.Message.Contains("statically rendered", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
}
|
|
}
|
|
|
|
LastRenderedLogCount = CampaignLog.Count;
|
|
}
|
|
|
|
[Inject]
|
|
private IJSRuntime JS { get; set; } = null!;
|
|
|
|
private ElementReference LogPanelRef { get; set; }
|
|
private int LastRenderedLogCount { get; set; }
|
|
|
|
[Parameter]
|
|
public bool IsCampaignDataLoading { get; set; }
|
|
|
|
[Parameter]
|
|
public IReadOnlyList<CampaignLogEntry> CampaignLog { get; set; } = [];
|
|
|
|
[Parameter]
|
|
public Func<CampaignLogEntry, string> RollerLabel { get; set; } = _ => string.Empty;
|
|
|
|
[Parameter]
|
|
public Func<Guid, string> SkillLabel { get; set; } = _ => string.Empty;
|
|
|
|
[Parameter]
|
|
public Func<Guid, string> CharacterLabel { get; set; } = _ => string.Empty;
|
|
|
|
[Parameter]
|
|
public Func<CampaignLogEntry, string> LogEntryCssClass { get; set; } = _ => string.Empty;
|
|
|
|
[Parameter]
|
|
public Func<CampaignLogEntry, string> VisibilityLabel { get; set; } = _ => string.Empty;
|
|
|
|
[Parameter]
|
|
public Func<CampaignLogEntry, string> VisibilityBadgeCssClass { get; set; } = _ => string.Empty;
|
|
}
|