diff options
Diffstat (limited to 'Pages/Component')
| -rw-r--r-- | Pages/Component/NsfwSwitch.razor | 8 | ||||
| -rw-r--r-- | Pages/Component/Switch.razor | 5 | ||||
| -rw-r--r-- | Pages/Component/TagSelectDialog.razor | 18 |
3 files changed, 30 insertions, 1 deletions
diff --git a/Pages/Component/NsfwSwitch.razor b/Pages/Component/NsfwSwitch.razor new file mode 100644 index 0000000..d4e809b --- /dev/null +++ b/Pages/Component/NsfwSwitch.razor @@ -0,0 +1,8 @@ +@inject IUserStateService userState + +<Switch InitialValue=userState.ShowNsfw OnToggle=ToggleNsfw/> + +@code { + private void ToggleNsfw(bool showNsfw) => + userState.ShowNsfw = showNsfw; +}
\ No newline at end of file diff --git a/Pages/Component/Switch.razor b/Pages/Component/Switch.razor index ffb3543..d11ac81 100644 --- a/Pages/Component/Switch.razor +++ b/Pages/Component/Switch.razor @@ -3,6 +3,7 @@ <label> <input type="checkbox" + checked=@InitialValue @onchange=@(e => OnToggle.InvokeAsync((e.Value as bool?) ?? false)) hidden/> <div class="switch-outer"> @@ -11,5 +12,9 @@ </label> @code { + [Parameter] + public bool InitialValue { get; set; } = false; + + [Parameter] public EventCallback<bool> OnToggle { get; set; } } diff --git a/Pages/Component/TagSelectDialog.razor b/Pages/Component/TagSelectDialog.razor index d9e297a..94693e5 100644 --- a/Pages/Component/TagSelectDialog.razor +++ b/Pages/Component/TagSelectDialog.razor @@ -1,4 +1,6 @@ @inject IDbContextFactory<HBContext> dbFactory +@inject ITagService tagService +@inject IUserStateService userState @implements IDisposable <link rel="stylesheet" href="@(nameof(HyperBooru)).styles.css"/> @@ -53,7 +55,10 @@ public void Show() => Visible = true; public void Hide() => Visible = false; - protected override void OnInitialized() => LoadTags(); + protected override void OnInitialized() { + userState.ShowNsfwChanged += ShowNsfwChanged; + LoadTags(); + } private void LoadTags() { db = dbFactory.CreateDbContext(); @@ -63,6 +68,11 @@ tagDefinitions = db.TagDefinitions .Where(td => td.Source == TagSource.UserTag) .OrderBy(td => td.Name) + .AsEnumerable() + .Where(td => userState.ShowNsfw || !tagService + .GetAllTags(td) + .Select(e => e.tagDefinition.Guid) + .Contains(HBContext.NsfwTag)) .Select(td => new Tuple<TagDefinition, bool>( td, selected.Contains(td.Guid)).ToValueTuple()) @@ -81,5 +91,11 @@ StateHasChanged(); } + public async void ShowNsfwChanged(object? sender, bool showNsfw) => + await InvokeAsync(() => { + LoadTags(); + StateHasChanged(); + }); + public void Dispose() => db.Dispose(); } |
