From 6e5b206c20d78fd5ea591fcf065f8dfdd9abe205 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Tue, 23 Jul 2024 11:12:52 +1000 Subject: [PATCH] Enable edit statuslog bio --- Classes/ApiService.cs | 9 ++-- Classes/State.cs | 2 +- Components/EditBioDialog.razor | 79 ++++++++++++++++++++++++++++++++++ Components/Pages/Person.razor | 6 +++ Models/API/PostStatusBio.cs | 5 +++ wwwroot/css/style.css | 4 ++ 6 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 Components/EditBioDialog.razor create mode 100644 Models/API/PostStatusBio.cs diff --git a/Classes/ApiService.cs b/Classes/ApiService.cs index 39da78e..1f9b904 100644 --- a/Classes/ApiService.cs +++ b/Classes/ApiService.cs @@ -167,10 +167,11 @@ namespace Neighbourhood.omg.lol public async Task> Statuslog(string address) => (await Get($"/address/{address}/statuses"))?.Statuses ?? new List(); - public async Task StatuslogBio(string address) { - StatusBioResponseData? responseData = await Get($"/address/{address}/statuses/bio"); - return Utilities.MdToHtmlMarkup(responseData?.Bio ?? ""); - } + public async Task StatuslogBio(string address) => + (await Get($"/address/{address}/statuses/bio"))?.Bio ?? string.Empty; + + public async Task PostStatuslogBio(string address, string bio) => + (await Post($"/address/{address}/statuses/bio", new PostStatusBio() { Content = bio }))?.Bio ?? string.Empty; public async Task AccountInfo() => await Get("/account/application/info"); diff --git a/Classes/State.cs b/Classes/State.cs index eb56aa9..baa8b26 100644 --- a/Classes/State.cs +++ b/Classes/State.cs @@ -224,7 +224,7 @@ namespace Neighbourhood.omg.lol { public async Task GetBio(string address, bool forceRefresh = false) { CachedAddress = address; if (forceRefresh || CachedAddressBio == null) { - CachedAddressBio = await api.StatuslogBio(address); + CachedAddressBio = Utilities.MdToHtmlMarkup(await api.StatuslogBio(address)); } return CachedAddressBio; } diff --git a/Components/EditBioDialog.razor b/Components/EditBioDialog.razor new file mode 100644 index 0000000..5d218f1 --- /dev/null +++ b/Components/EditBioDialog.razor @@ -0,0 +1,79 @@ +@inject IJSRuntime JS +@inject State State +@inject ApiService api + +
+ +
Edit your statuslog bio
+
+
+ @if (Bio != null) { + + + + + + + + + + + + + + + + } +
+
+ +
+ +@code { + private MarkdownEditor? Editor; + public string? Bio { get; set; } + [Parameter] + public string? Address { get; set; } + private bool loading = true; + [Parameter] + public string? id { get; set; } + + protected override async Task OnInitializedAsync() { + await base.OnInitializedAsync(); + Bio = await api.StatuslogBio(Address ?? State.SelectedAddressName!); + await InvokeAsync(StateHasChanged); + await Editor!.SetValueAsync(Bio); + loading = false; + await InvokeAsync(StateHasChanged); + } + + public async Task PostBio() { + loading = true; + await InvokeAsync(StateHasChanged); + + // Post the bio + await api.PostStatuslogBio(Address!, Bio ?? string.Empty); + State.CachedAddressBio = Utilities.MdToHtmlMarkup(Bio ?? string.Empty); + + await JS.InvokeVoidAsync("ui", "#" + id); + // reset input + await OnInitializedAsync(); + loading = false; + await InvokeAsync(StateHasChanged); + State.SendRefresh(); + } +} diff --git a/Components/Pages/Person.razor b/Components/Pages/Person.razor index 75967fc..6936a98 100644 --- a/Components/Pages/Person.razor +++ b/Components/Pages/Person.razor @@ -79,6 +79,12 @@ } + @if (IsMe) { + +
+ +
+ } @if(IsMe) {