Skip to content

Commit

Permalink
The most significant changes in the code involve the addition of cond…
Browse files Browse the repository at this point in the history
…itions in the `Index.razor` file. These conditions check the number of favorites and the last image in the history. The code has also been restructured and reformatted for better readability.

1. Code formatting and restructuring: The code in the `Index.razor` file has been re-indented and some lines have been moved around to improve readability and structure.

2. Addition of condition for favorites: A condition has been added to check if the number of favorites is greater than or equal to 3. Depending on the result, the favorites are displayed in three columns or without chunking.

3. Reformatted `clipboardSupported` check: The check for `clipboardSupported` has been reformatted to improve readability.

4. Addition of condition for image history: In the function that handles image history, a condition has been added to check if the last image in the history is the same as the current image. Depending on the result, the current image is set to `PreloadImageUrl1`.

5. Handling of image history: In the function that handles image history, the current image is set to the previous image in the history if it exists.

6. Removal of unnecessary code: Some unnecessary lines of code have been removed.
  • Loading branch information
SCJA03 committed Mar 21, 2024
1 parent 7125ddb commit bfae67d
Showing 1 changed file with 42 additions and 32 deletions.
74 changes: 42 additions & 32 deletions Nekos/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
<img class="img-fluid" src="@ImageUrl" style="box-shadow: 0px 0px 15px 10px; @(mobile ? "max-height: 100vh;" : "height: 100vh;")">

