summaryrefslogtreecommitdiff
path: root/Pages/Component
diff options
context:
space:
mode:
Diffstat (limited to 'Pages/Component')
-rw-r--r--Pages/Component/AboutDialog.razor26
-rw-r--r--Pages/Component/MediaTagTable.razor39
-rw-r--r--Pages/Component/NsfwSwitch.razor8
-rw-r--r--Pages/Component/Switch.razor4
-rw-r--r--Pages/Component/TagEditDialog.razor10
-rw-r--r--Pages/Component/TagSelectDialog.razor103
-rw-r--r--Pages/Component/Titlebar.razor93
7 files changed, 151 insertions, 132 deletions
diff --git a/Pages/Component/AboutDialog.razor b/Pages/Component/AboutDialog.razor
index 1229dc7..fa7b1ca 100644
--- a/Pages/Component/AboutDialog.razor
+++ b/Pages/Component/AboutDialog.razor
@@ -1,7 +1,9 @@
@using System.Reflection
-@using Microsoft.AspNetCore.Hosting
-@inject IDbContextFactory<HBContext> dbFactory
-@inject IHostingEnvironment hostingEnvironment
+@*
+ * @using Microsoft.AspNetCore.Hosting
+ * @inject IDbContextFactory<HBContext> dbFactory
+ * @inject IHostingEnvironment hostingEnvironment
+ *@
@implements IDialog
<Dialog @ref=dialog>
@@ -699,15 +701,15 @@
set {
dialog.Visible = value;
if(value) {
- using var db = dbFactory.CreateDbContext();
- progress = (
- Untagged: db.Media
- .Where(m => m.Tags.Any(t => t.TagDefinition.ObjectId == (int) HBObjectId.IngestTag))
- .Count(),
- Total: db.Media.Count()
- );
- progressBar.Progress = (float) progress.Value!.Untagged / (float) progress.Value!.Total;
- InvokeAsync(() => StateHasChanged());
+ // using var db = dbFactory.CreateDbContext();
+ // progress = (
+ // Untagged: db.Media
+ // .Where(m => m.Tags.Any(t => t.TagDefinition.ObjectId == (int) HBObjectId.IngestTag))
+ // .Count(),
+ // Total: db.Media.Count()
+ // );
+ // progressBar.Progress = (float) progress.Value!.Untagged / (float) progress.Value!.Total;
+ // InvokeAsync(() => StateHasChanged());
}
}
}
diff --git a/Pages/Component/MediaTagTable.razor b/Pages/Component/MediaTagTable.razor
index 1b62832..0524739 100644
--- a/Pages/Component/MediaTagTable.razor
+++ b/Pages/Component/MediaTagTable.razor
@@ -1,7 +1,4 @@
-@inject IDbContextFactory<HBContext> dbFactory
-@inject ITagService tagService
-
-<link rel="stylesheet" href="@(nameof(HyperBooru)).styles.css"/>
+@inject HBSession hb
<table class="data-table">
<tr>
@@ -19,7 +16,7 @@
}
</td>
<td>
- <a href="/Gallery?t=@(e.tagDef.Guid)" class="nondecorated">
+ <a href="/Gallery?t=@(e.tagDef.TagDefinitionId)" class="nondecorated">
@if(e.isImplicit) {
<i>@e.tagDef.Name</i>
} else {
@@ -40,33 +37,39 @@
@code {
[Parameter]
- public Media Media { get; set; }
+ public Guid MediaId { get; set; }
- private (TagDefinition tagDef, bool isImplicit)[] tagDefs;
+ private (TagDefinition tagDef, bool isImplicit)[] tagDefs = [];
protected override void OnInitialized() => LoadTagDefs();
public void Refresh() {
LoadTagDefs();
- StateHasChanged();
+ // StateHasChanged();
}
private void Delete(TagDefinition tagDef) {
- tagService.RemoveTag(Media.Guid, tagDef.Guid);
- Refresh();
+ // tagService.RemoveTag(Media.Guid, tagDef.Guid);
+ // Refresh();
}
- private void LoadTagDefs() {
- using var db = dbFactory.CreateDbContext();
- var media = db.Media.First(m => m.ObjectId == Media.ObjectId);
+ private async void LoadTagDefs() {
+ var tags = await hb.Media.GetTagsAsync(MediaId);
+
+ tagDefs = tags.Select(td => (tagDef: td, isImplicit: false)).ToArray();
+
+ await InvokeAsync(() => StateHasChanged());
+
+ // using var db = dbFactory.CreateDbContext();
+ // var media = db.Media.First(m => m.ObjectId == Media.ObjectId);
- tagDefs = tagService.GetAllTags(Media)
- .Where(e => e.tagDefinition.Source == ApiModels.TagSource.UserTag)
- .ToArray();
+ // tagDefs = tagService.GetAllTags(Media)
+ // .Where(e => e.tagDefinition.Source == TagSource.UserTag)
+ // .ToArray();
}
private void MakeExplicit(TagDefinition tagDef) {
- tagService.AddTag(Media, tagDef);
- Refresh();
+ // tagService.AddTag(Media, tagDef);
+ // Refresh();
}
}
diff --git a/Pages/Component/NsfwSwitch.razor b/Pages/Component/NsfwSwitch.razor
index b96606d..f4f9c1f 100644
--- a/Pages/Component/NsfwSwitch.razor
+++ b/Pages/Component/NsfwSwitch.razor
@@ -1,8 +1,6 @@
-@inject IUserService userService
-
-<Switch InitialValue=userService.UserSessionState.ShowNsfw OnToggle=ToggleNsfw/>
+<Switch InitialValue=false OnToggle=ToggleNsfw/>
@code {
- private void ToggleNsfw(bool showNsfw) =>
- userService.UserSessionState.ShowNsfw = showNsfw;
+ private void ToggleNsfw(bool showNsfw) => _ = 0;
+ // userService.UserSessionState.ShowNsfw = showNsfw;
} \ No newline at end of file
diff --git a/Pages/Component/Switch.razor b/Pages/Component/Switch.razor
index d11ac81..5264094 100644
--- a/Pages/Component/Switch.razor
+++ b/Pages/Component/Switch.razor
@@ -1,6 +1,4 @@
-<link rel="stylesheet" href="@(nameof(HyperBooru)).styles.css"/>
-
-<label>
+<label>
<input
type="checkbox"
checked=@InitialValue
diff --git a/Pages/Component/TagEditDialog.razor b/Pages/Component/TagEditDialog.razor
index afa312e..14d8c27 100644
--- a/Pages/Component/TagEditDialog.razor
+++ b/Pages/Component/TagEditDialog.razor
@@ -1,5 +1,7 @@
-@inject IDbContextFactory<HBContext> dbFactory;
-@inject ITagService tagService
+@*
+ * @inject IDbContextFactory<HBContext> dbFactory;
+ * @inject ITagService tagService
+ *@
@implements IDialog
<Dialog Title=@Title @ref=dialog>
@@ -80,9 +82,9 @@
private void Submit() {
try {
if(TagDefinition is null) {
- tagService.CreateTagDefinition(tagName, tagNamespace, tagAlias);
+ // tagService.CreateTagDefinition(tagName, tagNamespace, tagAlias);
} else {
- tagService.UpdateTagDefinition(TagDefinition, tagName, tagNamespace, tagAlias);
+ // tagService.UpdateTagDefinition(TagDefinition, tagName, tagNamespace, tagAlias);
}
} catch(ApiModels.TagDuplicateException e) {
nameExists = e.NameExists;
diff --git a/Pages/Component/TagSelectDialog.razor b/Pages/Component/TagSelectDialog.razor
index d33b178..99321fe 100644
--- a/Pages/Component/TagSelectDialog.razor
+++ b/Pages/Component/TagSelectDialog.razor
@@ -1,6 +1,8 @@
-@inject IDbContextFactory<HBContext> dbFactory
-@inject ITagService tagService
-@inject IUserService userService
+@*
+ * @inject IDbContextFactory<HBContext> dbFactory
+ * @inject ITagService tagService
+ * @inject IUserService userService
+ *@
@implements IDisposable
@implements IDialog
@@ -28,6 +30,7 @@
ns,
alias is not null ? $"({alias})" : null
});
+@*
<input
type="checkbox"
id="tagDef-@tagDefinitions[i].tagDefinition.Guid"
@@ -37,6 +40,7 @@
title=@title>
@tagDefinitions[i].tagDefinition.Name
</label>
+*@
}
</div>
<ButtonContainer>
@@ -67,7 +71,7 @@
private (TagDefinition tagDefinition, bool selected)[] tagDefinitions;
- private HBContext db;
+ // private HBContext db;
private Dialog dialog;
@@ -80,33 +84,33 @@
public void Hide() => Visible = false;
protected override void OnInitialized() {
- userService.UserSessionState.OnStateChange += ShowNsfwChanged;
+ // userService.UserSessionState.OnStateChange += ShowNsfwChanged;
LoadTags();
}
private void LoadTags() {
- db = dbFactory.CreateDbContext();
+ // db = dbFactory.CreateDbContext();
- var selected = SelectedTags.Select(td => td.Guid);
+ // var selected = SelectedTags.Select(td => td.Guid);
- int[] nsfwTags = Array.Empty<int>();
- if(!userService.UserSessionState.ShowNsfw)
- nsfwTags = tagService.TagsThatImply(HBContext.NsfwTag)
- .Select(td => td.ObjectId)
- .ToArray();
+ // int[] nsfwTags = Array.Empty<int>();
+ // if(!userService.UserSessionState.ShowNsfw)
+ // nsfwTags = tagService.TagsThatImply(HBContext.NsfwTag)
+ // .Select(td => td.ObjectId)
+ // .ToArray();
- tagDefinitions = db.TagDefinitions
- .Include(td => td.ImplicitTags)
- .Where(td => td.Source == ApiModels.TagSource.UserTag)
- .OrderBy(td => td.Name)
- .AsEnumerable()
- .Where(td => userService.UserSessionState.ShowNsfw || !td.ImplicitTags
- .IntersectBy(nsfwTags, td => td.ObjectId)
- .Any())
- .Select(td => new Tuple<TagDefinition, bool>(
- td,
- selected.Contains(td.Guid)).ToValueTuple())
- .ToArray();
+ // tagDefinitions = db.TagDefinitions
+ // .Include(td => td.ImplicitTags)
+ // .Where(td => td.Source == TagSource.UserTag)
+ // .OrderBy(td => td.Name)
+ // .AsEnumerable()
+ // .Where(td => userService.UserSessionState.ShowNsfw || !td.ImplicitTags
+ // .IntersectBy(nsfwTags, td => td.ObjectId)
+ // .Any())
+ // .Select(td => new Tuple<TagDefinition, bool>(
+ // td,
+ // selected.Contains(td.Guid)).ToValueTuple())
+ // .ToArray();
}
private void QueryInput(ChangeEventArgs e) {
@@ -141,30 +145,31 @@
}
private bool MatchesQuery(TagDefinition tagDef) {
- TagDefinition? singleTag = null;
+ // TagDefinition? singleTag = null;
- if(string.IsNullOrEmpty(query))
- return true;
+ // if(string.IsNullOrEmpty(query))
+ // return true;
- singleTag = tagDefinitions.FirstOrDefault(
- e => string.Equals(
- e.tagDefinition.Alias,
- query,
- StringComparison.OrdinalIgnoreCase)).tagDefinition;
+ // singleTag = tagDefinitions.FirstOrDefault(
+ // e => string.Equals(
+ // e.tagDefinition.Alias,
+ // query,
+ // StringComparison.OrdinalIgnoreCase)).tagDefinition;
- if(singleTag is not null)
- return tagDef.Guid == singleTag.Guid;
+ // if(singleTag is not null)
+ // return tagDef.Guid == singleTag.Guid;
- singleTag = tagDefinitions.FirstOrDefault(
- e => string.Equals(
- e.tagDefinition.Name,
- query,
- StringComparison.OrdinalIgnoreCase)).tagDefinition;
+ // singleTag = tagDefinitions.FirstOrDefault(
+ // e => string.Equals(
+ // e.tagDefinition.Name,
+ // query,
+ // StringComparison.OrdinalIgnoreCase)).tagDefinition;
- if(singleTag is not null)
- return tagDef.Guid == singleTag.Guid;
+ // if(singleTag is not null)
+ // return tagDef.Guid == singleTag.Guid;
- return tagDef.Name.ToLower().Contains(query.ToLower());
+ // return tagDef.Name.ToLower().Contains(query.ToLower());
+ return false;
}
private async void Submit() {
@@ -179,14 +184,14 @@
StateHasChanged();
}
- public async void ShowNsfwChanged(UserSessionState userSessionState) =>
- await InvokeAsync(() => {
- LoadTags();
- StateHasChanged();
- });
+ // public async void ShowNsfwChanged(UserSessionState userSessionState) =>
+ // await InvokeAsync(() => {
+ // LoadTags();
+ // StateHasChanged();
+ // });
public void Dispose() {
- db.Dispose();
- userService.UserSessionState.OnStateChange -= ShowNsfwChanged;
+ // db.Dispose();
+ // userService.UserSessionState.OnStateChange -= ShowNsfwChanged;
}
}
diff --git a/Pages/Component/Titlebar.razor b/Pages/Component/Titlebar.razor
index 48257b2..521fb46 100644
--- a/Pages/Component/Titlebar.razor
+++ b/Pages/Component/Titlebar.razor
@@ -1,5 +1,7 @@
@inject IJSRuntime jsRuntime
-@inject IUserService userService
+@inject NavigationManager nav
+@inject HBSession session;
+@* @inject IUserService userService *@
<script suppress-error="BL9992">
async function login() {
@@ -40,48 +42,57 @@
}
</script>
-<AuthorizeView>
- <Authorized>
- <div id="navbar">
- <p class="mobile">HyperBooru</p>
- <a class="mobile menu-button" href="javascript:toggleMobileMenu();">&#x2630</a>
+@if(!IsLoginPage) {
+ <div id="navbar">
+ <p class="mobile">HyperBooru</p>
+ <a class="mobile menu-button" href="javascript:toggleMobileMenu();">&#x2630</a>
- <a class="desktop" href="/">Home</a>
- <a class="desktop" href="/TagDefinitions">Tags</a>
- <a class="desktop" href="/Gallery?ingest=true">Ingest</a>
- <a class="desktop" href="/Upload">Upload</a>
- <a class="desktop" href="javascript:;" @onclick=@(() => aboutDialog.Show())>About</a>
+ <a class="desktop" href="/">Home</a>
+ <a class="desktop" href="/TagDefinitions">Tags</a>
+ <a class="desktop" href="/Gallery?ingest=true">Ingest</a>
+ <a class="desktop" href="/Upload">Upload</a>
+ @* <a class="desktop" href="javascript:;" @onclick=@(() => aboutDialog.Show())>About</a> *@
+ <a class="desktop" href="javascript:;">About</a>
- <p class="desktop" id="nsfw-label">NSFW</p>
- <div id="nsfw-switch" class="desktop">
- <NsfwSwitch/>
- </div>
- <form action="/Gallery" method="get" class="desktop">
- <input type="text" name="q" placeholder="Search"/>
- </form>
- <a class="desktop" href="javascript:logout();">Logout</a>
- </div>
- <AboutDialog @ref=aboutDialog/>
- </Authorized>
- <NotAuthorized>
- <div id="navbar">
- <h2>Login</h2>
- <form class="login" action="javascript:login();">
- <input
- id="username"
- placeholder="Username"
- type="text"
- autocorrect="off"
- autocapitalize="off"
- autocomplete="off"
- autofocus/>
- <input id="password" placeholder="Password" type="password"/>
- </form>
- <a href="javascript:login();">Login</a>
- </div>
- </NotAuthorized>
-</AuthorizeView>
+ <p class="desktop" id="nsfw-label">NSFW</p>
+ <div id="nsfw-switch" class="desktop">
+ <NsfwSwitch/>
+ </div>
+ <form action="/Gallery" method="get" class="desktop">
+ <input type="text" name="q" placeholder="Search"/>
+ </form>
+ <a class="desktop" href="javascript:logout();">Logout</a>
+ </div>
+ @* <AboutDialog @ref=aboutDialog/> *@
+} else {
+ <div id="navbar">
+ <h2>Login</h2>
+ <form class="login" action="javascript:login();">
+ <input
+ id="username"
+ placeholder="Username"
+ type="text"
+ autocorrect="off"
+ autocapitalize="off"
+ autocomplete="off"
+ autofocus
+ @bind=Username/>
+ <input id="password" placeholder="Password" type="password" @bind=Password/>
+ </form>
+ <a @onclick=Login>Login</a>
+ </div>
+}
@code {
- private AboutDialog aboutDialog;
+ // private AboutDialog aboutDialog;
+
+ public string Username { get; set; } = "";
+ public string Password { get; set; } = "";
+
+ private bool IsLoginPage =>
+ new Uri(nav.Uri).AbsolutePath.Equals("/Login", StringComparison.OrdinalIgnoreCase);
+
+ private async void Login() {
+ await session.LoginAsync(Username, Password);
+ }
}