Skip to content

Commit

Permalink
🐛 Mobile | Fix camera button not showing on profile (#654)
Browse files Browse the repository at this point in the history
* Fix camera not showing

* Add Image Name to UploadProfilePic

* Fix ProfilePics Upload

---------

Co-authored-by: Tylah Kapa <[email protected]>
  • Loading branch information
zacharykeeping and tkapa authored Feb 9, 2024
1 parent 028a7b1 commit 92b9070
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 24 deletions.
30 changes: 25 additions & 5 deletions src/ApiClient/Services/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public interface IUserService
{
Task DeleteMyProfile(CancellationToken cancellationToken = default);

Task<ProfilePicResponseDto> UploadProilePic(Stream file, CancellationToken cancellationToken = default);
Task<ProfilePicResponseDto> UploadProfilePic(Stream file, string fileName,
CancellationToken cancellationToken = default);

Task<CurrentUserDto> GetCurrentUser(CancellationToken cancellationToken = default);

Expand Down Expand Up @@ -44,12 +45,12 @@ public async Task DeleteMyProfile(CancellationToken cancellationToken = default)
throw new Exception($"Failed to delete my profile: {responseContent}");
}

public async Task<ProfilePicResponseDto> UploadProilePic(Stream file, CancellationToken cancellationToken = default)
public async Task<ProfilePicResponseDto> UploadProfilePic(Stream file, string fileName,
CancellationToken cancellationToken = default)
{
var content = new MultipartFormDataContent();
content.Add(new StreamContent(file), "file", "file");
var content = Helpers.ProcessImageContent(file, fileName);

var result = await _httpClient.PostAsync($"{_baseRoute}/UploadProfilePic", content, cancellationToken);
var result = await _httpClient.PostAsync($"{_baseRoute}UploadProfilePic", content, cancellationToken);

if (result.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -160,4 +161,23 @@ public async Task<UserRewardsViewModel> GetUserRewards(int userId, CancellationT

throw new Exception($"Failed to get user rewards: {responseContent}");
}

// public async Task<NewUsersViewModel> GetNewUsers(LeaderboardFilter filter, bool filterStaff = false, CancellationToken cancellationToken = default)
// {
// var result = await _httpClient.GetAsync($"{_baseRoute}/NewUsers?filter={filter}&filterStaff={filterStaff}");
//
// if (result.IsSuccessStatusCode)
// {
// var response = await result.Content.ReadFromJsonAsync<NewUsersViewModel>(cancellationToken: cancellationToken);
//
// if (response is not null)
// {
// return response;
// }
// }
//
// var responseContent = await result.Content.ReadAsStringAsync(cancellationToken);
//
// throw new Exception($"Failed to get user rewards: {responseContent}");
// }
}
2 changes: 1 addition & 1 deletion src/Infrastructure/Services/ProfilePicStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class ProfilePicStorageProvider : IProfilePicStorageProvider
{
private readonly IStorageProvider _storageProvider;

private const string CONTAINER_NAME = "ProfilePics";
private const string CONTAINER_NAME = "profilepics";

public ProfilePicStorageProvider(IStorageProvider storageProvider)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MobileUI/Controls/ProfileStats.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
TranslationY="-35"
StrokeShape="Ellipse"
StrokeThickness="0"
IsVisible="{Binding ShowCamera}">
IsVisible="{Binding IsMe}">
<Border.GestureRecognizers>
<TapGestureRecognizer Command="{Binding CameraCommand}"/>
</Border.GestureRecognizers>
Expand Down
2 changes: 1 addition & 1 deletion src/MobileUI/Services/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IUserService
Task<IEnumerable<Reward>> GetRewardsAsync();
Task<IEnumerable<Reward>> GetRewardsAsync(int userId);
Task<ImageSource> GetAvatarAsync(string url);
Task<string> UploadImageAsync(Stream image);
Task<string> UploadImageAsync(Stream image, string fileName);


Task<bool> DeleteProfileAsync();
Expand Down
4 changes: 2 additions & 2 deletions src/MobileUI/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public string MyProfilePic

public bool IsStaff { get => !string.IsNullOrWhiteSpace(MyQrCode); }

public async Task<string> UploadImageAsync(Stream image)
public async Task<string> UploadImageAsync(Stream image, string fileName)
{
var response = await _userClient.UploadProilePic(image);
var response = await _userClient.UploadProfilePic(image, fileName);

Preferences.Set(nameof(MyProfilePic), response.PicUrl);

Expand Down
2 changes: 1 addition & 1 deletion src/MobileUI/ViewModels/CameraPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public async Task UploadProfilePic()
{
IsUploading = true;
var imageStream = await _imageFile.OpenReadAsync();
await _userService.UploadImageAsync(imageStream);
await _userService.UploadImageAsync(imageStream, _imageFile.FileName);
await MopupService.Instance.PopAllAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task Initialise()
});
}

_isMe = true;
IsMe = true;

var profilePic = _userService.MyProfilePic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task Initialise()
});
}

