Skip to content

Commit 4c1de2f

Browse files
committed
message sent animation
1 parent 848252e commit 4c1de2f

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/web/Client/Features/Chat/LargeChatComponent.razor

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@using MudExtensions.Enums
12
@inject IChatService ChatService
23
@inject IProfileCache ProfileCache
34
@inject ISnackbar Snackbar
@@ -81,13 +82,17 @@
8182
}
8283

8384
</Virtualize>
84-
@if (LastMessageWasSentSuccessfully)
85-
{
86-
<div title="Din besked er blevet sendt" class="message-sent-successfully-container">
87-
<MudIcon Icon="@Icons.Material.Outlined.CheckCircleOutline"
88-
Class="message-sent-successfully" />
89-
</div>
90-
}
85+
86+
<MudAnimate @ref="_messageSuccessfullySentAnimation"
87+
AnimationType="AnimationType.Fade"
88+
AnimationTiming="AnimationTiming.EaseIn"
89+
Delay="500"
90+
Selector=".message-sent-successfully-container" />
91+
92+
<div title="Din besked er blevet sendt" class="message-sent-successfully-container">
93+
<MudIcon Icon="@Icons.Material.Outlined.CheckCircleOutline"
94+
Class="message-sent-successfully" />
95+
</div>
9196

9297
<MudTextField @bind-Value="_userText"
9398
FullWidth
@@ -109,6 +114,10 @@
109114

110115
</MudLoading>
111116
@code {
117+
// TODO: Select currently displayed chat using this, when we update to dotnet 8
118+
[SupplyParameterFromQuery]
119+
public Guid? ChatId { get; set; }
120+
112121
private UserProfile? _currentUser;
113122
private UserSlim _currentUserSlim = null!;
114123
private List<ChatDto> _chats = new();
@@ -119,6 +128,7 @@
119128
private bool _isActiveChatPublished = true;
120129
private bool _isLoading = true;
121130

131+
private MudAnimate _messageSuccessfullySentAnimation = null!;
122132
private Dictionary<Guid, Guid> _lastSuccessfullySentMessageForChat = new();
123133
private bool LastMessageWasSentSuccessfully
124134
{
@@ -142,10 +152,6 @@
142152
}
143153
}
144154

145-
// TODO: Select currently displayed chat using this, when we update to dotnet 8
146-
[SupplyParameterFromQuery]
147-
public Guid? ChatId { get; set; }
148-
149155
protected override async Task OnInitializedAsync()
150156
{
151157
_currentUser = await ProfileCache.GetOrCreateProfileAsync();
@@ -183,6 +189,8 @@
183189
if (message.SenderId == _currentUser.Id)
184190
{
185191
_lastSuccessfullySentMessageForChat[chat.Id] = message.Id;
192+
StateHasChanged();
193+
await _messageSuccessfullySentAnimation.Refresh();
186194
return;
187195
}
188196

@@ -321,13 +329,12 @@
321329
_chats.Insert(0, newChat);
322330

323331
_isActiveChatPublished = false;
324-
325332
await SelectChat(newChat);
326333
}
327334

328335
private string GetRecipientsProfilePictureUrl(ChatMessageDto message)
329-
{
330-
return _activeChat?.Recipients.FirstOrDefault(recipient => recipient.Id == message.SenderId)?.ProfilePictureUrl ?? ProfileConstants.Default_Profile_Picture;
331-
}
332-
336+
=> _activeChat?
337+
.Recipients
338+
.FirstOrDefault(recipient => recipient.Id == message.SenderId)?.ProfilePictureUrl
339+
?? ProfileConstants.Default_Profile_Picture;
333340
}

0 commit comments

Comments
 (0)