1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-10-30 05:42:47 +01:00
Minecraft-Phantom-Panel/Server/Phantom.Server.Web/Shared/InstanceLog.razor
2022-10-07 17:21:39 +02:00

54 lines
1.3 KiB
Plaintext

@using Phantom.Server.Services.Instances
@using Phantom.Utils.Collections
@using Phantom.Utils.Events
@implements IDisposable
@inject IJSRuntime Js;
@inject InstanceLogManager InstanceLogManager
<div id="log" class="font-monospace mb-3">
@foreach (var line in instanceLogs.EnumerateLast(uint.MaxValue)) {
<p>@line</p>
}
</div>
@code {
[Parameter, EditorRequired]
public Guid InstanceGuid { get; set; }
private IJSObjectReference? PageJs { get; set; }
private EventSubscribers<RingBuffer<string>> instanceLogsSubs = null!;
private RingBuffer<string> instanceLogs = null!;
protected override void OnInitialized() {
instanceLogsSubs = InstanceLogManager.GetSubs(InstanceGuid);
instanceLogsSubs.Subscribe(this, buffer => {
instanceLogs = buffer;
InvokeAsync(RefreshLog);
});
}
protected override async Task OnAfterRenderAsync(bool firstRender) {
if (firstRender) {
PageJs = await Js.InvokeAsync<IJSObjectReference>("import", "./Shared/InstanceLog.razor.js");
StateHasChanged();
await PageJs.InvokeVoidAsync("initLog");
}
}
private async Task RefreshLog() {
StateHasChanged();
if (PageJs != null) {
await PageJs.InvokeVoidAsync("scrollLog");
}
}
public void Dispose() {
instanceLogsSubs.Unsubscribe(this);
}
}