From 25f362bfc53ec8c0520df0b9d5b67967b7c1b04f Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Fri, 5 Jul 2024 15:47:05 +1000 Subject: [PATCH] Added a way to edit the profile page Including custom css and head content, but not custom themes or metadata (yet) --- Classes/RestService.cs | 9 ++++ Components/Pages/EditProfile.razor | 83 ++++++++++++++++++++++++++++++ Components/Pages/Person.razor | 6 +++ Models/API/PostProfile.cs | 14 +++++ Models/API/ProfileResponseData.cs | 21 ++++++++ wwwroot/css/style.css | 6 +++ wwwroot/js/csharp.js | 6 +++ 7 files changed, 145 insertions(+) create mode 100644 Components/Pages/EditProfile.razor create mode 100644 Models/API/PostProfile.cs create mode 100644 Models/API/ProfileResponseData.cs diff --git a/Classes/RestService.cs b/Classes/RestService.cs index f7aefe9..4693d00 100644 --- a/Classes/RestService.cs +++ b/Classes/RestService.cs @@ -223,6 +223,15 @@ namespace Neighbourhood.omg.lol public async Task PostEphemeral(string content) => await Post("/ephemeral", new EphemeralData { Content = content }); + public async Task GetProfile(string address) => + await Get($"/address/{address}/web"); + + public async Task PostProfile(string address, string content, bool publish = true) => + await Post($"/address/{address}/web", new PostProfile { Content = content, Publish = publish }); + + public async Task PostProfile(string address, PostProfile data) => + await Post($"/address/{address}/web", data); + public async Task> EphemeralScrape() { List notes = new List(); Uri Uri = new Uri($"https://eph.emer.al/"); diff --git a/Components/Pages/EditProfile.razor b/Components/Pages/EditProfile.razor new file mode 100644 index 0000000..43612e5 --- /dev/null +++ b/Components/Pages/EditProfile.razor @@ -0,0 +1,83 @@ +@page "/editProfile" +@inject NavigationManager Nav +@inject RestService api +@inject State State + + +
+ +
+ +
+ Advanced + Style you include here will be places in a <style> element in your page’s <head>. +
+ + +
+ Anything you put here will be included in your page’s <head> element. +
+ + +
+
+ + + +@code { + private MarkdownEditor? Editor; + private string? markdownValue; + private string? css; + private string? head; + + private bool loading = false; + + protected override async Task OnInitializedAsync() { + await base.OnInitializedAsync(); + ProfileResponseData? data = await api.GetProfile(State.SelectedAddressName!); + if (data != null) { + markdownValue = data.Content; + css = data.Css; + head = data.Head; + + await Editor!.SetValueAsync(markdownValue); + } + await InvokeAsync(StateHasChanged); + } + + Task OnMarkdownValueChanged(string value) { + return Task.CompletedTask; + } + + public async Task Save() { + loading = true; + await InvokeAsync(StateHasChanged); + var result = await api.PostProfile(State.SelectedAddressName!, + new PostProfile() { + Content = markdownValue ?? string.Empty, + Css = string.IsNullOrEmpty(css) ? null : css, + Head = string.IsNullOrEmpty(head) ? null : head + }); + if (result != null) { + await State.RefreshNow(); + await InvokeAsync(StateHasChanged); + Nav.NavigateTo($"/person/{State.SelectedAddressName}#profile"); + } + + loading = false; + } +} diff --git a/Components/Pages/Person.razor b/Components/Pages/Person.razor index c95494e..15e2bbc 100644 --- a/Components/Pages/Person.razor +++ b/Components/Pages/Person.razor @@ -52,6 +52,12 @@
Open in browser + @if (IsMe) { + + + Edit + + }
diff --git a/Models/API/PostProfile.cs b/Models/API/PostProfile.cs new file mode 100644 index 0000000..7d3da00 --- /dev/null +++ b/Models/API/PostProfile.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Neighbourhood.omg.lol.Models { + public class PostProfile { + public string Content { get; set; } = string.Empty; + public bool Publish { get; set; } = true; + public string? Css { get; set; } + public string? Head { get; set; } + } +} diff --git a/Models/API/ProfileResponseData.cs b/Models/API/ProfileResponseData.cs new file mode 100644 index 0000000..988e1e5 --- /dev/null +++ b/Models/API/ProfileResponseData.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Neighbourhood.omg.lol.Models { + public class ProfileResponseData: IOmgLolResponseData { + public string Message { get; set; } = string.Empty; + public string Content { get; set; } = string.Empty; + public string Type { get; set; } = string.Empty; + public string Theme { get; set; } = string.Empty; + public string Css { get; set; } = string.Empty; + public string Head { get; set; } = string.Empty; + public string Verified { get; set; } = string.Empty; + public string Pfp { get; set; } = string.Empty; + public string Metadata { get; set; } = string.Empty; + public string Branding { get; set; } = string.Empty; + + } +} diff --git a/wwwroot/css/style.css b/wwwroot/css/style.css index 64c5dd6..44a224a 100644 --- a/wwwroot/css/style.css +++ b/wwwroot/css/style.css @@ -495,4 +495,10 @@ article { article.now { margin: 0; width:auto; +} + +#advanced textarea, #advanced .field.textarea { + background-color: #212121; + color: #EEFFFF; + font-family: monospace; } \ No newline at end of file diff --git a/wwwroot/js/csharp.js b/wwwroot/js/csharp.js index 2985c9f..8e98bcd 100644 --- a/wwwroot/js/csharp.js +++ b/wwwroot/js/csharp.js @@ -22,4 +22,10 @@ function scrollToId(id) { inline: "nearest" }); } +} + +function toggleDetails(id) { + const element = document.getElementById(id) + if (element instanceof HTMLDetailsElement) + element.open = !element.open } \ No newline at end of file