-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathShortCodeDialog.razor
More file actions
62 lines (58 loc) · 1.69 KB
/
Copy pathShortCodeDialog.razor
File metadata and controls
62 lines (58 loc) · 1.69 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
51
52
53
54
55
56
57
58
59
60
61
62
@using LinkDotNet.Blog.Domain
@inject IToastService ToastService
@inject IJSRuntime JSRuntime
<ModalDialog @ref="ModalDialog" Title="Select shortcode">
<div class="modal-body">
<div class="alert alert-info">
<p class="p-2">
Clicking on a shortcode, will put the shortcode into the clipboard.
So you can paste it into the markdown editor. Currently it isn't possible to insert it directly into the editor at the cursor position.
</p>
</div>
<div class="table-responsive" style="max-height: 400px; overflow-y: auto;">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Preview</th>
</tr>
</thead>
<tbody>
@foreach (var shortCode in ShortCodes)
{
<tr @onclick="() => AddShortCode(shortCode)" style="cursor: pointer;">
<td>@shortCode.Name</td>
<td>
<div class="markdown-scrollable">
@MarkdownConverter.ToMarkupString(shortCode.MarkdownContent)
</div>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" @onclick="CloseDialog">Close</button>
</div>
</ModalDialog>
@code {
private ModalDialog ModalDialog { get; set; } = default!;
[Parameter] public IReadOnlyCollection<ShortCode> ShortCodes { get; set; } = [];
public void Open()
{
ModalDialog.Open();
StateHasChanged();
}
private async Task AddShortCode(ShortCode shortCode)
{
await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", $"[[{shortCode.Name}]]");
ToastService.ShowSuccess($"Shortcode {shortCode.Name} copied to clipboard");
CloseDialog();
}
private void CloseDialog()
{
ModalDialog.Close();
}
}