[frontend] Add support for posting quotes

This commit is contained in:
Lilian 2024-05-20 15:14:45 +02:00
parent 7b7dd2ee61
commit ba2392ac90
No known key found for this signature in database
GPG key ID: 007CA12D692829E1
4 changed files with 59 additions and 19 deletions

View file

@ -14,10 +14,10 @@
<Dropdown TBind="NoteVisibility" Elements="@DropDownCreate()" @bind-Value="NoteDraft.Visibility"/>
<button @onclick="SendNote" class="post-btn">Post<Icon Name="Icons.PaperPlaneRight"/></button>
</div>
@if (ReplyTo != null)
@if (ReplyOrQuote != null)
{
<div class="reply-to">
<NoteComponent Note="ReplyTo" AsQuote="true" />
<div class="reply-or-quote">
<NoteComponent Note="ReplyOrQuote" AsQuote="true"/>
</div>
}
@if (NoteDraft.Cw != null)
@ -25,7 +25,7 @@
<input @bind="NoteDraft.Cw" class="input cw-field" placeholder="Content Warning"/>
<hr class="separator"/>
}
<textarea @bind="NoteDraft.Text" class="textarea" placeholder="What's on your mind?" rows="5" cols="35"></textarea>
<textarea @bind="NoteDraft.Text" class="textarea" placeholder="@TextPlaceholder" rows="5" cols="35"></textarea>
<div class="footer">
<button class="footer-btn" @onclick="OpenUpload">
<Icon Name="Icons.Upload" Size="1.3rem"></Icon>
@ -44,14 +44,21 @@
private IJSObjectReference? _module;
private IList<DriveFileResponse> Attachments { get; set; } = [];
private InputFile UploadInput { get; set; }
private NoteBase? ReplyTo { get; set; }
private NoteBase? ReplyOrQuote { get; set; }
private string? TextPlaceholder { get; set; }
private NoteCreateRequest NoteDraft { get; set; } = new NoteCreateRequest
{
Text = "",
Visibility = NoteVisibility.Followers, // FIXME: Default to visibilty in settings
Cw = null
};
private Dictionary<string, string> AvailablePlaceholders { get; set; } = new()
{
{ "default", "What's on your mind?" },
{ "reply", "Reply goes here!" },
{ "quote", "Quote this post!" }
};
RenderFragment DropdownIcon(NoteVisibility vis)
{
@ -92,25 +99,43 @@
await _module.InvokeVoidAsync("openUpload", UploadInput.Element);
}
public async Task OpenDialog(NoteBase? replyTo = null)
public async Task OpenDialog(NoteBase? replyTo = null, NoteBase? quote = null)
{
if (replyTo != null)
{
ReplyTo = replyTo;
ResetState();
ReplyOrQuote = replyTo;
NoteDraft.ReplyId = replyTo.Id;
NoteDraft.Visibility = replyTo.Visibility;
TextPlaceholder = AvailablePlaceholders["reply"];
StateHasChanged();
}
else if (quote != null)
{
ResetState();
ReplyOrQuote = quote;
NoteDraft.RenoteId = quote.Id;
NoteDraft.Visibility = quote.Visibility;
TextPlaceholder = AvailablePlaceholders["quote"];
StateHasChanged();
}
else
{
ReplyTo = null;
NoteDraft.ReplyId = null;
ResetState();
StateHasChanged();
}
await _module.InvokeVoidAsync("openDialog", Dialog);
}
private void ResetState()
{
ReplyOrQuote = null;
Attachments = new List<DriveFileResponse>();
NoteDraft = new NoteCreateRequest { Text = "", Visibility = NoteVisibility.Followers, Cw = null };
TextPlaceholder = AvailablePlaceholders["default"];
}
private async Task CloseDialog()
{
await _module.InvokeVoidAsync("closeDialog", Dialog);
@ -151,4 +176,9 @@
}
}
protected override void OnInitialized()
{
TextPlaceholder = AvailablePlaceholders["default"];
}
}

View file

@ -48,7 +48,7 @@
.file-input {
display: none;
}
.reply-to {
.reply-or-quote {
border: solid var(--highlight-color) 0.1rem;
border-radius: 0.75rem;
padding: 0.5rem;

View file

@ -89,7 +89,7 @@
public void Reply()
{
ComposeService.ComposeDialog?.OpenDialog(Note);
ComposeService.ComposeDialog?.OpenDialog(Note, null);
}
public void Renote()
@ -106,4 +106,9 @@
};
ApiService.Notes.CreateNote(renote);
}
public void DoQuote()
{
ComposeService.ComposeDialog?.OpenDialog(null, Note);
}
}

View file

@ -31,7 +31,7 @@
<button class="btn" @onclick:stopPropagation="true">
<Icon Name="Icons.Smiley" Size="1.3em"/>
</button>
<button class="btn" @onclick:stopPropagation="true">
<button class="btn" @onclick="Quote" @onclick:stopPropagation="true">
<Icon Name="Icons.Quotes" Size="1.3em"/>
</button>
<button class="btn" @onclick:stopPropagation="true">
@ -59,4 +59,9 @@
{
NoteComponent.Renote();
}
private void Quote()
{
NoteComponent.DoQuote();
}
}