Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement image filtering by tags #2

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions Nekos/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
{
<button class="btn btn-outline-light btn-lg border rounded-circle mt-auto" type="button" style="margin-left: 10px; height: 56.5px;" @onclick="async () => { if (Image != null) await Clipboard.WriteTextAsync(Image.Value.Image_url); await Message.Success(Copied + await GetAsciiNeko()); }"><i class="far fa-copy"></i></button>
}
<button class="btn btn-outline-light btn-lg border rounded-circle mt-auto" type="button" style="margin-left: 10px; height: 56.5px;" @onclick="ToggleTagFilterMenu"><i class="fas fa-filter"></i></button>
</div>
</div>
@if (!Mobile && !_keyBoardUsed)
Expand All @@ -55,7 +56,7 @@
<div class="col">
@foreach (var img in chunk)
{
<a href="" @onclick="() => { HistoryToFavorite(img); ToggleFavoriteView(); }"><img class="img-fluid" src="@img.Image_url" style="box-shadow: 0px 0px 15px 10px; max-height: 100vh;"></a>

Check warning on line 59 in Nekos/Pages/Index.razor

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 59 in Nekos/Pages/Index.razor

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 59 in Nekos/Pages/Index.razor

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 59 in Nekos/Pages/Index.razor

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}
</div>
}
Expand Down Expand Up @@ -104,6 +105,7 @@
public LinkedListNode<ImageSchema>? PreloadImageUrl2;

private readonly RandomNekoClient _nekoClient = new(new HttpClient());
private readonly ApiNekoClient _apiClient = new(new HttpClient());

private readonly LinkedList<ImageSchema> _images = [];

Expand Down Expand Up @@ -135,6 +137,16 @@

private JsConsole _console = null!;

private bool _showTagFilterMenu;

private List<int> _selectedTags = new();

private PagedTagSchema _availableTags = new();

protected override async Task OnInitializedAsync()
{
_availableTags = await _apiClient.TagsAsync();
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
Expand Down Expand Up @@ -191,7 +203,7 @@
private async Task LoadImages()
{
await _console.LogAsync("Loading new images in queue...");
var images = await _nekoClient.ImagesAsync(rating: ["explicit"], tag: [8], is_screenshot:false);
var images = await _nekoClient.ImagesAsync(rating: ["explicit"], tag: _selectedTags, is_screenshot:false);
foreach (var image in images.Items) if (!_images.Any(x => x.Id.Equals(image.Id))) _images.AddLast(image);
await _console.LogAsync($"Image loading finished. Total images in list: {_images.Count}");
}
Expand All @@ -202,7 +214,7 @@
/// <param name="e">The keyboard event arguments.</param>
protected void KeyDown(KeyboardEventArgs e)
{
if (_showFavorites) return;
if (_showFavorites || _showTagFilterMenu) return;
switch (e.Key)
{
case "ArrowRight":
Expand Down Expand Up @@ -253,19 +265,25 @@
await LoadImages();
}

private void ToggleTagFilterMenu()
{
_showTagFilterMenu = !_showTagFilterMenu;
StateHasChanged();
}

//Swipe event
(TouchPoint ReferencePoint, DateTime StartTime) _startPoint;

void HandleTouchStart(TouchEventArgs t)
{
if (_showFavorites) return;
if (_showFavorites || _showTagFilterMenu) return;
_startPoint.ReferencePoint = t.TargetTouches[0];
_startPoint.StartTime = DateTime.Now;
}

void HandleTouchEnd(TouchEventArgs t)
{
if (_showFavorites) return;
if (_showFavorites || _showTagFilterMenu) return;
const double swipeThreshold = 0.4;
try
{
Expand Down
45 changes: 45 additions & 0 deletions Nekos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Nekos
[![Deploy to Server](https://github.com/MarkenJaden/Nekos/actions/workflows/deploy.yml/badge.svg)](https://github.com/MarkenJaden/Nekos/actions/workflows/deploy.yml)
[![CodeFactor](https://www.codefactor.io/repository/github/markenjaden/nekos.lol/badge)](https://www.codefactor.io/repository/github/markenjaden/nekos.lol)
[![wakatime](https://wakatime.com/badge/user/17f322c9-222a-48b4-9e15-983c41f7aed4/project/d3a3b200-4514-4fa7-a958-9f5914af1406.svg)](https://wakatime.com/badge/user/17f322c9-222a-48b4-9e15-983c41f7aed4/project/d3a3b200-4514-4fa7-a958-9f5914af1406)

#### https://nekos.lol/
Website providing you with random lewd nsfw neko pics using [NekosAPI.NET](https://github.com/MarkenJaden/NekosAPI.NET)

## Developement

#### I appreciate any contribution to the website! If you have an idea, implement it or ask me to do it! ^^

This website was created using [Blazor Server](https://dotnet.microsoft.com/en-us/apps/aspnet/web-apps/blazor) in [.NET 8](https://dotnet.microsoft.com/en-us/download/dotnet/8.0).

### Libraries used
* [NekosAPI.NET](https://github.com/MarkenJaden/NekosAPI.NET)
* [Blazored.LocalStorage](https://github.com/Blazored/LocalStorage)
* [CurrieTechnologies.Razor.Clipboard](https://github.com/Basaingeal/Razor.Clipboard)
* [AntDesign](https://github.com/ant-design-blazor/ant-design-blazor)

### For the development you need
* [.NET IDE](https://dotnet.microsoft.com/en-us/platform/tools)
* [.NET 8.0](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)

Clone the repo into your IDE. Make sure that all libraries are downloaded. Now you should already be able to start the website locally.

All the logic is done in [Index.razor](https://github.com/MarkenJaden/Nekos/blob/master/Nekos/Pages/Index.razor) and is not very complicated.

The rest of the application you don't really need to pay attention to, unless you want to add a bigger feature, but with such ambition I assume you have the necessary knowledge.

Once you're happy with your change you can just open a pull request, I'll take a quick look over it, and thanks to GitHub Actions your changes are live on the website just a few minutes later, it's really not hard :)

**If there are any questions you can always reach me via Discord (MarkenJaden#7787) ^^**

## Using the Tag Filtering Feature

The website now includes a feature that allows users to filter images by tags. This feature is accessible through a menu where users can select multiple tags to refine the images displayed. The tags available for selection are fetched using the `TagsAsync()` method from `NekosAPI.NET`, ensuring that users have access to a comprehensive list of tags to choose from.

To use the tag filtering feature, simply click on the tag menu, browse through the list of available tags, and select the ones you wish to apply. You can select multiple tags by clicking on more than one tag. The images displayed on the page will automatically update to only show those that match the selected tags. To clear the selection and view all images again, simply deselect the tags from the menu.

This feature enhances the user experience by providing a more tailored browsing experience, allowing users to easily find images that match their specific interests.

## Legal

I **do not** own or save any of the images displayed. All images are retrieved and displayed using the [Nekos.Fun API](https://nekos.fun/).
Loading