docs: #342 changing the method which user upvoted recitations are marked at the start of page rendering

This commit is contained in:
Hamid Reza Mohammadi 2022-07-07 17:16:22 +04:30
parent ee2acdcdfb
commit c9c5856060
5 changed files with 38 additions and 12 deletions

View File

@ -234,13 +234,6 @@
{
if (Model.IsPoemPage)
{
if (Model.GanjoorPage.Poem.Recitations.Length > 0)
{
<script>
MarkUserUpvotedRecitations(@Model.GanjoorPage.Id);
</script>
}
if (Model.KeepHistory)
{
<script>
@ -248,8 +241,6 @@
</script>
}
}
}

View File

@ -333,7 +333,7 @@ namespace GanjooRazor.Pages
/// <summary>
/// specify which comments belong to current user
/// </summary>
private void _markMyComments()
private async Task _markMyCommentsAndBringUpMyRecitations()
{
if (GanjoorPage == null)
{
@ -360,6 +360,26 @@ namespace GanjooRazor.Pages
comment.MyComment = comment.UserId == userId;
_markMyReplies(comment, userId, null);
}
if(GanjoorPage.Poem.Recitations.Length > 0)
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{GanjoorPage.Poem.Id}/recitations/upvotes");
if (response.IsSuccessStatusCode)
{
var upVotedIds = JsonConvert.DeserializeObject<int[]>(await response.Content.ReadAsStringAsync());
foreach (var recitation in GanjoorPage.Poem.Recitations)
{
recitation.UpVotedByUser = upVotedIds.Contains(recitation.Id);
}
}
}
}
}
}
private void _markMyReplies(GanjoorCommentSummaryViewModel parent, Guid userId, GanjoorUserBookmarkViewModel[] bookmarks)
@ -649,7 +669,7 @@ namespace GanjooRazor.Pages
switch (GanjoorPage.GanjoorPageType)
{
case GanjoorPageType.PoemPage:
_markMyComments();
await _markMyCommentsAndBringUpMyRecitations();
_preparePoemExcerpt(GanjoorPage.Poem.Next);
_preparePoemExcerpt(GanjoorPage.Poem.Previous);
GanjoorPage.PoetOrCat = GanjoorPage.Poem.Category;
@ -906,6 +926,11 @@ namespace GanjooRazor.Pages
return new OkObjectResult(false);
}
/// <summary>
/// unused now, to be removed
/// </summary>
/// <param name="poemId"></param>
/// <returns></returns>
public async Task<IActionResult> OnGetUserUpvotedRecitationsAsync(int poemId)
{
using (HttpClient secureClient = new HttpClient())

View File

@ -22,7 +22,7 @@
<a role="button" class="w3tooltip cursor-pointer recitation-button" href="@($"/ReportRecitation/?a={recitaion.Id}")" onclick="wpopen(this.href); return false"><i class="recitation-icons recitation-report"></i><span class="w3tooltiptext">گزارش خطا</span></a>
@if (Model.LoggedIn)
{
<a role="button" class="w3tooltip cursor-pointer recitation-button" onclick="switchRecitationVote(@recitaion.Id)"><i class="recitation-icons recitation-novote" id="@($"recitaion-{recitaion.Id}")"></i><span class="w3tooltiptext">رأی به خوانش</span></a>
<a role="button" class="w3tooltip cursor-pointer recitation-button" onclick="switchRecitationVote(@recitaion.Id)"><i class="recitation-icons @(recitaion.UpVotedByUser ? "recitation-vote" : "recitation-novote")" id="@($"recitaion-{recitaion.Id}")"></i><span class="w3tooltiptext">رأی به خوانش</span></a>
}
<a role="button" class="w3tooltip cursor-pointer recitation-button" href="@($"/RecitationsOrder/?p={recitaion.PoemId}#a{recitaion.Id}")" onclick="wpopen(this.href); return false"><i class="recitation-icons recitation-score"></i><span class="w3tooltiptext">اطلاعات رتبه‌بندی</span></a>
@if(recitaion.AudioArtistUrl.IndexOf("http") == 0)

View File

@ -102,5 +102,10 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels
/// </summary>
public RecitationMistakeViewModel[] Mistakes { get; set; }
/// <summary>
/// upvoted by current user (filled at client)
/// </summary>
public bool UpVotedByUser { get; set; }
}
}

View File

@ -4861,6 +4861,11 @@
mistakes
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.PublicRecitationViewModel.UpVotedByUser">
<summary>
upvoted by current user (filled at client)
</summary>
</member>
<member name="T:RMuseum.Models.GanjoorAudio.ViewModels.RecitationErrorReportViewModel">
<summary>
Post Error Report for recitations