-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathEditorView.razor
More file actions
50 lines (39 loc) · 1.55 KB
/
EditorView.razor
File metadata and controls
50 lines (39 loc) · 1.55 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
43
44
45
46
47
48
49
50
@inject IConfiguration _config;
<MudStack Justify="Justify.FlexEnd" Row="true">
<MudButton OnClick="OnCancel" Size="Size.Small">Cancel</MudButton>
<MudButton OnClick="Reset" Size="Size.Small">Reset</MudButton>
<MudButton Color="Color.Primary" OnClick="SaveChanges" Size="Size.Small" StartIcon="@Icons.Material.Filled.Save" Variant="Variant.Filled">Save Changes</MudButton>
</MudStack>
<MudHtmlEditor @ref="_editor" @bind-Html="@_html" />
@code {
private MudHtmlEditor _editor = default!;
private string _html = "";
[Parameter]
public string InitialHtml { get; set; } = "";
[Parameter]
public EventCallback OnCancel { get; set; }
[Parameter]
public EventCallback<string> OnSave { get; set; }
protected override void OnParametersSet()
{
_html = InitialHtml;
}
private async Task Reset()
{
await _editor.Reset();
}
private async Task SaveChanges()
{
await OnSave.InvokeAsync(_html);
}
// Upload the image into the wwwroot/images folder for demonstration
private async Task<string> ImageUploadHandler(string imageName, string imageContentType, Stream imageStream)
{
var root = _config.GetValue<string>(WebHostDefaults.ContentRootKey) ?? "";
var path = Path.Combine(root, $"wwwroot{Path.DirectorySeparatorChar}images", imageName);
FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
await imageStream.CopyToAsync(filestream);
filestream.Close();
return $"images/{imageName}";
}
}