-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented register and view news reactions.
- Loading branch information
Showing
38 changed files
with
13,791 additions
and
19 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/Microservices/Services/News/NewsAggregator.News.Mvc/Components/NewsReactions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using NewsAggregator.News.UseCases.Queries; | ||
|
||
namespace NewsAggregator.News.Mvc.Components | ||
{ | ||
public class NewsReactions : ViewComponent | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public NewsReactions(IMediator mediator) | ||
{ | ||
_mediator = mediator; | ||
} | ||
|
||
public async Task<IViewComponentResult> InvokeAsync(Guid newsId, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var reactions = await _mediator.Send(new GetNewsReactionsQuery(newsId), cancellationToken); | ||
|
||
return View(reactions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ervices/News/NewsAggregator.News.Mvc/Views/Shared/Components/NewsReactions/Default.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@model IReadOnlyCollection<NewsReactionDto> | ||
|
||
<div class="news-reactions"> | ||
@foreach (var reaction in Model) | ||
{ | ||
<div class="news-reactions__reaction" data-reaction-newsId="@reaction.NewsId" data-reaction-id="@reaction.ReactionId"> | ||
<i class="bi @reaction.ReactionIconClass" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="@reaction.ReactionTitle" style="color: @reaction.ReactionIconColor"></i> | ||
<span class="news-reactions__reaction__counter" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="@(reaction.Count.ToString("N0", new CultureInfo("en-US")))"> | ||
@reaction.Count.ToString("N0", new CultureInfo("en-US")) | ||
</span> | ||
</div> | ||
} | ||
</div> |
12 changes: 12 additions & 0 deletions
12
...ices/News/NewsAggregator.News.Mvc/Views/Shared/Components/NewsReactions/Default.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace NewsAggregator.News.Mvc.Views.Shared.Components.NewsReactions | ||
{ | ||
public class DefaultModel : PageModel | ||
{ | ||
public void OnGet() | ||
{ | ||
|
||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/Microservices/Services/News/NewsAggregator.News.Mvc/Views/Shared/_Scripts.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<script src="~/lib/jquery/dist/jquery.min.js"></script> | ||
<script src="~/lib/axios/dist/axios.min.js"></script> | ||
<script src="~/lib/moment/dist/moment.min.js"></script> | ||
<script src="~/lib/signalr/dist/signalr.min.js"></script> | ||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script> | ||
<script src="~/js/search-news-modal.js"></script> | ||
<script src="~/js/pagination.js"></script> | ||
<script src="~/js/hotline.js"></script> | ||
<script src="~/js/time-converter.js"></script> | ||
<script src="~/js/news-reaction.js"></script> | ||
<script src="~/js/site.js"></script> | ||
<script src="~/js/color-modes.js"></script> |
2 changes: 2 additions & 0 deletions
2
src/Microservices/Services/News/NewsAggregator.News.Mvc/Views/Shared/_Styles.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<link rel="stylesheet" href="@("https://cdn.jsdelivr.net/npm/@docsearch/css@3")" asp-append-version="true" /> | ||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> | ||
<link rel="stylesheet" href="@("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css")" /> | ||
<link rel="stylesheet" href="~/lib/bootstrap/dist/" /> | ||
<link rel="stylesheet" href="~/css/custom.css" asp-append-version="true" /> | ||
<link rel="stylesheet" href="@("https://fonts.googleapis.com/css?family=Playfair+Display:700,900&display=swap")" asp-append-version="true" /> | ||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" /> |
20 changes: 20 additions & 0 deletions
20
src/Microservices/Services/News/NewsAggregator.News.Mvc/wwwroot/js/news-reaction.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
document.addEventListener('DOMContentLoaded', function (e) { | ||
var newsReactionsContainer = document.querySelector('div.news-reactions'); | ||
var newsReactions = newsReactionsContainer?.querySelectorAll('div.news-reactions__reaction[data-reaction-newsId][data-reaction-id]'); | ||
|
||
if (newsReactions) { | ||
newsReactions.forEach(function (newsReactionElement) { | ||
newsReactionElement.addEventListener('click', async function () { | ||
var newsId = newsReactionElement.getAttribute('data-reaction-newsId'); | ||
var reactionId = newsReactionElement.getAttribute('data-reaction-id'); | ||
|
||
try { | ||
await axios.post(`http://${window.location.hostname}/news/${newsId}/sendNewsReaction?reactionId=${reactionId}`); | ||
alert('Sending a reaction to the news was successful.'); | ||
} catch (error) { | ||
alert('An error occurred when sending a reaction to the news'); | ||
} | ||
}); | ||
}); | ||
} | ||
}); |
2 changes: 2 additions & 0 deletions
2
src/Microservices/Services/News/NewsAggregator.News.Mvc/wwwroot/lib/axios/dist/axios.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/Microservices/Services/News/NewsAggregator.News/DTOs/NewsReactionDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace NewsAggregator.News.DTOs | ||
{ | ||
public class NewsReactionDto | ||
{ | ||
public Guid NewsId { get; set; } | ||
|
||
public Guid ReactionId { get; set; } | ||
|
||
public string ReactionTitle { get; set; } | ||
|
||
public string? ReactionIconClass { get; set; } | ||
|
||
public string? ReactionIconColor { get; set; } | ||
|
||
public int Count { get; set; } | ||
} | ||
} |
Oops, something went wrong.