-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathTextHTMLViewPlugin.razor.cs
More file actions
42 lines (34 loc) · 1.29 KB
/
TextHTMLViewPlugin.razor.cs
File metadata and controls
42 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Ganss.Xss;
namespace FluentCMS.Web.Plugins.TextHTML;
public partial class TextHTMLViewPlugin
{
private const string CONTENT_TYPE_NAME = nameof(TextHTMLContent);
private TextHTMLContent? Item { get; set; }
private static readonly HtmlSanitizer Sanitizer = new();
private string _sanitizedContent = string.Empty;
private async Task UpdateContent(string content)
{
if (Item is null)
return;
Item.Content = content;
_sanitizedContent = Sanitizer.Sanitize(Item.Content);
await ApiClient.PluginContent.UpdateAsync(CONTENT_TYPE_NAME, Plugin.Id, Item.Id, Item.ToDictionary());
}
private async Task OnCancel()
{
StateHasChanged();
await Task.CompletedTask;
}
protected override async Task OnInitializedAsync()
{
if (Plugin is not null)
{
var response = await ApiClient.PluginContent.GetAllAsync(CONTENT_TYPE_NAME, Plugin.Id);
if (response?.Data != null && response.Data.ToContentList<TextHTMLContent>().Count != 0)
{
Item = response.Data.ToContentList<TextHTMLContent>().FirstOrDefault() ?? default!;
_sanitizedContent = Item is not null ? Sanitizer.Sanitize(Item.Content) : string.Empty;
}
}
}
}