From b1cb4e21c430c8a49ea23c8f11f5f2c5f2a6ace7 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Mon, 1 Jul 2024 09:44:55 +1000 Subject: [PATCH] =?UTF-8?q?Proper=20Ephemeral=20Integration=20=F0=9F=A5=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Components/NewEphemeral.razor | 58 ++++++++++++++++++++++++++++++++ Components/Pages/Ephemeral.razor | 9 +++++ Models/EphemeralData.cs | 11 ++++++ Models/EphemeralResponseData.cs | 12 +++++++ Models/State.cs | 2 +- RestService.cs | 8 ++++- 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 Components/NewEphemeral.razor create mode 100644 Models/EphemeralData.cs create mode 100644 Models/EphemeralResponseData.cs diff --git a/Components/NewEphemeral.razor b/Components/NewEphemeral.razor new file mode 100644 index 0000000..bb0b235 --- /dev/null +++ b/Components/NewEphemeral.razor @@ -0,0 +1,58 @@ +@inject IJSRuntime JS +@inject State State +@inject RestService api +@inject NavigationManager navigationManager + +
+ +
Share a fleeting thought
+
+
+ +
+
+
+

Your anonymous post will be shared for a while, and then it will disappear forever. It can’t be edited, so take care before submitting.

+
+
+

If you need help, don’t suffer in silence. Talk to someone right now.

+
+ +
+ +@code { + [Parameter] + public string id { get; set; } + [Parameter] + public bool Active { get; set; } + [Parameter] + public string Content { get; set; } = string.Empty; + + private bool loading = false; + + public async Task PostEphemeral() { + loading = true; + await InvokeAsync(StateHasChanged); + var result = await api.PostEphemeral(Content); + if (result != null) { + await State.RefreshStatuses(); + State.SendRefresh(); + await InvokeAsync(StateHasChanged); + } + + this.Active = false; + await JS.InvokeVoidAsync("ui", "#" + id); + Content = string.Empty; + loading = false; + } +} diff --git a/Components/Pages/Ephemeral.razor b/Components/Pages/Ephemeral.razor index 1255c8f..364c93d 100644 --- a/Components/Pages/Ephemeral.razor +++ b/Components/Pages/Ephemeral.razor @@ -9,6 +9,15 @@ Eph.emer.al is a place for fleeting thoughts. Everything on this page will disappear after a while. + + + + + + +
@if (messages != null) { diff --git a/Models/EphemeralData.cs b/Models/EphemeralData.cs new file mode 100644 index 0000000..81d96e7 --- /dev/null +++ b/Models/EphemeralData.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Neighbourhood.omg.lol.Models { + public class EphemeralData { + public string Content { get; set; } + } +} diff --git a/Models/EphemeralResponseData.cs b/Models/EphemeralResponseData.cs new file mode 100644 index 0000000..ed106cd --- /dev/null +++ b/Models/EphemeralResponseData.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Neighbourhood.omg.lol.Models { + public class EphemeralResponseData : IOmgLolResponseData { + public string Message { get; set; } + public List Content { get; set; } + } +} diff --git a/Models/State.cs b/Models/State.cs index 677806e..d3f8934 100644 --- a/Models/State.cs +++ b/Models/State.cs @@ -6,7 +6,7 @@ using System.Text.Json; namespace Neighbourhood.omg.lol.Models { public class State : INotifyPropertyChanged { // Feature flags - public bool FeatureFollowing { get; } = true; + public bool FeatureFollowing { get; } = false; // Main data lists public List? Statuses { get; set; } public List? Pics { get; set; } diff --git a/RestService.cs b/RestService.cs index 540bfb6..01a5dec 100644 --- a/RestService.cs +++ b/RestService.cs @@ -219,7 +219,13 @@ namespace Neighbourhood.omg.lol { public async Task PostNowPage(string address, string content, bool listed) => await Post($"/address/{address}/now", new NowContentData { Content = content, Listed = listed ? 1 : 0 }); - public async Task> Ephemeral() { + public async Task> Ephemeral() => + (await Get($"/ephemeral"))?.Content?.Select(s => (MarkupString)s)?.ToList() ?? new List(); + + public async Task PostEphemeral(string content) => + await Post("/ephemeral", new EphemeralData { Content = content }); + + public async Task> EphemeralScrape() { List notes = new List(); Uri Uri = new Uri($"https://eph.emer.al/"); try {