diff --git a/src/FocusApp.Client/Views/Social/AddFriendPopupInterface.cs b/src/FocusApp.Client/Views/Social/AddFriendPopupInterface.cs index 8697c7f..c369b32 100644 --- a/src/FocusApp.Client/Views/Social/AddFriendPopupInterface.cs +++ b/src/FocusApp.Client/Views/Social/AddFriendPopupInterface.cs @@ -224,7 +224,7 @@ public AddFriendPopupInterface( }; // Populate PendingFriends upon popup open - PopulatePopup(); + Task.Run(PopulatePopup); } private void AddFriendPopupInterface_Closed(object? sender, PopupClosedEventArgs e) @@ -237,6 +237,8 @@ private ListView BuildFriendRequestListView() ListView listView = new ListView(); listView.Header = "Pending Friend Requests"; + listView.IsPullToRefreshEnabled = true; + listView.Invoke(l => l.Refreshing += RefreshFriendRequestList); listView.ItemTemplate = new DataTemplate(() => { @@ -309,18 +311,29 @@ private ListView BuildFriendRequestListView() return listView; } - private async void PopulatePopup() + private async Task PopulatePopup() { - List pendingFriendRequests; + List pendingFriendRequests = new List(); // Fetch all pending friend requests var query = new GetAllFriendRequestsQuery { UserId = _authenticationService.CurrentUser.Id }; - pendingFriendRequests = await _client.GetAllFriendRequests(query, default); - _friendrequestView.ItemsSource = pendingFriendRequests; + try + { + pendingFriendRequests = await _client.GetAllFriendRequests(query, default); + } + catch (Exception ex) + { + _logger.LogError(ex, "An error occured while fetching friend requests"); + } + + MainThread.BeginInvokeOnMainThread(() => + { + _friendrequestView.ItemsSource = pendingFriendRequests; + }); } // Populate entry error label with corresponding message @@ -383,7 +396,7 @@ private async void OnClickSendFriendRequest(object sender, EventArgs e) PopulateErrorLabel((HttpStatusCode)httpCode); } - PopulatePopup(); + Task.Run(PopulatePopup); } private async void OnClickAcceptFriendRequest(object sender, EventArgs e) @@ -406,9 +419,9 @@ private async void OnClickAcceptFriendRequest(object sender, EventArgs e) Task.Run(SocialPage.PopulateFriendsList); Task.Run(ShowSocialBadgeIfEarned); - PopulatePopup(); + Task.Run(PopulatePopup); + - } private async Task ShowSocialBadgeIfEarned() @@ -443,7 +456,7 @@ private async void OnClickRejectFriendRequest(object sender, EventArgs e) // Reject Friend Request await _client.CancelFriendRequest(cancelCommand); - PopulatePopup(); + Task.Run(PopulatePopup); } private async void OnClickCancelFriendRequest(object sender, EventArgs e) @@ -462,7 +475,13 @@ private async void OnClickCancelFriendRequest(object sender, EventArgs e) // Cancel Friend Request await _client.CancelFriendRequest(cancelCommand); - PopulatePopup(); + Task.Run(PopulatePopup); + } + + private async void RefreshFriendRequestList(object? sender, EventArgs e) + { + Task.Run(PopulatePopup); + _friendrequestView.EndRefresh(); } // Navigate to page according to button diff --git a/src/FocusApp.Client/Views/Social/SocialPage.cs b/src/FocusApp.Client/Views/Social/SocialPage.cs index 4eb8e97..f5be44e 100644 --- a/src/FocusApp.Client/Views/Social/SocialPage.cs +++ b/src/FocusApp.Client/Views/Social/SocialPage.cs @@ -138,6 +138,8 @@ private AvatarView GetProfilePictureNavMenuButton() => private ListView BuildFriendsListView() { ListView listView = new ListView(); + listView.IsPullToRefreshEnabled = true; + listView.Invoke(l => l.Refreshing += RefreshFriendsList); listView.ItemTemplate = new DataTemplate(() => { @@ -283,6 +285,12 @@ private void OnClickShowAddFriendsPopup(object? sender, EventArgs e) addFriendPopup.SocialPage = this; } + private async void RefreshFriendsList(object? sender, EventArgs e) + { + Task.Run(PopulateFriendsList); + _friendsListView.EndRefresh(); + } + public AsyncRelayCommand TapFriendItemCommand => new(OnFriendClickShowFriendProfilePage); ///