Skip to content

Commit

Permalink
Merge pull request #14 from DrNoLife/mediadisplay-rework-and-tag-incl…
Browse files Browse the repository at this point in the history
…using

Changed the media display, and added some tags for the doomscroll
  • Loading branch information
DrNoLife authored Feb 8, 2024
2 parents e30cc39 + 634fbf1 commit 2bcb0dc
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 114 deletions.
79 changes: 79 additions & 0 deletions Danbooru/Danbooru.UI/Danbooru.UI/Components/MediaComponent.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@using Danbooru.ApiWrapper.Models
@using Danbooru.UI.Interfaces

<div class="media-result @(DoomScrollService.PostOfInterest?.Id == MediaPost.Id ? "focused-post" : String.Empty)">
@if (!MediaPost.IsImage)
{
<div class="meta-data">
@{
string duration = MediaPost.MediaAsset?.Duration?.ToString() ?? "0";
double durationInTime = Convert.ToDouble(duration, System.Globalization.CultureInfo.InvariantCulture);
double durationInTimeRounded = Math.Round(durationInTime, 2);
}
<p>@durationInTimeRounded seconds</p>
<p>@MediaPost.FileExt</p>
</div>

<video
controls="controls"
src="@_mediaUrl"
loop="loop"
poster="@MediaPost.PreviewFileUrl">
</video>
}
else
{
<img
style="background-image: url(@MediaPost.PreviewFileUrl);"
src="@_mediaUrl"
alt="@(MediaPost.TagsCharacter.Count > 0 ? MediaPost.TagsCharacter.First() : "Image!")" />
}

<div class="tag-display-toggle-container" @onclick=ToggleTagDisplay>
<p>?</p>
</div>
</div>

