Neighbourhood.omg.lol/Components/Pages/EditProfile.razor
Gordon Pedersen 25f362bfc5 Added a way to edit the profile page
Including custom css and head content, but not custom themes or metadata (yet)
2024-07-05 15:47:05 +10:00

83 lines
2.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@page "/editProfile"
@inject NavigationManager Nav
@inject RestService api
@inject State State
<div class="max markdown-editor">
<MarkdownEditor @ref="Editor"
@bind-Value="@markdownValue"
Theme="material-darker"
MaxHeight="100%" />
</div>
<details id="advanced">
<summary> Advanced </summary>
<small>Style you include here will be places in a &lt;style&gt; element in your pages &lt;head&gt;.</small>
<div class="field textarea label border max">
<InputTextArea @bind-Value="css"></InputTextArea>
<label>Custom CSS</label>
</div>
<small>Anything you put here will be included in your pages &lt;head&gt; element.</small>
<div class="field textarea label border max">
<InputTextArea @bind-Value="head"></InputTextArea>
<label>Additional &lt;head&gt; Content</label>
</div>
</details>
<nav>
<div class="max"></div>
<button class="transparent link" onclick="history.back();" disabled="@loading">Cancel</button>
<button @onclick="Save" disabled="@loading">
@if (loading) {
<span>Saving...</span>
}
else {
<i class="fa-solid fa-floppy-disk"></i> <span>Save & Publish</span>
}
</button>
</nav>
@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;
}
}