Skip to content

Commit

Permalink
Merge pull request #122 from ChrispyPeaches/friends-lists-refresh-views
Browse files Browse the repository at this point in the history
Friends lists refresh views
  • Loading branch information
iggy808 authored May 10, 2024
2 parents 76d7c08 + 451a853 commit 4d6b606
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/FocusApp.Client/Views/Social/AddFriendPopupInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public AddFriendPopupInterface(
};

// Populate PendingFriends upon popup open
PopulatePopup();
Task.Run(PopulatePopup);
}

private void AddFriendPopupInterface_Closed(object? sender, PopupClosedEventArgs e)
Expand All @@ -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(() =>
{
Expand Down Expand Up @@ -309,18 +311,29 @@ private ListView BuildFriendRequestListView()
return listView;
}

private async void PopulatePopup()
private async Task PopulatePopup()
{
List<FriendRequest> pendingFriendRequests;
List<FriendRequest> pendingFriendRequests = new List<FriendRequest>();

// 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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/FocusApp.Client/Views/Social/SocialPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
{
Expand Down Expand Up @@ -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<string> TapFriendItemCommand => new(OnFriendClickShowFriendProfilePage);

/// <summary>
Expand Down

0 comments on commit 4d6b606

Please sign in to comment.