summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Pages/Component/Dialog.razor39
-rw-r--r--Program.cs1
-rw-r--r--Services/DialogService.cs39
3 files changed, 75 insertions, 4 deletions
diff --git a/Pages/Component/Dialog.razor b/Pages/Component/Dialog.razor
index f479368..e71ddc6 100644
--- a/Pages/Component/Dialog.razor
+++ b/Pages/Component/Dialog.razor
@@ -1,6 +1,8 @@
-@implements IDialog
+@inject IDialogService dialogService
+@implements IDialog
+@implements IDisposable
-<div style="@(heightStyle + visiblilityStyle)">
+<div @onclick=Bump style="@(style)">
@if(Title is not null) {
<p>@Title</p>
<hr/>
@@ -24,20 +26,49 @@
get => visible;
set {
visible = value;
+ if(value)
+ Bump();
StateHasChanged();
}
}
- public void Show() => Visible = true;
- public void Hide() => Visible = false;
+ public int? ZIndex {
+ get => zIndex;
+ set {
+ zIndex = value;
+ StateHasChanged();
+ }
+ }
private bool visible = false;
+ private int? zIndex;
+
private string? height;
+ protected override void OnInitialized() =>
+ dialogService.Register(this);
+
+ public void Show() => Visible = true;
+ public void Hide() => Visible = false;
+
+ private void Bump() =>
+ dialogService.BumpZIndex(this);
+
+ private string style =>
+ zIndexStyle +
+ heightStyle +
+ visiblilityStyle;
+
+ private string zIndexStyle =>
+ zIndex is null ? "display:none;" : $"z-index:{zIndex};";
+
private string heightStyle =>
$"{(height is null ? "" : $"max-height:{height};")}";
private string visiblilityStyle =>
Visible ? "opacity:1;visibility:visible;" : "opacity:0;visibility:hidden;";
+
+ public void Dispose() =>
+ dialogService.Unregister(this);
}
diff --git a/Program.cs b/Program.cs
index 564ab30..494a808 100644
--- a/Program.cs
+++ b/Program.cs
@@ -21,6 +21,7 @@ public class Program {
builder.Services.AddScoped<ITagService, TagService>();
builder.Services.AddScoped<IMediaService, MediaService>();
builder.Services.AddSingleton<IUserService, UserService>();
+ builder.Services.AddScoped<IDialogService, DialogService>();
builder.Services.AddHostedService<OcrService>();
var app = builder.Build();
diff --git a/Services/DialogService.cs b/Services/DialogService.cs
new file mode 100644
index 0000000..5967d95
--- /dev/null
+++ b/Services/DialogService.cs
@@ -0,0 +1,39 @@
+using HyperBooru.Pages.Component;
+
+namespace HyperBooru.Services;
+
+public interface IDialogService {
+ public void Register(Dialog dialog);
+ public void Unregister(Dialog dialog);
+ public void BumpZIndex(Dialog dialog);
+}
+
+public class DialogService : IDialogService {
+ private const int MinZLevel = 900;
+
+ private List<Dialog> dialogs = new();
+
+ public void Register(Dialog dialog) {
+ if(!dialogs.Contains(dialog))
+ dialogs.Add(dialog);
+
+ dialog.ZIndex = dialogs.Count() - 1 + MinZLevel;
+ }
+
+ public void Unregister(Dialog dialog) {
+ dialogs.Remove(dialog);
+ for(int i = 0; i < dialogs.Count(); i++)
+ dialogs[i].ZIndex = i + MinZLevel;
+ }
+
+ public void BumpZIndex(Dialog dialog) {
+ if(!dialogs.Contains(dialog))
+ return;
+
+ dialogs.Remove(dialog);
+ dialogs.Add(dialog);
+
+ for(int i = 0; i < dialogs.Count(); i++)
+ dialogs[i].ZIndex = i + MinZLevel;
+ }
+} \ No newline at end of file