[frontend] Refactor Note rendering code, add quotes
This commit is contained in:
parent
d1de8057e9
commit
f5e9c036fd
22 changed files with 51 additions and 54 deletions
9
Iceshrimp.Frontend/Components/Note/Note.razor
Normal file
9
Iceshrimp.Frontend/Components/Note/Note.razor
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
@using Iceshrimp.Shared.Schemas
|
||||||
|
|
||||||
|
<NoteComponent Note="NoteResponse" Quote="NoteResponse.Quote" Indented="Indented"></NoteComponent>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter][EditorRequired] public required NoteResponse NoteResponse { get; set; }
|
||||||
|
[Parameter] public bool Indented { get; set; }
|
||||||
|
|
||||||
|
}
|
0
Iceshrimp.Frontend/Components/Note/Note.razor.css
Normal file
0
Iceshrimp.Frontend/Components/Note/Note.razor.css
Normal file
|
@ -37,9 +37,9 @@
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter] public required NoteBase NoteBase { get; set; }
|
[Parameter] public required Shared.Schemas.NoteBase NoteBase { get; set; }
|
||||||
[Parameter] public required bool OverLength { get; set; }
|
[Parameter] public required bool OverLength { get; set; }
|
||||||
[Parameter] public bool Indented { get; set; } = false;
|
[Parameter] public bool Indented { get; set; } = false;
|
||||||
|
|
||||||
private static int MaxHeight => 500;
|
private static int MaxHeight => 500;
|
||||||
private bool Truncate { get; set; } = true;
|
private bool Truncate { get; set; } = true;
|
|
@ -1,6 +1,7 @@
|
||||||
@using Iceshrimp.Frontend.Core.Services
|
@using Iceshrimp.Frontend.Core.Services
|
||||||
@using Iceshrimp.Shared.Schemas
|
@using Iceshrimp.Shared.Schemas
|
||||||
@inject ApiService ApiService;
|
@inject ApiService ApiService;
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
<CascadingValue Value="this">
|
<CascadingValue Value="this">
|
||||||
<div class="note-header">
|
<div class="note-header">
|
||||||
<NoteUserInfo
|
<NoteUserInfo
|
||||||
|
@ -15,16 +16,32 @@
|
||||||
CreatedAt="DateTime.Parse(Note.CreatedAt)"></NoteMetadata>
|
CreatedAt="DateTime.Parse(Note.CreatedAt)"></NoteMetadata>
|
||||||
</div>
|
</div>
|
||||||
<NoteBody NoteBase="Note" OverLength="@CheckLen()" Indented="Indented"/>
|
<NoteBody NoteBase="Note" OverLength="@CheckLen()" Indented="Indented"/>
|
||||||
<NoteFooter Reactions="Note.Reactions" Likes="Note.Likes" IsLiked="Note.Liked"/>
|
@if (Quote != null)
|
||||||
|
{
|
||||||
|
<div @onclick="OpenQuote" @onclick:stopPropagation="true" class="quote">
|
||||||
|
<NoteComponent Note="Quote" AsQuote="true"></NoteComponent>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if (!AsQuote)
|
||||||
|
{
|
||||||
|
<NoteFooter Reactions="Note.Reactions" Likes="Note.Likes" IsLiked="Note.Liked"/>
|
||||||
|
}
|
||||||
</CascadingValue>
|
</CascadingValue>
|
||||||
@code {
|
@code {
|
||||||
[Parameter][EditorRequired] public required NoteResponse Note { get; set; }
|
[Parameter][EditorRequired] public required NoteBase Note { get; set; }
|
||||||
[Parameter] public bool Indented { get; set; }
|
[Parameter] public bool Indented { get; set; }
|
||||||
|
[Parameter] public NoteBase? Quote { get; set; }
|
||||||
|
[Parameter] public bool AsQuote { get; set; }
|
||||||
private bool CheckLen()
|
private bool CheckLen()
|
||||||
{
|
{
|
||||||
return Note.Text?.Length > 500;
|
return Note.Text?.Length > 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OpenQuote()
|
||||||
|
{
|
||||||
|
NavigationManager.NavigateTo($"/notes/{Quote!.Id}");
|
||||||
|
}
|
||||||
|
|
||||||
public void React(string name, bool target)
|
public void React(string name, bool target)
|
||||||
{
|
{
|
||||||
var index = Note.Reactions.FindIndex(x => x.Name == name);
|
var index = Note.Reactions.FindIndex(x => x.Name == name);
|
|
@ -13,3 +13,12 @@
|
||||||
width: 3em;
|
width: 3em;
|
||||||
height: 3em;
|
height: 3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.quote {
|
||||||
|
border-style: solid;
|
||||||
|
border-color: var(--highlight-color);
|
||||||
|
border-width: 0.2rem;
|
||||||
|
border-radius: 1.25rem;
|
||||||
|
padding: 1rem;
|
||||||
|
margin: 0.5rem;
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: end;
|
align-items: end;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
|
white-space: nowrap;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
.info {
|
.info {
|
||||||
display: block;
|
display: block;
|
|
@ -1,4 +1,5 @@
|
||||||
@using Iceshrimp.Shared.Schemas
|
@using Iceshrimp.Shared.Schemas
|
||||||
|
@using Iceshrimp.Frontend.Components.Note
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
<div class="@(Depth > 0 ? "descendant" : "root-note")">
|
<div class="@(Depth > 0 ? "descendant" : "root-note")">
|
||||||
|
@ -14,7 +15,7 @@
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
<div class="note" @onclick="OpenNote">
|
<div class="note" @onclick="OpenNote">
|
||||||
<NoteComponent Indented="_indented" Note="Note"/>
|
<Note Indented="_indented" NoteResponse="Note"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@if (Note.Descendants != null)
|
@if (Note.Descendants != null)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
@using Iceshrimp.Shared.Schemas
|
@using Iceshrimp.Shared.Schemas
|
||||||
|
@using Iceshrimp.Frontend.Components.Note
|
||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
<div class="note-container" @onclick="OpenNote" id="@Note.Id">
|
<div class="note-container" @onclick="OpenNote" id="@Note.Id">
|
||||||
<NoteComponent Note="Note"></NoteComponent>
|
<Note NoteResponse="Note"></Note>
|
||||||
</div>
|
</div>
|
||||||
@code {
|
@code {
|
||||||
[Parameter][EditorRequired] public required NoteResponse Note { get; set; }
|
[Parameter][EditorRequired] public required NoteResponse Note { get; set; }
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
min-width: 20rem;
|
min-width: 20rem;
|
||||||
background-color: var(--foreground-color);
|
background-color: var(--foreground-color);
|
||||||
padding: 1.5rem 1.5rem 1rem; /* top, left-right, bottom*/
|
padding: 1.5rem 1.5rem 1rem; /* top, left-right, bottom*/
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
padding: 1.5rem 1rem 1rem;
|
||||||
|
}
|
||||||
border-radius: 0.75rem;
|
border-radius: 0.75rem;
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
margin-right: 0.5rem;
|
margin-right: 0.5rem;
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
@page "/Note/{id}"
|
|
||||||
@using Iceshrimp.Frontend.Core.Miscellaneous
|
|
||||||
@using Iceshrimp.Frontend.Core.Services
|
|
||||||
@using Iceshrimp.Shared.Schemas
|
|
||||||
@using Iceshrimp.Frontend.Components
|
|
||||||
@inject ApiService Api
|
|
||||||
<h3>Authenticated note preview</h3>
|
|
||||||
|
|
||||||
@if (_note != null)
|
|
||||||
{
|
|
||||||
<TimelineNote Note="_note" />
|
|
||||||
}
|
|
||||||
else if (_error != null)
|
|
||||||
{
|
|
||||||
<p>Error!: @_error.Error</p>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<p>Fetching note...</p>
|
|
||||||
}
|
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter]
|
|
||||||
public string Id { get; set; } = null!;
|
|
||||||
|
|
||||||
private ErrorResponse? _error;
|
|
||||||
private NoteResponse? _note;
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_note = await Api.Notes.GetNote(Id) ?? throw new ApiException(new ErrorResponse
|
|
||||||
{
|
|
||||||
StatusCode = 404,
|
|
||||||
Error = "Note not found",
|
|
||||||
RequestId = "-"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (ApiException e)
|
|
||||||
{
|
|
||||||
_error = e.Response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,13 +2,14 @@
|
||||||
@using Iceshrimp.Shared.Schemas
|
@using Iceshrimp.Shared.Schemas
|
||||||
@using Iceshrimp.Frontend.Components
|
@using Iceshrimp.Frontend.Components
|
||||||
@using Iceshrimp.Frontend.Core.Services
|
@using Iceshrimp.Frontend.Core.Services
|
||||||
|
@using Iceshrimp.Frontend.Components.Note
|
||||||
@inject ApiService ApiService
|
@inject ApiService ApiService
|
||||||
|
|
||||||
@if (_init)
|
@if (_init)
|
||||||
{
|
{
|
||||||
<div class="scroller">
|
<div class="scroller">
|
||||||
<div class="root-note">
|
<div class="root-note">
|
||||||
<NoteComponent Note="RootNote"></NoteComponent>
|
<Note NoteResponse="RootNote"></Note>
|
||||||
</div>
|
</div>
|
||||||
@if (Descendants != null)
|
@if (Descendants != null)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue