Iceshrimp.NET/Iceshrimp.Frontend/Components/Note/NoteBody.razor
2024-07-04 18:02:00 +02:00

68 lines
No EOL
2 KiB
Text

@using Iceshrimp.Shared.Schemas.Web
@if (NoteBase.Cw != null)
{
<div class="cw">
<span class="cw-field">@NoteBase.Cw</span><button class="cw-button" @onclick="ToggleCw" @onclick:stopPropagation="true">Toggle CW</button>
</div>
<div hidden="@CwToggle" class="note-body @(CwToggle ? "hidden" : "") @(Indented ? "indent" : "")">
<MfmText Text="@NoteBase.Text" Emoji="@NoteBase.Emoji"/>
@if (NoteBase.Attachments.Count > 0)
{
<NoteAttachments Attachments="NoteBase.Attachments"/>
}
</div>
}
@if (NoteBase.Cw == null && OverLength)
{
<div
class="note-body @(Truncate ? "truncated" : "") @(Indented ? "indent" : "")"
style="max-height: @(Truncate ? MaxHeight + "px" : "initial")">
<MfmText Text="@NoteBase.Text" Emoji="@NoteBase.Emoji"/>
@if (NoteBase.Attachments.Count > 0)
{
<NoteAttachments Attachments="NoteBase.Attachments"/>
}
</div>
<button class="truncate-btn" @onclick="ToggleTruncate" @onclick:stopPropagation="true">
@if (Truncate)
{
<span>Show more</span>
}
@if (!Truncate)
{
<span>Show less</span>
}
</button>
}
@if (NoteBase.Cw == null && OverLength == false)
{
<div class="note-body @(Indented ? "indent" : "")">
<MfmText Text="@NoteBase.Text" Emoji="@NoteBase.Emoji"/>
@if (NoteBase.Attachments.Count > 0)
{
<NoteAttachments Attachments="NoteBase.Attachments"/>
}
</div>
}
@code {
[Parameter] public required NoteBase NoteBase { get; set; }
[Parameter] public required bool OverLength { get; set; }
[Parameter] public bool Indented { get; set; } = false;
private static int MaxHeight => 500;
private bool Truncate { get; set; } = true;
private bool CwToggle { get; set; } = true;
private void ToggleCw()
{
CwToggle = !CwToggle;
StateHasChanged();
}
private void ToggleTruncate()
{
Truncate = !Truncate;
}
}