Skip to content

Commit

Permalink
Fix SO behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jun 28, 2024
1 parent c2c5933 commit c139a0d
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,29 @@
[Parameter]
public EventCallback<bool> OnBlogPostLiked { get; set; }

private bool shouldBeUpdated;

private bool HasLiked { get; set; }

private string BtnClass => HasLiked ? "clap-active" : string.Empty;

protected override void OnParametersSet()
{
base.OnParametersSet();
shouldBeUpdated = true;
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
HasLiked = await GetHasLiked();
StateHasChanged();
// As we are using static prerendering, we can only issue JS Interop in OnAfterRender
// As the page might be updated (click a related blog post inside a blog post), we need to update the like status
// But we only want to do this once
if (shouldBeUpdated)
{
HasLiked = await GetHasLiked();
shouldBeUpdated = false;
StateHasChanged();
}
}

private async Task LikeBlogPost()
Expand Down

0 comments on commit c139a0d

Please sign in to comment.