[frontend/pages] Use UserProfileEntity.AvatarAlt and .BannerAlt

This commit is contained in:
pancakes 2024-12-20 17:40:14 +10:00 committed by Laura Hausmann
parent 58d10228e9
commit d5b2ec15b8
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 17 additions and 23 deletions

View file

@ -10,12 +10,8 @@ internal class ProfileControllerModel(ApiClient api)
public Task<UserProfileEntity> GetProfileAsync() => public Task<UserProfileEntity> GetProfileAsync() =>
api.CallAsync<UserProfileEntity>(HttpMethod.Get, "/profile"); api.CallAsync<UserProfileEntity>(HttpMethod.Get, "/profile");
public Task UpdateProfileAsync(UserProfileEntity request, string? newAvatarAlt, string? newBannerAlt) => public Task UpdateProfileAsync(UserProfileEntity request) =>
api.CallAsync(HttpMethod.Put, "/profile", api.CallAsync(HttpMethod.Put, "/profile", data: request);
QueryString.Create(new Dictionary<string, string?>
{
{ "newAvatarAlt", newAvatarAlt }, { "newBannerAlt", newBannerAlt }
}), request);
public Task<DriveFileResponse> GetAvatarAsync() => public Task<DriveFileResponse> GetAvatarAsync() =>
api.CallAsync<DriveFileResponse>(HttpMethod.Get, "/profile/avatar"); api.CallAsync<DriveFileResponse>(HttpMethod.Get, "/profile/avatar");

View file

@ -38,7 +38,7 @@
@if (Banner != null || BannerFile != null) @if (Banner != null || BannerFile != null)
{ {
<label for="banner-alt">@(BannerFile != null ? Loc["Set alt text for your new banner"] : Loc["Set alt text for your banner"])</label> <label for="banner-alt">@(BannerFile != null ? Loc["Set alt text for your new banner"] : Loc["Set alt text for your banner"])</label>
<textarea class="input alt-text" @bind="BannerAlt" id="banner-alt" rows="3" placeholder="@Loc["Alt text"]" disabled="@DelBanner"></textarea> <textarea class="input alt-text" @bind="UserProfile.BannerAlt" id="banner-alt" rows="3" placeholder="@Loc["Alt text"]" disabled="@DelBanner"></textarea>
} }
</div> </div>
<div class="section"> <div class="section">
@ -55,7 +55,7 @@
@if (Avatar != null || AvatarFile != null) @if (Avatar != null || AvatarFile != null)
{ {
<label for="avatar-alt">@(AvatarFile != null ? Loc["Set alt text for your new avatar"] : Loc["Set alt text for your avatar"])</label> <label for="avatar-alt">@(AvatarFile != null ? Loc["Set alt text for your new avatar"] : Loc["Set alt text for your avatar"])</label>
<textarea class="input alt-text" @bind="AvatarAlt" id="avatar-alt" rows="3" placeholder="@Loc["Alt text"]" disabled="@DelAvatar"></textarea> <textarea class="input alt-text" @bind="UserProfile.AvatarAlt" id="avatar-alt" rows="3" placeholder="@Loc["Alt text"]" disabled="@DelAvatar"></textarea>
} }
</div> </div>
<div class="section"> <div class="section">
@ -149,10 +149,8 @@
private string FieldValue { get; set; } = ""; private string FieldValue { get; set; } = "";
private StateButton SaveButton { get; set; } = null!; private StateButton SaveButton { get; set; } = null!;
private IBrowserFile? AvatarFile { get; set; } = null; private IBrowserFile? AvatarFile { get; set; } = null;
private string? AvatarAlt { get; set; }
private bool DelAvatar { get; set; } = false; private bool DelAvatar { get; set; } = false;
private IBrowserFile? BannerFile { get; set; } = null; private IBrowserFile? BannerFile { get; set; } = null;
private string? BannerAlt { get; set; }
private bool DelBanner { get; set; } = false; private bool DelBanner { get; set; } = false;
private DateTime Birthday { get; set; } = DateTime.Now; private DateTime Birthday { get; set; } = DateTime.Now;
private bool SetBirthday { get; set; } = false; private bool SetBirthday { get; set; } = false;
@ -181,8 +179,8 @@
Avatar = await Api.Profile.GetAvatarAsync(); Avatar = await Api.Profile.GetAvatarAsync();
Banner = await Api.Profile.GetBannerAsync(); Banner = await Api.Profile.GetBannerAsync();
AvatarAlt = Avatar.Description; UserProfile.AvatarAlt = Avatar.Description;
BannerAlt = Banner.Description; UserProfile.BannerAlt = Banner.Description;
} }
catch (ApiException e) catch (ApiException e)
{ {
@ -217,26 +215,26 @@
if (DelAvatar) if (DelAvatar)
{ {
await Api.Profile.DeleteAvatarAsync(); await Api.Profile.DeleteAvatarAsync();
AvatarAlt = null; UserProfile.AvatarAlt = null;
} }
else if (AvatarFile != null) else if (AvatarFile != null)
{ {
await Api.Profile.UpdateAvatarAsync(AvatarFile, AvatarAlt); await Api.Profile.UpdateAvatarAsync(AvatarFile, UserProfile.AvatarAlt);
AvatarAlt = null; UserProfile.AvatarAlt = null;
} }
if (DelBanner) if (DelBanner)
{ {
await Api.Profile.DeleteBannerAsync(); await Api.Profile.DeleteBannerAsync();
BannerAlt = null; UserProfile.BannerAlt = null;
} }
else if (BannerFile != null) else if (BannerFile != null)
{ {
await Api.Profile.UpdateBannerAsync(BannerFile, BannerAlt); await Api.Profile.UpdateBannerAsync(BannerFile, UserProfile.BannerAlt);
BannerAlt = null; UserProfile.BannerAlt = null;
} }
await Api.Profile.UpdateProfileAsync(UserProfile, AvatarAlt, BannerAlt); await Api.Profile.UpdateProfileAsync(UserProfile);
SaveButton.State = StateButton.StateEnum.Success; SaveButton.State = StateButton.StateEnum.Success;
} }
catch (ApiException e) catch (ApiException e)
@ -249,13 +247,13 @@
private void OnAvatarFileChange(InputFileChangeEventArgs e) private void OnAvatarFileChange(InputFileChangeEventArgs e)
{ {
AvatarFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/")); AvatarFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/"));
AvatarAlt = ""; UserProfile.AvatarAlt = "";
} }
private void OnBannerFileChange(InputFileChangeEventArgs e) private void OnBannerFileChange(InputFileChangeEventArgs e)
{ {
BannerFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/")); BannerFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/"));
BannerAlt = ""; UserProfile.BannerAlt = "";
} }
private void ToggleEmojiPicker() private void ToggleEmojiPicker()