Skip to content

Commit

Permalink
message sent animation
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Sep 3, 2023
1 parent 848252e commit 4c1de2f
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/web/Client/Features/Chat/LargeChatComponent.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@using MudExtensions.Enums
@inject IChatService ChatService
@inject IProfileCache ProfileCache
@inject ISnackbar Snackbar
Expand Down Expand Up @@ -81,13 +82,17 @@
}

</Virtualize>
@if (LastMessageWasSentSuccessfully)
{
<div title="Din besked er blevet sendt" class="message-sent-successfully-container">
<MudIcon Icon="@Icons.Material.Outlined.CheckCircleOutline"
Class="message-sent-successfully" />
</div>
}

<MudAnimate @ref="_messageSuccessfullySentAnimation"
AnimationType="AnimationType.Fade"
AnimationTiming="AnimationTiming.EaseIn"
Delay="500"
Selector=".message-sent-successfully-container" />

<div title="Din besked er blevet sendt" class="message-sent-successfully-container">
<MudIcon Icon="@Icons.Material.Outlined.CheckCircleOutline"
Class="message-sent-successfully" />
</div>

<MudTextField @bind-Value="_userText"
FullWidth
Expand All @@ -109,6 +114,10 @@

</MudLoading>
@code {
// TODO: Select currently displayed chat using this, when we update to dotnet 8
[SupplyParameterFromQuery]
public Guid? ChatId { get; set; }

private UserProfile? _currentUser;
private UserSlim _currentUserSlim = null!;
private List<ChatDto> _chats = new();
Expand All @@ -119,6 +128,7 @@
private bool _isActiveChatPublished = true;
private bool _isLoading = true;

private MudAnimate _messageSuccessfullySentAnimation = null!;
private Dictionary<Guid, Guid> _lastSuccessfullySentMessageForChat = new();
private bool LastMessageWasSentSuccessfully
{
Expand All @@ -142,10 +152,6 @@
}
}

// TODO: Select currently displayed chat using this, when we update to dotnet 8
[SupplyParameterFromQuery]
public Guid? ChatId { get; set; }

protected override async Task OnInitializedAsync()
{
_currentUser = await ProfileCache.GetOrCreateProfileAsync();
Expand Down Expand Up @@ -183,6 +189,8 @@
if (message.SenderId == _currentUser.Id)
{
_lastSuccessfullySentMessageForChat[chat.Id] = message.Id;
StateHasChanged();
await _messageSuccessfullySentAnimation.Refresh();
return;
}

Expand Down Expand Up @@ -321,13 +329,12 @@
_chats.Insert(0, newChat);

_isActiveChatPublished = false;

await SelectChat(newChat);
}

private string GetRecipientsProfilePictureUrl(ChatMessageDto message)
{
return _activeChat?.Recipients.FirstOrDefault(recipient => recipient.Id == message.SenderId)?.ProfilePictureUrl ?? ProfileConstants.Default_Profile_Picture;
}

=> _activeChat?
.Recipients
.FirstOrDefault(recipient => recipient.Id == message.SenderId)?.ProfilePictureUrl
?? ProfileConstants.Default_Profile_Picture;
}

0 comments on commit 4c1de2f

Please sign in to comment.