@* ReSharper disable once RedundantUsingDirective *@
@using Iceshrimp.Frontend.Components.Note
@using Iceshrimp.Frontend.Core.Services
@using Iceshrimp.Shared.Schemas.Web
@inject NavigationManager NavigationManager
@inject MessageService MessageService
@inject ApiService Api
@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 IDisposable _noteChangedHandler = null!;
private bool _hidden = false;
protected override void OnInitialized()
{
_noteChangedHandler = MessageService.Register(Note.Id, OnNoteChanged, MessageService.Type.Updated);
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)
{
var __ = Refresh();
}
private async Task Refresh()
{
if (Depth < MaxDepth)
{
var res = await Api.Notes.GetNoteDescendantsAsync(Note.Id, MaxDepth - Depth);
Note.Descendants = res;
StateHasChanged();
}
}
private void OpenNote()
{
NavigationManager.NavigateTo($"/notes/{Note.Id}");
}
public void Dispose()
{
_noteChangedHandler.Dispose();
}
}