Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Mobile | Restore opening user profile on QR code scan #1109

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,28 @@ public async Task<ClaimAchievementResult> Handle(PostAchievementCommand request,
// check for milestone achievements
if (requestedAchievement.Type == AchievementType.Scanned)
{
// TODO: Re-enable when fixed
// var scannedUser = await _context.Users
// .FirstOrDefaultAsync(u => u.AchievementId == requestedAchievement.Id, cancellationToken);
//
// if (scannedUser == null)
// {
// var staffMember = await _context.StaffMembers
// .Include(s => s.StaffAchievement)
// .Where(s => s.StaffAchievement != null)
// .FirstOrDefaultAsync(s => s.StaffAchievement!.Id == requestedAchievement.Id, cancellationToken);
//
// achievementModel.UserId = staffMember?.Id;
// }
// else
// {
// achievementModel.UserId = scannedUser.Id;
// }
var scannedUser = await _context.Users
.FirstOrDefaultAsync(u => u.AchievementId == requestedAchievement.Id, cancellationToken);

if (scannedUser == null)
{
var staffMember = await _context.StaffMembers
.Include(s => s.StaffAchievement)
.Where(s => s.StaffAchievement != null)
.FirstOrDefaultAsync(s => s.StaffAchievement!.Id == requestedAchievement.Id, cancellationToken);

if (staffMember != null)
{
var staffUser = await _context.Users
.FirstOrDefaultAsync(u => u.Email == staffMember.Email, cancellationToken);

achievementModel.UserId = staffUser?.Id;
}
}
else
{
achievementModel.UserId = scannedUser.Id;
}

if (!userAchievements.Any(ua => ua.Achievement.Name == MilestoneAchievements.MeetSSW))
{
Expand Down
44 changes: 26 additions & 18 deletions src/MobileUI/Features/Profile/ProfileViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,34 @@ protected async Task LoadProfileSections()
if (!_loadingProfileSectionsSemaphore.Wait(0))
return;

IsLoading = true;
var profileTask = _userService.GetUserAsync(UserId);
var socialMediaTask = LoadSocialMedia();
try
{
IsLoading = true;
var profileTask = _userService.GetUserAsync(UserId);
var socialMediaTask = LoadSocialMedia();

await Task.WhenAll(profileTask, socialMediaTask);

var profile = profileTask.Result;

ProfilePic = profile.ProfilePic ?? "v2sophie";
Name = profile.FullName;
Rank = profile.Rank;
Points = profile.Points;
Balance = profile.Balance;
IsStaff = profile.IsStaff;
UserEmail = profile.Email;
Title = GetTitle();
await Task.WhenAll(profileTask, socialMediaTask);

var profile = profileTask.Result;

ProfilePic = profile.ProfilePic ?? "v2sophie";
Name = profile.FullName;
Rank = profile.Rank;
Points = profile.Points;
Balance = profile.Balance;
IsStaff = profile.IsStaff;
UserEmail = profile.Email;
Title = GetTitle();

await UpdateSkillsSectionIfRequired();
UpdateLastSeenSection(profile.Achievements);
UpdateRecentActivitySection(profile.Achievements, profile.Rewards);
await UpdateSkillsSectionIfRequired();
UpdateLastSeenSection(profile.Achievements);
UpdateRecentActivitySection(profile.Achievements, profile.Rewards);
}
catch (Exception)
{
await ClosePage();
await App.Current.MainPage.DisplayAlert("Oops...", "There was an error loading this profile", "OK");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random observation but we need an IAlertService for this. Added #1111

}

_loadingProfileSectionsSemaphore.Release();
IsLoading = false;
Expand Down
Loading