@page "/editProfile"
@inject NavigationManager Nav
@inject ApiService api
@inject State State
@inject IJSRuntime JS
@if (markdownValue != null)
{
}
@if (markdownValue != null)
{
Advanced
Theme:
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 string? theme;
private Theme? selectedTheme;
private Dictionary? themes;
private bool loading = true;
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;
theme = data.Theme;
themes = await State.GetThemes();
selectedTheme = themes?[theme];
loading = false;
await InvokeAsync(StateHasChanged);
await Editor!.SetValueAsync(markdownValue);
}
loading = false;
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,
Theme = string.IsNullOrEmpty(theme) ? null : theme
});
if (result != null) {
await State.RefreshNow();
await InvokeAsync(StateHasChanged);
Nav.NavigateTo($"/person/{State.SelectedAddressName}#profile");
}
loading = false;
await InvokeAsync(StateHasChanged);
}
public async Task OnCustomButtonClicked(MarkdownButtonEventArgs eventArgs) {
if (eventArgs.Name == "Help") {
await JS.InvokeVoidAsync("open", "https://home.omg.lol/info/editor", "_blank");
}
}
public void ThemeChanged(Theme? _theme) {
theme = _theme?.Id;
selectedTheme = _theme;
InvokeAsync(StateHasChanged);
}
}