Skip to content

Commit

Permalink
Fixed Approve and Reject buttons on Moderation screen
Browse files Browse the repository at this point in the history
  • Loading branch information
csharpfritz committed Feb 2, 2024
1 parent 434ae98 commit 710b8e2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 31 deletions.
31 changes: 15 additions & 16 deletions src/TagzApp.Blazor.Client/Components/ModerationMessage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
@inject NavigationManager NavigationManager

<article @ref="thisArticle"
class="@AdditionalClasses"
class="modMessage @AdditionalClasses"
@onmouseover="() => ShowModerationActions = true"
@onmouseleave="() => ShowModerationActions = false"> @* @onclick="() => OnContentSelected?.InvokeAsync(Content)"> *@

@if (ShowModerationActions)
{
<div id="moderationAction">
<i class="bi bi-check2 approve" title="Approve this content" @onclick="() => Moderate(ModerationState.Approved)"></i>
<i class="bi bi-x-circle-fill reject" title="Reject this content" @onclick="() => Moderate(ModerationState.Rejected)"></i>
<i class="bi bi-check2 approve" title="Approve this content" @onclick="async () => await Moderate(ModerationState.Approved)"></i>
<i class="bi bi-x-circle-fill reject" title="Reject this content" @onclick="async () => await Moderate(ModerationState.Rejected)"></i>
<i class="bi bi-journal-text more"
@onclick="@(() => NavigationManager.NavigateTo($"/MessageDetails/{Content.Provider}/{Content.ProviderId}"))"
title="More Actions"></i>
Expand All @@ -35,7 +35,7 @@
<i class="provider bi @MapProviderToIcon(Content.Provider)"></i>

<div class="time">
<div>@Content.Timestamp.ToString("d") @Content.Timestamp.ToString("t")</div>
<div>@Content.Timestamp.ToLocalTime().ToString("d") @Content.Timestamp.ToLocalTime().ToString("t")</div>
<div class="autoModReason"></div>
</div>

Expand All @@ -50,8 +50,11 @@
[Parameter]
public ModerationContentModel Content { get; set; }

[Parameter]
public EventCallback<ModerationAction> OnModerate { get; set; }
// [Parameter]
// public EventCallback<ModerationAction> OnModerate { get; set; }
[CascadingParameter]
public Components.Pages.Moderation ModerationPage { get; set; }

private ElementReference thisArticle;

Expand Down Expand Up @@ -82,24 +85,20 @@
async Task Moderate(ModerationState action)
{

Content = Content with
{
ModerationTimestamp = DateTimeOffset.Now,
State = action
};
Content.ModerationTimestamp = DateTimeOffset.Now;
Content.State = action;

ShowModerationActions = false;

await InvokeAsync(StateHasChanged);
Console.WriteLine($"Content state: {Content.State} {Content.ModerationTimestamp} {AdditionalClasses}");
StateHasChanged();

await OnModerate.InvokeAsync(new ModerationAction {
await ModerationPage.Moderate(new ModerationAction {
Provider = Content.Provider,
ProviderId = Content.ProviderId,
State = action,
Timestamp = DateTimeOffset.Now
});



}

public static string MapProviderToIcon(string provider) =>
Expand Down
45 changes: 34 additions & 11 deletions src/TagzApp.Blazor.Client/Components/Pages/Moderation.razor
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@

<div id="taggedContent" class="">

@foreach (var content in _Content.Values.Reverse())
{
<ModerationMessage Content="content" OnModerate="Moderate" />
}
<CascadingValue Value="this">
@foreach (var content in _Content.Values.Reverse())
{
<ModerationMessage Content="content" />
}
</CascadingValue>

</div>

Expand Down Expand Up @@ -197,10 +199,21 @@

_Connection.On<ModerationContentModel>("NewRejectedMessage", async (content) => {
if (!ThePauseButton.IsPaused) {
// TODO: Write this method
//RejectMessage(content);
await InvokeAsync(StateHasChanged);
} else {
var existing = _Content.FirstOrDefault(p => p.Value.ProviderId == content.ProviderId);
if (existing.Value is not null && existing.Value.State == ModerationState.Rejected) return;

if (existing.Value is not null)
{
existing.Value.State = ModerationState.Rejected;
existing.Value.ModerationTimestamp = content.ModerationTimestamp;
}
else
{
_Content.Add(content.Timestamp, content);
}
}
else
{

var existing = _PauseQueue.FirstOrDefault(p => p is ContentModel && p.ProviderId == content.ProviderId);
if (existing is not null)
Expand Down Expand Up @@ -237,8 +250,18 @@
{
if (!ThePauseButton.IsPaused)
{
// TODO: Approve the message
//ApproveMessage(content);
var existing = _Content.FirstOrDefault(p => p.Value.ProviderId == content.ProviderId);
if (existing.Value is not null && existing.Value.State == ModerationState.Approved) return;

if (existing.Value is not null)
{
existing.Value.State = ModerationState.Approved;
existing.Value.ModerationTimestamp = content.ModerationTimestamp;
}
else
{
_Content.Add(content.Timestamp, content);
}
await InvokeAsync(StateHasChanged);
}
else
Expand Down Expand Up @@ -268,7 +291,7 @@

}

async Task Moderate(ModerationAction action)
public async Task Moderate(ModerationAction action)
{

await _Connection.InvokeAsync("SetStatus", action.Provider, action.ProviderId, action.State);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<i class="provider bi @MapProviderToIcon(Content.Provider)"></i>

<div class="time">
<div>@Content.Timestamp.ToString("d") @Content.Timestamp.ToString("t")</div>
<div>@Content.Timestamp.ToLocalTime().ToString("d") @Content.Timestamp.ToLocalTime().ToString("t")</div>
<div class="autoModReason"></div>
</div>

Expand Down
44 changes: 41 additions & 3 deletions src/TagzApp.ViewModels/Data/ModerationContentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace TagzApp.ViewModels.Data;
/// <param name="AuthorProfileUri">Profile URI of the author of the content</param>
/// <param name="AuthorProfileImageUri">Profile Image URI of the author of the content</param>
/// <param name="Text">Text of the content</param>
public record ModerationContentModel(
public class ModerationContentModel
{

public ModerationContentModel(
string Provider,
string ProviderId,
string Type,
Expand All @@ -28,8 +31,26 @@ public record ModerationContentModel(
string? Moderator,
DateTimeOffset? ModerationTimestamp,
Emote[] Emotes
)
{
)
{
this.Provider = Provider;
this.ProviderId = ProviderId;
this.Type = Type;
this.SourceUri = SourceUri;
this.Timestamp = Timestamp;
this.AuthorDisplayName = AuthorDisplayName;
this.AuthorUserName = AuthorUserName;
this.AuthorProfileUri = AuthorProfileUri;
this.AuthorProfileImageUri = AuthorProfileImageUri;
this.Text = Text;
this.PreviewCard = PreviewCard;
this.State = State;
this.Reason = Reason;
this.Moderator = Moderator;
this.ModerationTimestamp = ModerationTimestamp;
this.Emotes = Emotes;

}

public ContentModel Content => new(
Provider,
Expand All @@ -46,6 +67,23 @@ Emote[] Emotes
Emotes
);

public string Provider { get; }
public string ProviderId { get; }
public string Type { get; }
public string SourceUri { get; }
public DateTimeOffset Timestamp { get; }
public string AuthorDisplayName { get; }
public string AuthorUserName { get; set; }
public string AuthorProfileUri { get; set; }
public string AuthorProfileImageUri { get; set; }
public string Text { get; set; }
public Card? PreviewCard { get; set; }
public ModerationState State { get; set; }
public string? Reason { get; set; }
public string? Moderator { get; set; }
public DateTimeOffset? ModerationTimestamp { get; set; }
public Emote[] Emotes { get; set; }

// TODO: Refactor to eliminate the direct reference to Common project
public static ModerationContentModel ToModerationContentModel(Content content, ModerationAction? action = null)
{
Expand Down

0 comments on commit 710b8e2

Please sign in to comment.