@code {
[Inject]
public IDoomScrollService DoomScrollService { get; set; } = null!;

[Parameter]
public Post MediaPost { get; set; } = null!;

private string _mediaUrl = String.Empty;

protected override void OnInitialized()
{
GetMediaUrl();
}

private void GetMediaUrl()
{
string largeFileUrl = MediaPost.LargeFileUrl;
if (!String.IsNullOrEmpty(largeFileUrl))
{
_mediaUrl = largeFileUrl;
return;
}

string fileUrl = MediaPost.FileUrl;
if (!String.IsNullOrEmpty(fileUrl))
{
_mediaUrl = fileUrl;
return;
}

string previewUrl = MediaPost.PreviewFileUrl;
if (!String.IsNullOrEmpty(previewUrl))
{
_mediaUrl = previewUrl;
return;
}
}

private void ToggleTagDisplay(MouseEventArgs e)
{
DoomScrollService.ToggleTagDisplay(MediaPost);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

.media-result {
position: relative;
}

.media-result img,
.media-result video {
max-width: 100%;
width: 100%;
}

.meta-data {
position: absolute;
top: 0;
right: 0;
display: flex;
gap: 10px;
padding: 5px;
background-color: rgba(0, 0, 0, 0.75);
}

.tag-display-toggle-container {
position: absolute;
top: 5px;
left: 5px;
background-color: rgba(0, 0, 0, 0.75);
padding: 15px;
cursor: pointer;
display: flex;
justify-content: center;
align-content: center;
text-align: center;
border-radius: 10px;
font-weight: bold;
}

.focused-post {
border: 1px solid var(--accent);
}
31 changes: 8 additions & 23 deletions Danbooru/Danbooru.UI/Danbooru.UI/Components/Pages/DoomScroll.razor
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,19 @@
<section class="search-results-container">
<div class="results">
<InfiniteScroll ObserverTargetId="observerTarget" ObservableTargetReached="(e) => FetchImages()">
@foreach (var post in _posts)

@foreach (Post post in _posts)
{
<div class="media-result">
@if (!post.IsImage)
{
<div class="meta-data">
@{
string duration = post.MediaAsset?.Duration?.ToString() ?? "0";
double durationInTime = Convert.ToDouble(duration, System.Globalization.CultureInfo.InvariantCulture);
double durationInTimeRounded = Math.Round(durationInTime, 2);
}
<p>@durationInTimeRounded seconds</p>
<p>@post.FileExt</p>
</div>

<video controls="controls" src="@post.LargeFileUrl" loop="loop" poster="@post.PreviewFileUrl">

</video>
}
else
{
<img style="background-image: url(@post.PreviewFileUrl);" src="@post.LargeFileUrl" />
}
</div>
<MediaComponent MediaPost="post" />
}

@* The target element that we observe. Once this is reached the callback will be triggered. *@
<li class="list-group-item" id="observerTarget"></li>
</InfiniteScroll>

@if(_shouldDisplayTagContainer)
{
<TagContainerComponent />
}
</div>
</section>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Danbooru.ApiWrapper.Enums;
using Danbooru.ApiWrapper.Interfaces;
using Danbooru.ApiWrapper.Models;
using Danbooru.UI.Interfaces;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;

Expand All @@ -14,9 +15,13 @@ public partial class DoomScroll
[Inject]
public ILogger<DoomScroll> Logger { get; set; } = null!;

[Inject]
public IDoomScrollService DoomScrollService { get; set; } = null!;

private List<Post> _posts = new();

private int _lastIdThatWasRetrieved = -1;
private bool _shouldDisplayTagContainer;

private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
private const int _debouncePeriod = 250;
Expand All @@ -26,6 +31,17 @@ public partial class DoomScroll
private List<TagAutocomplete> _selectedTags = new();
private ContentRating? _contentRating;

protected override void OnInitialized()
{
DoomScrollService.TagContainerToggled += HandleTagContainerToggled;
}

private void HandleTagContainerToggled(object? sender, EventArgs e)
{
_shouldDisplayTagContainer = DoomScrollService.DisplayTagContainer;
StateHasChanged();
}

private void RemoveSelectedTag(TagAutocomplete tag)
{
Logger.LogDebug("Removing selected tag.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,7 @@
gap: 25px;
}

.media-result {
position: relative;
}

.media-result img,
.media-result video {
max-width: 100%;
width: 100%;
}

.meta-data {
position: absolute;
top: 0;
right: 0;
display: flex;
gap: 10px;
padding: 5px;
background-color: rgba(0, 0, 0, 0.75);
}

.search-options-container {
padding: 10px 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
public int Id { get; set; }

[Inject]
public IDanbooruWrapper DanbooruWrapper { get; set; }
public IDanbooruWrapper DanbooruWrapper { get; set; } = null!;

private Post? _post;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ article {
.image-container {
max-width: 98vw;
max-height: 98vh;
object-fit: scale-down;
width: 100%;
height: 100%;
/*object-fit: scale-down;*/
display: flex;
justify-content: center;
align-self: center;
Expand All @@ -46,7 +44,7 @@ article {
.image-container img {
max-width: 100%;
max-height: 100%;
border-radius: 10px;
object-fit: contain;
}

section.image-section {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@using Danbooru.UI.Interfaces

<div class="tag-container-wrapper">

<div class="top">
<div>Tags</div>
<div class="close-tags-button" @onclick=CloseTagsContainer>
<p>❌</p>
</div>
</div>

<div class="tag-container">

<section class="tag-section">
<div class="tag-title-container">
<p>Character</p>
</div>
<div class="tags">
@foreach (var tag in DoomScrollService.PostOfInterest!.TagsCharacter)
{
<p><a href="/search/@tag">@tag</a></p>
}
</div>
</section>

<section class="tag-section">
<div class="tag-title-container">
<p>General</p>
</div>
<div class="tags">
@foreach (var tag in DoomScrollService.PostOfInterest!.TagsGeneral)
{
<p><a href="/search/@tag">@tag</a></p>
}
</div>
</section>

</div>

</div>

@code {
[Inject]
public IDoomScrollService DoomScrollService { get; set; } = null!;

protected override void OnInitialized()
{
DoomScrollService.TagContainerToggled += HandleTagContainerToggled;
}

private void HandleTagContainerToggled(object? sender, EventArgs args)
{
StateHasChanged();
}

private void CloseTagsContainer(MouseEventArgs args)
{
DoomScrollService.ToggleTagDisplay(null);
}
}
Loading

0 comments on commit 2bcb0dc

Please sign in to comment.