Skip to content

Commit

Permalink
Added mute function to card AfterRender (#386)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
csharpfritz and github-actions[bot] authored Feb 27, 2024
1 parent 01218e4 commit 0918161
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/TagzApp.Blazor.Client/Components/ModerationMessage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
if (Content.Content.PreviewCard.ImageUri.ToString().EndsWith(".mp4"))
{
<div class="contentcard">
<video muted="muted" controls="controls" autoplay src="@Content.Content.PreviewCard.ImageUri" class="card-img-top" alt="@Content.Content.PreviewCard.AltText"></video>
<video id="video_@Content.ProviderId" muted controls="controls" autoplay src="@Content.Content.PreviewCard.ImageUri" class="card-img-top" alt="@Content.Content.PreviewCard.AltText"></video>
</div>
}
else
Expand Down Expand Up @@ -116,9 +116,15 @@

private bool ShowModerationActions = false;

protected override Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnAfterRenderAsync(bool firstRender)
{


if (Content.Content.HasVideoPreview)
{
await JSRuntime.InvokeVoidAsync("window.WaterfallUi.MuteVideo", $"video_{Content.ProviderId}");
}

if (firstRender)
{
JSRuntime.InvokeVoidAsync("window.Masonry.resizeGridItem", thisArticle);
Expand All @@ -129,7 +135,7 @@

}

return base.OnAfterRenderAsync(firstRender);
await base.OnAfterRenderAsync(firstRender);
}

private const string CSS_APPROVED = "status-approved";
Expand Down
9 changes: 6 additions & 3 deletions src/TagzApp.Blazor.Client/Components/WaterfallMessage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
if (Content.PreviewCard.ImageUri.ToString().EndsWith(".mp4"))
{
<div class="contentcard">
<video muted="muted" controls="controls" autoplay src="@Content.PreviewCard.ImageUri" class="card-img-top" alt="@Content.PreviewCard.AltText"></video>
<video id="video_@Content.ProviderId" controls="controls" autoplay src="@Content.PreviewCard.ImageUri" class="card-img-top" alt="@Content.PreviewCard.AltText"></video>
</div>
}
else
Expand Down Expand Up @@ -61,12 +61,15 @@
private List<string> _CssClasses = new();
private string CssClass => string.Join(" ", _CssClasses);

protected override Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnAfterRenderAsync(bool firstRender)
{

if (Content.HasVideoPreview) {
await JSRuntime.InvokeVoidAsync("window.WaterfallUi.MuteVideo", $"video_{Content.ProviderId}");
}
JSRuntime.InvokeVoidAsync("window.Masonry.resizeGridItem", thisArticle);

return base.OnAfterRenderAsync(firstRender);
await base.OnAfterRenderAsync(firstRender);
}

}
5 changes: 5 additions & 0 deletions src/TagzApp.Blazor/wwwroot/js/waterfall.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@
},

Messages: messages,

MuteVideo: function (video) {
var video = document.getElementById(video);
video.muted = true;
},
};

window.WaterfallUi = waterfallUi;
Expand Down
2 changes: 2 additions & 0 deletions src/TagzApp.ViewModels/Data/ContentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Emote[] Emotes
)
{

public bool HasVideoPreview => PreviewCard?.ImageUri.ToString().EndsWith(".mp4") ?? false;

// TODO: Refactor to not take a dependency on the Common library
public static explicit operator ContentModel(Content content)
{
Expand Down

0 comments on commit 0918161

Please sign in to comment.