|
| 1 | +@using LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Services |
| 2 | +<ModalDialog @ref="Dialog" Title="AutoComplete Content"> |
| 3 | + <form> |
| 4 | + <div class="mb-3"> |
| 5 | + <label for="systemMessage" class="form-label">Message</label> |
| 6 | + <TextAreaWithShortcuts Class="form-control" Id="systemMessage" Rows="2" Placeholder="Enter message..." @bind-Value="@options.Prompt"></TextAreaWithShortcuts> |
| 7 | + </div> |
| 8 | + |
| 9 | + <div class="mb-3"> |
| 10 | + <small class="text-muted">Include the blog post's title in the AI input.</small> |
| 11 | + <div class="form-check form-switch"> |
| 12 | + <input class="form-check-input" type="checkbox" id="includeTitle" @bind-value="@options.IncludeTitle"> |
| 13 | + <label class="form-check-label" for="includeTitle">Include Title</label> |
| 14 | + </div> |
| 15 | + </div> |
| 16 | + |
| 17 | + <div class="mb-3"> |
| 18 | + <small class="text-muted">Include the blog post's short description in the AI input.</small> |
| 19 | + <div class="form-check form-switch"> |
| 20 | + <input class="form-check-input" type="checkbox" id="includeShortDescription" @bind-value="@options.IncludeShortDescription"> |
| 21 | + <label class="form-check-label" for="includeShortDescription">Include Short Description</label> |
| 22 | + </div> |
| 23 | + </div> |
| 24 | + |
| 25 | + <div class="mb-3"> |
| 26 | + <small class="text-muted">Include the blog post's tags in the AI input.</small> |
| 27 | + <div class="form-check form-switch"> |
| 28 | + <input class="form-check-input" type="checkbox" id="includeTags" @bind-value="@options.IncludeTags"> |
| 29 | + <label class="form-check-label" for="includeTags">Include Tags</label> |
| 30 | + </div> |
| 31 | + </div> |
| 32 | + |
| 33 | + <div class="mb-3"> |
| 34 | + <small class="text-muted">Include the blog post's content in the AI input.</small> |
| 35 | + <div class="form-check form-switch"> |
| 36 | + <input class="form-check-input" type="checkbox" id="includeContent" @bind-value="@options.IncludeContent"> |
| 37 | + <label class="form-check-label" for="includeContent">Include Content</label> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + |
| 41 | + <div class="mb-3"> |
| 42 | + <small class="text-muted">Keep original text and append AI-generated content, or allow AI to rewrite the content.</small> |
| 43 | + <div class="form-check form-switch"> |
| 44 | + <input class="form-check-input" type="checkbox" id="keepOriginalText" @bind-value="@options.KeepOriginalText"> |
| 45 | + <label class="form-check-label" for="keepOriginalText">Keep Original Text</label> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + |
| 49 | + <button type="button" class="btn btn-primary btn-sm" @onclick="Generate">Generate</button> |
| 50 | + |
| 51 | + <div class="mt-3"> |
| 52 | + <label for="outputField" class="form-label">Output</label> |
| 53 | + <textarea class="form-control" id="outputField" rows="6" readonly>@options.Content</textarea> |
| 54 | + </div> |
| 55 | + |
| 56 | + <div class="d-flex mt-3 justify-content-end gap-3"> |
| 57 | + <button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button> |
| 58 | + <button type="button" class="btn btn-success" @onclick="Save" disabled="@(!options.AllowSave)">Save</button> |
| 59 | + </div> |
| 60 | + </form> |
| 61 | +</ModalDialog> |
| 62 | + |
| 63 | +@code { |
| 64 | + [Inject] private AutocompleteService AutocompleteService { get; set; } |
| 65 | + |
| 66 | + [Parameter] public CreateNewModel Model { get; set; } |
| 67 | + [Parameter] public EventCallback<string> ContentGenerated { get; set; } |
| 68 | + |
| 69 | + private ModalDialog Dialog { get; set; } |
| 70 | + private Options options = new (); |
| 71 | + |
| 72 | + public void Open() |
| 73 | + { |
| 74 | + Dialog.Open(); |
| 75 | + StateHasChanged(); |
| 76 | + } |
| 77 | + |
| 78 | + private void Cancel() |
| 79 | + { |
| 80 | + Dialog.Close(); |
| 81 | + } |
| 82 | + |
| 83 | + private async Task Generate() |
| 84 | + { |
| 85 | + var completeOptions = new AutocompleteOptions( |
| 86 | + options.IncludeTitle ? Model.Title : string.Empty, |
| 87 | + options.IncludeShortDescription ? Model.ShortDescription : string.Empty, |
| 88 | + options.IncludeTags ? Model.Tags : string.Empty, |
| 89 | + options.IncludeContent ? Model.Content : string.Empty, |
| 90 | + options.Prompt, |
| 91 | + options.KeepOriginalText); |
| 92 | + options.Content = await AutocompleteService.GetAutocomplete(completeOptions); |
| 93 | + options.AllowSave = true; |
| 94 | + } |
| 95 | + |
| 96 | + private async Task Save() |
| 97 | + { |
| 98 | + await ContentGenerated.InvokeAsync(options.Content); |
| 99 | + Dialog.Close(); |
| 100 | + options = new(); |
| 101 | + } |
| 102 | + |
| 103 | + private sealed class Options |
| 104 | + { |
| 105 | + public string Prompt { get; set; } |
| 106 | + public bool IncludeTitle { get; set; } |
| 107 | + public bool IncludeShortDescription { get; set; } |
| 108 | + public bool IncludeTags { get; set; } |
| 109 | + public bool IncludeContent { get; set; } |
| 110 | + public bool KeepOriginalText { get; set; } |
| 111 | + public string Content { get; set; } |
| 112 | + |
| 113 | + public bool AllowSave { get; set; } |
| 114 | + } |
| 115 | +} |
0 commit comments