Skip to content

Commit

Permalink
Fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Sep 10, 2021
1 parent 22c599b commit 5d50916
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public async Task ShouldSubtractLikeOnEvent()
await Repository.StoreAsync(publishedPost);
using var ctx = new TestContext();
var localStorage = new Mock<ILocalStorageService>();
localStorage.Setup(l => l.ContainKeyAsync("hasLiked", default)).ReturnsAsync(true);
localStorage.Setup(l => l.GetItemAsync<bool>("hasLiked", default)).ReturnsAsync(true);
var hasLikedStorage = $"hasLiked/{publishedPost.Id}";
localStorage.Setup(l => l.ContainKeyAsync(hasLikedStorage, default)).ReturnsAsync(true);
localStorage.Setup(l => l.GetItemAsync<bool>(hasLikedStorage, default)).ReturnsAsync(true);
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
RegisterComponents(ctx, localStorage.Object);
ctx.AddTestAuthorization().SetAuthorized("s");
Expand Down
6 changes: 3 additions & 3 deletions LinkDotNet.Blog.Web/Shared/Like.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@

HasLiked = !HasLiked;
await OnBlogPostLiked.InvokeAsync(HasLiked);
await localStorage.SetItemAsync("hasLiked", HasLiked);
await localStorage.SetItemAsync($"hasLiked/{BlogPost.Id}", HasLiked);
}

private async Task<bool> GetHasLiked()
{
if (await localStorage.ContainKeyAsync("hasLiked"))
if (await localStorage.ContainKeyAsync($"hasLiked/{BlogPost.Id}"))
{
return await localStorage.GetItemAsync<bool>("hasLiked");
return await localStorage.GetItemAsync<bool>($"hasLiked/{BlogPost.Id}");
}

return false;
Expand Down

0 comments on commit 5d50916

Please sign in to comment.