|
1 | 1 | @using LinkDotNet.Blog.Domain |
| 2 | +@using LinkDotNet.Blog.Infrastructure |
| 3 | +@using LinkDotNet.Blog.Infrastructure.Persistence |
2 | 4 | @using LinkDotNet.Blog.Web.Features.Services |
3 | 5 | @using NCronJob |
4 | 6 | @inject IJSRuntime JSRuntime |
5 | 7 | @inject ICacheInvalidator CacheInvalidator |
6 | 8 | @inject IInstantJobRegistry InstantJobRegistry |
| 9 | +@inject IRepository<ShortCode> ShortCodeRepository |
7 | 10 |
|
8 | 11 | <div class="container"> |
9 | 12 | <h3 class="fw-bold">@Title</h3> |
|
17 | 20 | </div> |
18 | 21 | <div class="form-floating mb-3"> |
19 | 22 | <MarkdownTextArea Id="short" Class="form-control" Rows="4" Placeholder="Short Description" |
20 | | - @bind-Value="@model.ShortDescription"></MarkdownTextArea> |
| 23 | + @bind-Value="@model.ShortDescription" |
| 24 | + PreviewFunction="ReplaceShortCodes" |
| 25 | + ></MarkdownTextArea> |
21 | 26 | <ValidationMessage For="() => model.ShortDescription"></ValidationMessage> |
22 | 27 | </div> |
23 | | - <div class="form-floating mb-3"> |
| 28 | + <div class="form-floating mb-3 relative"> |
24 | 29 | <MarkdownTextArea Id="content" Class="form-control" Rows="20" Placeholder="Content" |
| 30 | + PreviewFunction="ReplaceShortCodes" |
25 | 31 | @bind-Value="@model.Content"></MarkdownTextArea> |
26 | 32 | <ValidationMessage For="() => model.Content"></ValidationMessage> |
| 33 | + |
| 34 | + <div class="btn-group position-absolute bottom-0 end-0 m-5 extra-buttons"> |
| 35 | + <button class="btn btn-primary btn-outlined btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> |
| 36 | + More |
| 37 | + </button> |
| 38 | + <ul class="dropdown-menu"> |
| 39 | + @if (shortCodes.Count > 0) |
| 40 | + { |
| 41 | + <li> |
| 42 | + <button type="button" @onclick="OpenShortCodeDialog" class="dropdown-item"> |
| 43 | + <span>Get shortcode</span> |
| 44 | + </button> |
| 45 | + </li> |
| 46 | + } |
| 47 | + <li><button type="button" class="dropdown-item" @onclick="FeatureDialog.Open">Experimental Features</button></li> |
| 48 | + </ul> |
| 49 | + </div> |
27 | 50 | </div> |
28 | 51 | <div class="form-floating mb-3"> |
29 | 52 | <InputText type="url" class="form-control" id="preview" placeholder="Preview-Url" @bind-Value="model.PreviewImageUrl"/> |
|
83 | 106 | </div> |
84 | 107 |
|
85 | 108 | <FeatureInfoDialog @ref="FeatureDialog"></FeatureInfoDialog> |
| 109 | +<ShortCodeDialog @ref="ShortCodeDialog" ShortCodes="shortCodes"></ShortCodeDialog> |
86 | 110 |
|
87 | 111 | <NavigationLock ConfirmExternalNavigation="@model.IsDirty" OnBeforeInternalNavigation="PreventNavigationWhenDirty"></NavigationLock> |
88 | 112 | @code { |
|
99 | 123 | public bool ClearAfterCreated { get; set; } = true; |
100 | 124 |
|
101 | 125 | private FeatureInfoDialog FeatureDialog { get; set; } = default!; |
| 126 | + private ShortCodeDialog ShortCodeDialog { get; set; } = default!; |
102 | 127 |
|
103 | 128 | private CreateNewModel model = new(); |
104 | 129 |
|
105 | 130 | private bool canSubmit = true; |
| 131 | + private IPagedList<ShortCode> shortCodes = PagedList<ShortCode>.Empty; |
106 | 132 |
|
107 | 133 | private bool IsScheduled => model.ScheduledPublishDate.HasValue; |
108 | 134 |
|
109 | | - protected override void OnParametersSet() |
| 135 | + protected override async Task OnInitializedAsync() |
| 136 | + { |
| 137 | + shortCodes = await ShortCodeRepository.GetAllAsync(); |
| 138 | + } |
| 139 | + |
| 140 | + protected override void OnParametersSet() |
110 | 141 | { |
111 | 142 | if (BlogPost is null) |
112 | 143 | { |
|
161 | 192 | context.PreventNavigation(); |
162 | 193 | } |
163 | 194 | } |
| 195 | + |
| 196 | + private Task<string> ReplaceShortCodes(string markdown) |
| 197 | + { |
| 198 | + foreach (var code in shortCodes) |
| 199 | + { |
| 200 | + markdown = markdown.Replace($"[[{code.Name}]]", code.MarkdownContent); |
| 201 | + } |
| 202 | + |
| 203 | + return Task.FromResult(MarkdownConverter.ToMarkupString(markdown).Value); |
| 204 | + } |
| 205 | + |
| 206 | + private void OpenShortCodeDialog() |
| 207 | + { |
| 208 | + ShortCodeDialog.Open(); |
| 209 | + StateHasChanged(); |
| 210 | + } |
164 | 211 | } |
0 commit comments