173 lines
5.2 KiB
Text
173 lines
5.2 KiB
Text
@using Iceshrimp.Shared.Schemas.Web
|
|
@using Iceshrimp.Assets.PhosphorIcons
|
|
@using Iceshrimp.Frontend.Core.Miscellaneous
|
|
@using Iceshrimp.Frontend.Localization
|
|
@using Microsoft.Extensions.Localization
|
|
@implements IDisposable
|
|
@inject IStringLocalizer<Localization> Loc;
|
|
@inject IJSRuntime Js;
|
|
@inject NavigationManager Nav;
|
|
|
|
<div class="note-content @(!_showFull ? "collapsed" : "") @(Indented ? "indent" : "")">
|
|
@if (NoteBase.Cw != null)
|
|
{
|
|
<div class="cw">
|
|
<span @onclick="OpenNote" class="cw-field @(ClickOpenNote ? "clickable" : "")"><MfmText Text="@NoteBase.Cw" Emoji="@NoteBase.Emoji" Simple="@true"/></span>
|
|
<button class="cw-button" @onclick="ToggleCw" @onclick:stopPropagation="true">
|
|
@if (_cwToggle)
|
|
{
|
|
@if (NoteBase.Text != null)
|
|
{
|
|
@Loc["Show Content ({0} Characters)", NoteBase.Text.Length]
|
|
}
|
|
else
|
|
{
|
|
@Loc["Show Content"]
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
@Loc["Hide Content"]
|
|
}
|
|
</button>
|
|
</div>
|
|
}
|
|
@if (_overHeight & !_showFull)
|
|
{
|
|
<button class="truncate-btn" @onclick="ToggleTruncate" @onclick:stopPropagation="true">
|
|
<span>@Loc["Show more"]</span>
|
|
</button>
|
|
}
|
|
<div
|
|
class="note-body @(_overHeight ? "too-long" : "") @(_showFull ? "show-full" : "") @(_cwToggle ? "hidden" : "")"
|
|
@ref="Body">
|
|
@if (ReplyInaccessible || !string.IsNullOrWhiteSpace(NoteBase.Text))
|
|
{
|
|
<span @onclick="OpenNote" class="@(ClickOpenNote ? "clickable" : "")">
|
|
@if (ReplyInaccessible)
|
|
{
|
|
<span class="reply-inaccessible">
|
|
<Icon Name="Icons.ArrowBendLeftUp"/><Icon Name="Icons.Lock"/>
|
|
</span>
|
|
}
|
|
<MfmText Text="@NoteBase.Text" Emoji="@NoteBase.Emoji"/>
|
|
</span>
|
|
}
|
|
@if (NoteBase.Poll != null)
|
|
{
|
|
<NotePoll Poll="@NoteBase.Poll" Emoji="@NoteBase.Emoji"/>
|
|
}
|
|
@if (NoteBase.Attachments.Count > 0)
|
|
{
|
|
<NoteAttachments Attachments="NoteBase.Attachments"/>
|
|
}
|
|
@if (Quote != null)
|
|
{
|
|
<div @onclick="OpenQuote" @onclick:stopPropagation="true" class="quote">
|
|
<NoteComponent Note="Quote" AsQuote="true" OpenNote="false"></NoteComponent>
|
|
</div>
|
|
}
|
|
</div>
|
|
@if (_overHeight & _showFull)
|
|
{
|
|
<button class="truncate-btn show-less" @onclick="ToggleTruncate" @onclick:stopPropagation="true">
|
|
<span>@Loc["Show less"]</span>
|
|
</button>
|
|
}
|
|
</div>
|
|
|
|
|
|
|
|
@code {
|
|
[CascadingParameter(Name = "Controller")]
|
|
ChildNoteController? Controller { get; set; }
|
|
|
|
[Parameter] public required NoteBase NoteBase { get; set; }
|
|
[Parameter] public bool Indented { get; set; }
|
|
[Parameter] public bool ReplyInaccessible { get; set; }
|
|
[Parameter] public NoteBase? Quote { get; set; }
|
|
[Parameter] public bool ClickOpenNote { get; set; }
|
|
|
|
private IJSObjectReference? Module { get; set; }
|
|
private ElementReference Body { get; set; }
|
|
private bool _showFull = false;
|
|
private bool _cwToggle = true;
|
|
private bool _overHeight = false;
|
|
private bool _flag = false;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Controller?.Register(this);
|
|
Module = await Js.InvokeAsync<IJSObjectReference>("import", "./Components/Note/NoteBody.razor.js");
|
|
if (NoteBase.Cw == null)
|
|
{
|
|
_cwToggle = false;
|
|
}
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (!firstRender)
|
|
{
|
|
if (Module != null && _flag == false)
|
|
{
|
|
var computedHeight = await Module.InvokeAsync<float>("getComputedHeight", Body);
|
|
if (computedHeight > 40)
|
|
{
|
|
_overHeight = true;
|
|
StateHasChanged();
|
|
}
|
|
else
|
|
{
|
|
_overHeight = false;
|
|
StateHasChanged();
|
|
}
|
|
|
|
_flag = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ToggleCw()
|
|
{
|
|
_cwToggle = !_cwToggle;
|
|
StateHasChanged();
|
|
_flag = false;
|
|
}
|
|
|
|
public void OpenCw()
|
|
{
|
|
_cwToggle = false;
|
|
_flag = false;
|
|
}
|
|
|
|
public void CloseCw()
|
|
{
|
|
if (NoteBase.Cw != null)
|
|
{
|
|
_cwToggle = true;
|
|
_flag = false;
|
|
}
|
|
}
|
|
|
|
private void ToggleTruncate()
|
|
{
|
|
_showFull = !_showFull;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Controller?.Unregister(this);
|
|
}
|
|
|
|
private void OpenNote()
|
|
{
|
|
if (ClickOpenNote) Nav.NavigateTo($"/notes/{NoteBase.Id}");
|
|
}
|
|
|
|
private void OpenQuote()
|
|
{
|
|
Nav.NavigateTo($"/notes/{Quote!.Id}");
|
|
}
|
|
}
|