2024-07-05 05:47:05 +00:00
|
|
|
|
@page "/editProfile"
|
|
|
|
|
@inject NavigationManager Nav
|
2024-07-16 00:45:33 +00:00
|
|
|
|
@inject ApiService api
|
2024-07-05 05:47:05 +00:00
|
|
|
|
@inject State State
|
2024-07-05 07:18:46 +00:00
|
|
|
|
@inject IJSRuntime JS
|
2024-07-05 05:47:05 +00:00
|
|
|
|
|
|
|
|
|
<div class="max markdown-editor">
|
2024-07-11 05:57:53 +00:00
|
|
|
|
@if (markdownValue != null)
|
|
|
|
|
{
|
|
|
|
|
<MarkdownEditor @ref="Editor"
|
|
|
|
|
@bind-Value="@markdownValue"
|
|
|
|
|
Theme="material-darker"
|
|
|
|
|
MaxHeight="100%"
|
2024-07-23 07:02:53 +00:00
|
|
|
|
CustomButtonClicked="@OnCustomButtonClicked"
|
|
|
|
|
AutoDownloadFontAwesome="false"
|
|
|
|
|
>
|
2024-07-11 05:57:53 +00:00
|
|
|
|
<Toolbar>
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.Bold" Icon="fa-solid fa-bold" Title="Bold" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.Italic" Icon="fa-solid fa-italic" Title="Italic" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.Heading" Icon="fa-solid fa-heading" Title="Heading" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.Code" Icon="fa-solid fa-code" Title="Code" Separator="true" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.Quote" Icon="fa-solid fa-quote-left" Title="Quote" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.UnorderedList" Icon="fa-solid fa-list-ul" Title="Unordered List" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.OrderedList" Icon="fa-solid fa-list-ol" Title="Ordered List" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.Link" Icon="fa-solid fa-link" Title="Link" Separator="true" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.Image" Icon="fa-solid fa-image" Title="Image" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.HorizontalRule" Icon="fa-solid fa-horizontal-rule" Title="Horizontal Rule" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.Guide" Icon="fa-solid fa-circle-question" Title="Guide" Separator="true" />
|
|
|
|
|
<MarkdownToolbarButton Action="MarkdownAction.Custom" Icon="omg-icon omg-prami" Title="Editor Information" Name="Help" />
|
|
|
|
|
</Toolbar>
|
|
|
|
|
</MarkdownEditor>
|
|
|
|
|
}
|
2024-07-05 05:47:05 +00:00
|
|
|
|
</div>
|
2024-07-11 05:57:53 +00:00
|
|
|
|
@if (markdownValue != null)
|
|
|
|
|
{
|
|
|
|
|
<details id="advanced">
|
|
|
|
|
<summary> Advanced </summary>
|
|
|
|
|
<h5>Theme:</h5>
|
|
|
|
|
<div class="row bottom-margin">
|
|
|
|
|
<ThemeDialog id="theme-modal" onthemechanged="ThemeChanged"></ThemeDialog>
|
|
|
|
|
<a data-ui="#theme-modal" class="row min" style="text-decoration:none;">
|
|
|
|
|
@if(selectedTheme != null) {
|
|
|
|
|
<ThemeCard theme="selectedTheme"></ThemeCard>
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
<button>Choose a theme</button>
|
|
|
|
|
}
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
<small>Style you include here will be places in a <style> element in your page’s <head>.</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 page’s <head> element.</small>
|
|
|
|
|
<div class="field textarea label border max">
|
|
|
|
|
<InputTextArea @bind-Value="head"></InputTextArea>
|
|
|
|
|
<label>Additional <head> Content</label>
|
|
|
|
|
</div>
|
|
|
|
|
</details>
|
|
|
|
|
}
|
2024-07-05 05:47:05 +00:00
|
|
|
|
<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;
|
2024-07-11 05:57:53 +00:00
|
|
|
|
private string? theme;
|
|
|
|
|
private Theme? selectedTheme;
|
|
|
|
|
private Dictionary<string, Theme>? themes;
|
2024-07-05 05:47:05 +00:00
|
|
|
|
|
2024-07-11 05:57:53 +00:00
|
|
|
|
private bool loading = true;
|
2024-07-05 05:47:05 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2024-07-11 05:57:53 +00:00
|
|
|
|
theme = data.Theme;
|
|
|
|
|
|
|
|
|
|
themes = await State.GetThemes();
|
|
|
|
|
selectedTheme = themes?[theme];
|
|
|
|
|
|
|
|
|
|
loading = false;
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
2024-07-05 05:47:05 +00:00
|
|
|
|
|
|
|
|
|
await Editor!.SetValueAsync(markdownValue);
|
|
|
|
|
}
|
2024-07-11 05:57:53 +00:00
|
|
|
|
loading = false;
|
2024-07-05 05:47:05 +00:00
|
|
|
|
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,
|
2024-07-11 05:57:53 +00:00
|
|
|
|
Head = string.IsNullOrEmpty(head) ? null : head,
|
|
|
|
|
Theme = string.IsNullOrEmpty(theme) ? null : theme
|
2024-07-05 05:47:05 +00:00
|
|
|
|
});
|
|
|
|
|
if (result != null) {
|
|
|
|
|
await State.RefreshNow();
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
Nav.NavigateTo($"/person/{State.SelectedAddressName}#profile");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loading = false;
|
2024-07-11 05:57:53 +00:00
|
|
|
|
await InvokeAsync(StateHasChanged);
|
2024-07-05 05:47:05 +00:00
|
|
|
|
}
|
2024-07-05 07:18:46 +00:00
|
|
|
|
|
|
|
|
|
public async Task OnCustomButtonClicked(MarkdownButtonEventArgs eventArgs) {
|
|
|
|
|
if (eventArgs.Name == "Help") {
|
|
|
|
|
await JS.InvokeVoidAsync("open", "https://home.omg.lol/info/editor", "_blank");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-11 05:57:53 +00:00
|
|
|
|
|
|
|
|
|
public void ThemeChanged(Theme? _theme) {
|
|
|
|
|
theme = _theme?.Id;
|
|
|
|
|
selectedTheme = _theme;
|
|
|
|
|
InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
2024-07-05 05:47:05 +00:00
|
|
|
|
}
|