_isMe = false;
IsMe = false;

await _initialise();
}
Expand Down
20 changes: 11 additions & 9 deletions src/MobileUI/ViewModels/ProfileViewModels/ProfileViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public partial class ProfileViewModelBase : BaseViewModel, IRecipient<Achievemen
[ObservableProperty]
private bool _isLoading;

public bool ShowCamera => _isMe && !IsLoading;
[ObservableProperty]
private bool _isMe;

public ObservableCollection<ProfileCarouselViewModel> ProfileSections { get; set; } = new ObservableCollection<ProfileCarouselViewModel>();

Expand All @@ -50,8 +51,6 @@ public partial class ProfileViewModelBase : BaseViewModel, IRecipient<Achievemen

public bool ShowPopButton { get; set; } = false;

protected bool _isMe;

protected double _topRewardCost;

private readonly SemaphoreSlim _loadingProfileSectionsSemaphore = new(1,1);
Expand Down Expand Up @@ -129,15 +128,15 @@ protected async Task _initialise()

private void ProcessAchievement(ProfileAchievement achievement)
{
if (achievement.IsMe == _isMe)
if (achievement.IsMe == IsMe)
{
if (achievement.Complete)
{
ShowAchievementSnackbar(achievement);
}
else
{
if (achievement.Type == AchievementType.Linked && _isMe)
if (achievement.Type == AchievementType.Linked && IsMe)
{
var popup = new LinkSocial(achievement);
MopupService.Instance.PushAsync(popup);
Expand All @@ -152,6 +151,9 @@ private void ProcessAchievement(ProfileAchievement achievement)

private async Task ShowCameraPageAsync()
{
if (IsLoading)
return;

var popup = new CameraPage(new CameraPageViewModel(_userService));
//App.Current.MainPage.ShowPopup(popup);
await MopupService.Instance.PushAsync(popup);
Expand Down Expand Up @@ -188,7 +190,7 @@ protected async Task LoadProfileSections()

foreach (var achievement in profileAchievements)
{
achivementsSection.Achievements.Add(achievement.ToProfileAchievement(_isMe));
achivementsSection.Achievements.Add(achievement.ToProfileAchievement(IsMe));
}

ProfileSections.Add(achivementsSection);
Expand All @@ -197,7 +199,7 @@ protected async Task LoadProfileSections()

var activitySection = new ProfileCarouselViewModel();
activitySection.Type = CarouselType.RecentActivity;
activitySection.IsMe = _isMe;
activitySection.IsMe = IsMe;
activitySection.ProfileName = Name;

var activityList = new List<Activity>();
Expand Down Expand Up @@ -234,7 +236,7 @@ protected async Task LoadProfileSections()

// ===== Notifications =====

if (_isMe)
if (IsMe)
{
var notificationsSection = new ProfileCarouselViewModel();
notificationsSection.Type = CarouselType.Notifications;
Expand Down Expand Up @@ -287,7 +289,7 @@ private async void ShowAchievementSnackbar(ProfileAchievement achievement)

public string GetMessage(Achievement achievement, bool IsActivity = false)
{
string prefix = _isMe ? "You have" : $"{Name} has";
string prefix = IsMe ? "You have" : $"{Name} has";

if (!achievement.Complete)
{
Expand Down
10 changes: 8 additions & 2 deletions src/WebAPI/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ public async Task<ActionResult<UserAchievementsViewModel>> ProfileAchievements([
}

[HttpPost]
public async Task<ActionResult<ProfilePicResponseDto>> UploadProfilePic(Stream file)
public async Task<ActionResult<ProfilePicResponseDto>> UploadProfilePic()
{
return Ok(await Mediator.Send(new UploadProfilePicCommand { File = file }));
var file = HttpContext.Request.Form.Files["file"];
if (file == null || file.Length == 0)
{
return BadRequest("No file received");
}

return Ok(await Mediator.Send(new UploadProfilePicCommand { File = file.OpenReadStream() }));
}

[HttpGet]
Expand Down

0 comments on commit 92b9070

Please sign in to comment.