<!-- Start: Preload iamges -->
<img src="@PreloadImageUrl1" style="width: 0;">
<img src="@PreloadImageUrl1" style="width: 0;">
<img src="@PreloadImageUrl2" style="width: 0;">
<!-- End: Preload iamges -->
</div>
</div>
<!-- Start: Footer Dark -->
<footer class="footer-dark">
<div class="container">
<div class="row">
<!-- Start: Social Icons -->
<div class="col item social"><a href="https://github.com/MarkenJaden/Nekos" target="_blank"><i class="icon ion-social-github"></i></a></div><!-- End: Social Icons -->
</div><!-- Start: Copyright -->
<p class="copyright">MarkenJaden | Nekos © @DateTime.Now.Year -&nbsp;I do not own or save any of the images displayed.</p><!-- End: Copyright -->
</div>
<div class="col item social"><a href="https://github.com/MarkenJaden/Nekos" target="_blank"><i class="icon ion-social-github"></i></a></div><!-- End: Social Icons -->
</div><!-- Start: Copyright -->
<p class="copyright">MarkenJaden | Nekos © @DateTime.Now.Year -&nbsp;I do not own or save any of the images displayed.</p><!-- End: Copyright -->
</div>
</footer>
<!-- End: Footer Dark -->
<nav class="navbar navbar-light navbar-expand fixed-bottom">
Expand All @@ -37,7 +37,7 @@
<button class="btn btn-outline-light btn-lg border rounded-circle mt-auto" type="button" style="margin-right: 10px; height: 56.5px;" @onclick="ToggleFavoriteView"><i class="fas fa-images"></i></button>
}
<button class="btn btn-outline-@(favorites.Contains(ImageUrl) ? "warning" : "light") btn-lg border rounded-circle mt-auto" type="button" style="height: 56.5px;" @onclick="ToggleFavorite"><i class="fa fa-star"></i></button>
@if(clipboardSupported)
@if (clipboardSupported)
{
<button class="btn btn-outline-light btn-lg border rounded-circle mt-auto" type="button" style="margin-left: 10px; height: 56.5px;" @onclick="async () => { await clipboard.WriteTextAsync(ImageUrl); await _message.Success(copied + await GetAsciiNeko()); }"><i class="far fa-copy"></i></button>
}
Expand All @@ -54,41 +54,51 @@
{
<div id="content-wrapper" style="min-height: 100vh;height: auto;">
<!-- Start: 1 Row 3 Columns -->
<div class="container">
<div class="container">
<div class="row justify-content-center">
@{
var chunks = favorites.Chunk(favorites.Count / 3).ToArray();
<div class="col">
@foreach (var img in chunks[0])
{
<a href="" @onclick="() => { ImageUrl = img; HistoryToFavorite(); ToggleFavoriteView(); }"><img class="img-fluid" src="@img" style="box-shadow: 0px 0px 15px 10px; max-height: 100vh;"></a>
}
</div>
<div class="col">
@foreach (var img in chunks[1])
{
<a href="" @onclick="() => { ImageUrl = img; HistoryToFavorite(); ToggleFavoriteView(); }"><img class="img-fluid" src="@img" style="box-shadow: 0px 0px 15px 10px; max-height: 100vh;"></a>
}
</div>
<div class="col">
@foreach (var img in chunks[2])
if (favorites.Count >= 3)

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

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
{
var chunks = favorites.Chunk(favorites.Count / 3).ToArray();
<div class="col">
@foreach (var img in chunks[0])
{
<a href="" @onclick="() => { ImageUrl = img; HistoryToFavorite(); ToggleFavoriteView(); }"><img class="img-fluid" src="@img" style="box-shadow: 0px 0px 15px 10px; max-height: 100vh;"></a>

Check warning on line 66 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 66 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>
<div class="col">
@foreach (var img in chunks[1])
{
<a href="" @onclick="() => { ImageUrl = img; HistoryToFavorite(); ToggleFavoriteView(); }"><img class="img-fluid" src="@img" style="box-shadow: 0px 0px 15px 10px; max-height: 100vh;"></a>

Check warning on line 72 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 72 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>
<div class="col">
@foreach (var img in chunks[2])
{
<a href="" @onclick="() => { ImageUrl = img; HistoryToFavorite(); ToggleFavoriteView(); }"><img class="img-fluid" src="@img" style="box-shadow: 0px 0px 15px 10px; max-height: 100vh;"></a>

Check warning on line 78 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>
}
else
{
@foreach (var img in favorites)
{
<a href="" @onclick="() => { ImageUrl = img; HistoryToFavorite(); ToggleFavoriteView(); }"><img class="img-fluid" src="@img" style="box-shadow: 0px 0px 15px 10px; max-height: 100vh;"></a>

Check warning on line 86 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>
}
}
</div>
</div><!-- End: 1 Row 3 Columns -->
</div>
</div>
<!-- Start: Footer Dark -->
<footer class="footer-dark">
<div class="container">
<div class="row">
<!-- Start: Social Icons -->
<div class="col item social"><a href="https://github.com/MarkenJaden/Nekos" target="_blank"><i class="icon ion-social-github"></i></a></div><!-- End: Social Icons -->
</div><!-- Start: Copyright -->
<p class="copyright">MarkenJaden | Nekos © @DateTime.Now.Year -&nbsp;I do not own or save any of the images displayed. Favorites are saved as link as cookie in local storage. API used: https://nekosapi.com/</p><!-- End: Copyright -->
</div>
<div class="col item social"><a href="https://github.com/MarkenJaden/Nekos" target="_blank"><i class="icon ion-social-github"></i></a></div><!-- End: Social Icons -->
</div><!-- Start: Copyright -->
<p class="copyright">MarkenJaden | Nekos © @DateTime.Now.Year -&nbsp;I do not own or save any of the images displayed. Favorites are saved as link as cookie in local storage. API used: https://nekosapi.com/</p><!-- End: Copyright -->
</div>
</footer>
<!-- End: Footer Dark -->
<nav class="navbar navbar-light navbar-expand fixed-bottom">
Expand Down Expand Up @@ -165,7 +175,7 @@
isDevice = mobile ? "Mobile" : "Desktop";

StateHasChanged();

var images = await NekoClient.ImagesAsync(rating: ["explicit"], tag: [8], limit: 3);
ImageUrl = images.Items.ElementAt(0).Image_url;
PreloadImageUrl1 = images.Items.ElementAt(1).Image_url;
Expand Down Expand Up @@ -210,7 +220,7 @@
await _message.Error("Something went wrong! Try again later. It will probably take a few hours.");
return;
}

if (History.Last!.Value.Equals(ImageUrl))
{
ImageUrl = PreloadImageUrl1;
Expand All @@ -237,7 +247,7 @@
await _message.Error("Something went wrong! Try again later. It will probably take a few hours.");
return;
}

var linkedListNode = History.Find(ImageUrl)!.Previous;
if (linkedListNode != null) ImageUrl = linkedListNode.Value;
}
Expand Down

0 comments on commit bfae67d

Please sign in to comment.