@* ReSharper disable once RedundantUsingDirective *@
@using Iceshrimp.Frontend.Components.Note
@using Iceshrimp.Frontend.Core.Services
@using Iceshrimp.Frontend.Core.Services.NoteStore
@using Iceshrimp.Shared.Schemas.Web
@inject NavigationManager NavigationManager
@inject ApiService Api
@inject RelatedStore Store
@implements IDisposable
@if (_hidden == false)
{
@if (_indented)
{
@if (Note.Descendants?.Count > 0)
{
}
}
@if (Note.Descendants != null)
{
@* We are checking for null 3 lines up. *@
@for (var i = 0; i < Note.Descendants!.Count; i++)
{
var note = Note.Descendants[i];
@if (Note.Descendants?.Count > 1)
{
@if (i == Note.Descendants.Count - 1)
{
}
else
{
}
}
else
{
}
}
}
}
@code {
[Parameter] [EditorRequired] public required NoteResponse Note { get; set; }
[Parameter] [EditorRequired] public required int Depth { get; set; }
[Parameter] [EditorRequired] public required int MaxDepth { get; set; }
private bool _indented = false;
private bool _hidden = false;
protected override void OnInitialized()
{
Store.NoteChanged += OnNoteChanged;
if (Depth > 0 || Note.Descendants?.Count > 0)
{
_indented = true;
}
// If the note is filtered, we don't want to render its tree, and hide this note.
if (Note.Filtered is { Hide: true })
{
Note.Descendants = null;
_hidden = true;
}
}
private void OnNoteChanged(object? _, NoteResponse note)
{
if (note.Id == Note.Id)
{
var __ = Refresh();
}
}
private async Task Refresh()
{
if (Depth < MaxDepth)
{
var res = await Store.GetDescendantsAsync(Note.Id, MaxDepth - Depth, true);
if (res == null) return;
Note.Descendants = res.Select(p => p.Value).ToList();
StateHasChanged();
}
}
public void Dispose()
{
Store.NoteChanged -= OnNoteChanged;
}
}