summaryrefslogtreecommitdiff
path: root/Pages/Component
diff options
context:
space:
mode:
Diffstat (limited to 'Pages/Component')
-rw-r--r--Pages/Component/AboutDialog.razor1
-rw-r--r--Pages/Component/Dialog.razor4
-rw-r--r--Pages/Component/TagEditDialog.razor96
-rw-r--r--Pages/Component/TagEditDialog.razor.css11
-rw-r--r--Pages/Component/TagSelectDialog.razor9
5 files changed, 116 insertions, 5 deletions
diff --git a/Pages/Component/AboutDialog.razor b/Pages/Component/AboutDialog.razor
index 9823761..9ffbad4 100644
--- a/Pages/Component/AboutDialog.razor
+++ b/Pages/Component/AboutDialog.razor
@@ -1,6 +1,7 @@
@using System.Reflection
@using Microsoft.AspNetCore.Hosting
@inject IHostingEnvironment hostingEnvironment
+@implements IDialog
<Dialog @ref=dialog>
<p id="title">@Title</p>
diff --git a/Pages/Component/Dialog.razor b/Pages/Component/Dialog.razor
index ded2d2d..f479368 100644
--- a/Pages/Component/Dialog.razor
+++ b/Pages/Component/Dialog.razor
@@ -1,4 +1,6 @@
-<div style="@(heightStyle + visiblilityStyle)">
+@implements IDialog
+
+<div style="@(heightStyle + visiblilityStyle)">
@if(Title is not null) {
<p>@Title</p>
<hr/>
diff --git a/Pages/Component/TagEditDialog.razor b/Pages/Component/TagEditDialog.razor
new file mode 100644
index 0000000..2e443d4
--- /dev/null
+++ b/Pages/Component/TagEditDialog.razor
@@ -0,0 +1,96 @@
+@inject IDbContextFactory<HBContext> dbFactory;
+@inject ITagService tagService
+@implements IDialog
+
+<Dialog Title=@Title @ref=dialog>
+ <label>
+ Name
+ @if(nameExists) {
+ <p class="error">Tag with that name already exists!</p>
+ }
+ </label>
+ <input type="text" @bind=tagName required/>
+ <label>Namespace</label>
+ <input type="text" @bind=tagNamespace/>
+ <label>
+ Alias
+ @if(aliasExists) {
+ <p class="error">Tag with that alias already exists!</p>
+ }
+ </label>
+ <input type="text" @bind=tagAlias/>
+ <ButtonContainer>
+ <button @onclick=Hide class="secondary">Cancel</button>
+ <button @onclick=Submit>@(TagDefinition is null ? "Create" : "Apply")</button>
+ </ButtonContainer>
+</Dialog>
+
+@code {
+ [Parameter]
+ public TagDefinition? TagDefinition { get; set; }
+
+ [Parameter]
+ public EventHandler OnTagUpdate { get; set; }
+
+ public bool Visible {
+ get => visible;
+ set {
+ if(value)
+ Load();
+ visible = dialog.Visible = value;
+ }
+ }
+
+ private string Title =>
+ TagDefinition is null ? "Create a new tag definition" : "Edit tag definition";
+
+ private Dialog dialog;
+
+ private string? tagName;
+ private string? tagNamespace;
+ private string? tagAlias;
+
+ private bool nameExists = false;
+ private bool aliasExists = false;
+
+ private bool visible = false;
+
+ public void Show() => Visible = true;
+ public void Hide() => Visible = false;
+
+ public void Show(TagDefinition? toEdit) {
+ TagDefinition = toEdit;
+ Visible = true;
+ }
+
+ public void Show(string? @namespace) {
+ TagDefinition = null;
+ Visible = true;
+ tagNamespace = @namespace;
+ }
+
+ private void Load() {
+ tagName = TagDefinition?.Name;
+ tagNamespace = TagDefinition?.Namespace;
+ tagAlias = TagDefinition?.Alias;
+ nameExists = false;
+ aliasExists = false;
+ }
+
+ private void Submit() {
+ try {
+ if(TagDefinition is null) {
+ tagService.CreateTagDefinition(tagName, tagNamespace, tagAlias);
+ } else {
+ tagService.UpdateTagDefinition(TagDefinition, tagName, tagNamespace, tagAlias);
+ }
+ } catch(TagDuplicateException e) {
+ nameExists = e.NameExists;
+ aliasExists = e.AliasExists;
+ return;
+ }
+
+ OnTagUpdate.Invoke(this, new EventArgs());
+ Hide();
+ }
+}
diff --git a/Pages/Component/TagEditDialog.razor.css b/Pages/Component/TagEditDialog.razor.css
new file mode 100644
index 0000000..02781c0
--- /dev/null
+++ b/Pages/Component/TagEditDialog.razor.css
@@ -0,0 +1,11 @@
+p.error {
+ color: var(--col-error-pri);
+ display: inline;
+ font-size: 8pt;
+ margin-left: 5px;
+ vertical-align: middle;
+}
+
+input {
+ width: 100%;
+}
diff --git a/Pages/Component/TagSelectDialog.razor b/Pages/Component/TagSelectDialog.razor
index 916a070..88e1471 100644
--- a/Pages/Component/TagSelectDialog.razor
+++ b/Pages/Component/TagSelectDialog.razor
@@ -2,6 +2,7 @@
@inject ITagService tagService
@inject IUserService userService
@implements IDisposable
+@implements IDialog
<link rel="stylesheet" href="@(nameof(HyperBooru)).styles.css"/>
@@ -36,11 +37,11 @@
</Dialog>
@code {
- [Parameter]
- public string? Title { get; set; }
+ [Parameter]
+ public string? Title { get; set; }
- [Parameter]
- public EventCallback<TagDefinition[]> OnSubmit { get; set; }
+ [Parameter]
+ public EventCallback<TagDefinition[]> OnSubmit { get; set; }
public TagDefinition[] SelectedTags { get; set; } =
Array.Empty<TagDefinition>();