comment styles
This commit is contained in:
parent
2f98b1c4ac
commit
7abb809d6f
@ -7,6 +7,7 @@ namespace HN.Application
|
|||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public string Content { get; set; }
|
public string Content { get; set; }
|
||||||
public DateTime CreatedAt { get; set; }
|
public DateTime CreatedAt { get; set; }
|
||||||
|
public string CreatedByName { get; set; }
|
||||||
public int UpVotes { get; set; }
|
public int UpVotes { get; set; }
|
||||||
public int DownVotes { get; set; }
|
public int DownVotes { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -18,11 +18,13 @@ namespace HN.Application
|
|||||||
public Task<CommentDto[]> Handle(GetLinkCommentsQuery request, CancellationToken cancellationToken)
|
public Task<CommentDto[]> Handle(GetLinkCommentsQuery request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var comments = from comment in _context.Comments
|
var comments = from comment in _context.Comments
|
||||||
|
join user in _context.Users on comment.CreatedBy equals user.Id
|
||||||
where comment.LinkId == request.LinkId
|
where comment.LinkId == request.LinkId
|
||||||
select new CommentDto
|
select new CommentDto
|
||||||
{
|
{
|
||||||
Id = comment.Id,
|
Id = comment.Id,
|
||||||
CreatedAt = comment.CreatedAt,
|
CreatedAt = comment.CreatedAt,
|
||||||
|
CreatedByName = user.UserName,
|
||||||
Content = comment.Content,
|
Content = comment.Content,
|
||||||
UpVotes = comment.Votes.Count(c => c.Type == VoteType.Up),
|
UpVotes = comment.Votes.Count(c => c.Type == VoteType.Up),
|
||||||
DownVotes = comment.Votes.Count(c => c.Type == VoteType.Down)
|
DownVotes = comment.Votes.Count(c => c.Type == VoteType.Down)
|
||||||
|
|||||||
@ -1,14 +1,22 @@
|
|||||||
@model ShowLinkViewModel
|
@model ShowLinkViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Viewing";
|
||||||
|
}
|
||||||
|
|
||||||
<partial name="_LinkItem" model="@Model.Link" />
|
<partial name="_LinkItem" model="@Model.Link" />
|
||||||
|
|
||||||
@if(Model.Comments.Length == 0) {
|
@if (Model.Comments.Length == 0)
|
||||||
<p>No comments yet</p>
|
{
|
||||||
} else {
|
<p class="no-comment-yet">No comments yet</p>
|
||||||
<ul>
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<ul class="comments">
|
||||||
@foreach (var comment in Model.Comments)
|
@foreach (var comment in Model.Comments)
|
||||||
{
|
{
|
||||||
<li><partial name="_CommentItem" model="@comment" /></li>
|
<li>
|
||||||
|
<partial name="_CommentItem" model="@comment" />
|
||||||
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,21 @@
|
|||||||
@model HN.Application.CommentLinkCommand
|
@model HN.Application.CommentLinkCommand
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h2>Add a comment</h2>
|
<h3 class="add-a-comment">Add a comment</h3>
|
||||||
@if(User.Identity.IsAuthenticated) {
|
@if (User.Identity.IsAuthenticated)
|
||||||
<form asp-action="Create" asp-controller="Comments" method="post">
|
{
|
||||||
|
<form class="form" asp-action="Create" asp-controller="Comments" method="post">
|
||||||
|
<div class="field">
|
||||||
<input type="hidden" asp-for="@Model.LinkId" />
|
<input type="hidden" asp-for="@Model.LinkId" />
|
||||||
<textarea asp-for="@Model.Content"></textarea>
|
<textarea asp-for="@Model.Content"></textarea>
|
||||||
<span asp-validation-for="@Model.Content"></span>
|
<span asp-validation-for="@Model.Content"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button type="submit">Post a comment</button>
|
<button type="submit">Post a comment</button>
|
||||||
</form>
|
</form>
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
<p>Only logged in users can comment.</p>
|
<p>Only logged in users can comment.</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@ -1,14 +1,21 @@
|
|||||||
@model HN.Application.CommentDto
|
@model HN.Application.CommentDto
|
||||||
|
|
||||||
<span>@Model.Content</span>
|
<article class="comment">
|
||||||
<div>
|
<p>@Model.Content</p>
|
||||||
👍: @Model.UpVotes / 👎: @Model.DownVotes
|
<ul class="comment__actions">
|
||||||
</div>
|
<li>posted at @Model.CreatedAt.ToLocalTime() by <strong>@Model.CreatedByName</strong></li>
|
||||||
|
<li>
|
||||||
@if (User.Identity.IsAuthenticated) {
|
<strong>@Model.UpVotes</strong> 👍 / <strong>@Model.DownVotes</strong> 👎
|
||||||
<form asp-action="Vote" asp-controller="Comments" asp-route-id="@Model.Id" method="post">
|
</li>
|
||||||
|
@if (User.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<form class="votable" asp-controller="Comments" asp-action="Vote" asp-route-id="@Model.Id" method="post">
|
||||||
<input type="hidden" name="redirectTo" value="@Context.Request.Path" />
|
<input type="hidden" name="redirectTo" value="@Context.Request.Path" />
|
||||||
<input type="submit" name="type" value="up" />
|
vote <input type="submit" name="type" value="up" /> or <input type="submit" name="type"
|
||||||
<input type="submit" name="type" value="down" />
|
value="down" />
|
||||||
</form>
|
</form>
|
||||||
|
</li>
|
||||||
}
|
}
|
||||||
|
</ul>
|
||||||
|
</article>
|
||||||
@ -63,7 +63,8 @@ a {
|
|||||||
color: gray;
|
color: gray;
|
||||||
}
|
}
|
||||||
|
|
||||||
.links {
|
.links,
|
||||||
|
.comments {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,23 +88,28 @@ a {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link__actions {
|
.link__actions,
|
||||||
|
.comment__actions {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: rgba(0, 0, 0, 0.54);
|
color: rgba(0, 0, 0, 0.54);
|
||||||
display: flex;
|
display: flex;
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link__actions li + li {
|
.link__actions li + li,
|
||||||
|
.comment__actions li + li {
|
||||||
margin-left: 1rem;
|
margin-left: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link__actions a {
|
.link__actions a,
|
||||||
|
.comment__actions a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link__actions a:hover,
|
.link__actions a:hover,
|
||||||
.link__actions a:focus {
|
.link__actions a:focus,
|
||||||
|
.comment__actions a:hover,
|
||||||
|
.comment__actions a:focus {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,8 +142,31 @@ label {
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.votable input[value="up"]::before {
|
.no-comment-yet {
|
||||||
color: red;
|
color: rgba(0, 0, 0, 0.72);
|
||||||
content: "test";
|
font-style: italic;
|
||||||
display: block;
|
margin: 2rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-a-comment {
|
||||||
|
color: gray;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
color: inherit;
|
||||||
|
font: inherit;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comments {
|
||||||
|
padding-left: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment {
|
||||||
|
background-color: #fafafa;
|
||||||
|
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.12);
|
||||||
|
padding: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user