Skip to content

Commit 16c830f

Browse files
committed
Restyled like button
1 parent 492f5aa commit 16c830f

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

src/LinkDotNet.Blog.Web/Features/ShowBlogPost/Components/Like.razor

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@using LinkDotNet.Blog.Domain
22
@using LinkDotNet.Blog.Web.Features.Services
33
@inject ILocalStorageService localStorage
4-
<div class="like-container">
5-
<button class="btn @BtnClass" @onclick="LikeBlogPost"><i class="far fa-thumbs-up"></i> @BlogPost.Likes @LikeText</button>
4+
<div class="d-flex align-items-center">
5+
<span class="clap-btn @BtnClass" @onclick="LikeBlogPost"></span> @BlogPost.Likes
66
</div>
77

88
@code {
@@ -14,10 +14,8 @@
1414

1515
private bool HasLiked { get; set; }
1616

17-
private string BtnClass => HasLiked ? "btn-secondary" : "btn-primary";
17+
private string BtnClass => HasLiked ? "clap-active" : string.Empty;
1818

19-
private string LikeText => BlogPost.Likes == 1 ? "Like" : "Likes";
20-
2119
protected override async Task OnAfterRenderAsync(bool firstRender)
2220
{
2321
if (firstRender)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.clap-btn {
2+
display: inline-block;
3+
Cursor: pointer;
4+
width: 50px;
5+
height: 50px;
6+
background: url('assets/ClapAnimation.png') no-repeat 0 50%;
7+
background-size: 900%;
8+
}
9+
10+
.clap-active {
11+
animation-name: animate;
12+
animation-duration: .8s;
13+
animation-iteration-count: 1;
14+
animation-fill-mode: forwards;
15+
animation-timing-function: steps(8);
16+
}
17+
18+
@keyframes animate {
19+
0% { background-position: left; }
20+
50% { background-position: right; }
21+
100% { background-position: right; }
22+
}
22.9 KB
Loading

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/LikeTests.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;
88

99
public class LikeTests : TestContext
1010
{
11-
[Theory]
12-
[InlineData(0, "0 Likes")]
13-
[InlineData(1, "1 Like")]
14-
[InlineData(2, "2 Likes")]
15-
public void ShouldDisplayLikes(int likes, string expectedText)
11+
[Fact]
12+
public void ShouldDisplayLikes()
1613
{
1714
Services.AddScoped(_ => Mock.Of<ILocalStorageService>());
18-
var blogPost = new BlogPostBuilder().WithLikes(likes).Build();
15+
var blogPost = new BlogPostBuilder().WithLikes(1).Build();
1916
var cut = RenderComponent<Like>(
2017
p => p.Add(l => l.BlogPost, blogPost));
2118

22-
var label = cut.Find("button").TextContent;
19+
var label = cut.Find("div").TextContent;
2320

24-
label.Should().Contain(expectedText);
21+
label.Should().Contain("1");
2522
}
2623

2724
[Fact]
@@ -39,7 +36,7 @@ public void ShouldInvokeEventWhenButtonClicked()
3936
wasLike = b;
4037
}));
4138

42-
cut.Find("button").Click();
39+
cut.Find("span").Click();
4340

4441
wasClicked.Should().BeTrue();
4542
wasLike.Should().BeTrue();
@@ -55,7 +52,7 @@ public void ShouldSetLocalStorageVariableOnClick()
5552
var cut = RenderComponent<Like>(
5653
p => p.Add(l => l.BlogPost, blogPost));
5754

58-
cut.Find("button").Click();
55+
cut.Find("span").Click();
5956

6057
localStorage.Verify(l => l.SetItemAsync("hasLiked/id", true), Times.Once);
6158
}
@@ -74,7 +71,7 @@ public void ShouldCheckLocalStorageOnInit()
7471
p => p.Add(l => l.BlogPost, blogPost)
7572
.Add(l => l.OnBlogPostLiked, b => wasLike = b));
7673

77-
cut.Find("button").Click();
74+
cut.Find("span").Click();
7875

7976
wasLike.Should().BeFalse();
8077
}
@@ -93,7 +90,7 @@ public void ShouldCheckStorageOnClickAgainAndDoNothingOnMismatch()
9390
localStorage.Setup(l => l.ContainKeyAsync("hasLiked/id")).ReturnsAsync(true);
9491
localStorage.Setup(l => l.GetItemAsync<bool>("hasLiked/id")).ReturnsAsync(true);
9592

96-
cut.Find("button").Click();
93+
cut.Find("span").Click();
9794

9895
wasClicked.Should().BeFalse();
9996
}

0 commit comments

Comments
 (0)