95 lines
No EOL
2.8 KiB
Text
95 lines
No EOL
2.8 KiB
Text
@page "/notes/{NoteId}"
|
|
@using Iceshrimp.Shared.Schemas
|
|
@using Iceshrimp.Frontend.Components
|
|
@using Iceshrimp.Frontend.Core.Services
|
|
@using Iceshrimp.Frontend.Components.Note
|
|
@inject ApiService ApiService
|
|
@inject IJSRuntime Js
|
|
|
|
@if (_init)
|
|
{
|
|
<div class="scroller">
|
|
<div class="wrapper">
|
|
<div class="container">
|
|
@if (Ascendants != null)
|
|
{
|
|
<div class="ascendants">
|
|
@foreach (var note in Ascendants)
|
|
{
|
|
<AscendedNote Note="note"/>
|
|
}
|
|
</div>
|
|
}
|
|
<div @ref="RootNoteRef" class="root-note">
|
|
<Note NoteResponse="RootNote"></Note>
|
|
</div>
|
|
@if (Descendants != null)
|
|
{
|
|
<div class="descendants">
|
|
@foreach (var element in Descendants)
|
|
{
|
|
<RecursiveNote Note="element" Depth="0"/>
|
|
}
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<div>Loading</div>
|
|
}
|
|
@if (_error)
|
|
{
|
|
<div>This note does not exist!</div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public string? NoteId { get; set; }
|
|
public NoteResponse? RootNote { get; set; }
|
|
private IList<NoteResponse>? Descendants { get; set; }
|
|
private IList<NoteResponse>? Ascendants { get; set; }
|
|
private IJSObjectReference? Module { get; set; }
|
|
private ElementReference RootNoteRef { get; set; }
|
|
private bool _init = false;
|
|
private bool _error = false;
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_init = false;
|
|
if (NoteId == null)
|
|
{
|
|
_error = true;
|
|
return;
|
|
}
|
|
|
|
RootNote = await ApiService.Notes.GetNote(NoteId);
|
|
if (RootNote == null)
|
|
{
|
|
_error = true;
|
|
return;
|
|
}
|
|
|
|
Descendants = await ApiService.Notes.GetNoteDescendants(NoteId, default);
|
|
Ascendants = await ApiService.Notes.GetNoteAscendants(NoteId, default);
|
|
_init = true;
|
|
|
|
StateHasChanged();
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
Module = await Js.InvokeAsync<IJSObjectReference>("import", "/Pages/SingleNote.razor.js");
|
|
}
|
|
|
|
if (_init)
|
|
{
|
|
await (Module ?? throw new InvalidOperationException("JS interop not initialized"))
|
|
.InvokeVoidAsync("ScrollIntoView", RootNoteRef);
|
|
}
|
|
}
|
|
|
|
} |