[frontend/pages] Use UserProfileEntity.AvatarAlt and .BannerAlt
This commit is contained in:
parent
58d10228e9
commit
d5b2ec15b8
2 changed files with 17 additions and 23 deletions
|
@ -10,12 +10,8 @@ internal class ProfileControllerModel(ApiClient api)
|
|||
public Task<UserProfileEntity> GetProfileAsync() =>
|
||||
api.CallAsync<UserProfileEntity>(HttpMethod.Get, "/profile");
|
||||
|
||||
public Task UpdateProfileAsync(UserProfileEntity request, string? newAvatarAlt, string? newBannerAlt) =>
|
||||
api.CallAsync(HttpMethod.Put, "/profile",
|
||||
QueryString.Create(new Dictionary<string, string?>
|
||||
{
|
||||
{ "newAvatarAlt", newAvatarAlt }, { "newBannerAlt", newBannerAlt }
|
||||
}), request);
|
||||
public Task UpdateProfileAsync(UserProfileEntity request) =>
|
||||
api.CallAsync(HttpMethod.Put, "/profile", data: request);
|
||||
|
||||
public Task<DriveFileResponse> GetAvatarAsync() =>
|
||||
api.CallAsync<DriveFileResponse>(HttpMethod.Get, "/profile/avatar");
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
@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>
|
||||
<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 class="section">
|
||||
|
@ -55,7 +55,7 @@
|
|||
@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>
|
||||
<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 class="section">
|
||||
|
@ -149,10 +149,8 @@
|
|||
private string FieldValue { get; set; } = "";
|
||||
private StateButton SaveButton { get; set; } = null!;
|
||||
private IBrowserFile? AvatarFile { get; set; } = null;
|
||||
private string? AvatarAlt { get; set; }
|
||||
private bool DelAvatar { get; set; } = false;
|
||||
private IBrowserFile? BannerFile { get; set; } = null;
|
||||
private string? BannerAlt { get; set; }
|
||||
private bool DelBanner { get; set; } = false;
|
||||
private DateTime Birthday { get; set; } = DateTime.Now;
|
||||
private bool SetBirthday { get; set; } = false;
|
||||
|
@ -181,8 +179,8 @@
|
|||
Avatar = await Api.Profile.GetAvatarAsync();
|
||||
Banner = await Api.Profile.GetBannerAsync();
|
||||
|
||||
AvatarAlt = Avatar.Description;
|
||||
BannerAlt = Banner.Description;
|
||||
UserProfile.AvatarAlt = Avatar.Description;
|
||||
UserProfile.BannerAlt = Banner.Description;
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
|
@ -217,26 +215,26 @@
|
|||
if (DelAvatar)
|
||||
{
|
||||
await Api.Profile.DeleteAvatarAsync();
|
||||
AvatarAlt = null;
|
||||
UserProfile.AvatarAlt = null;
|
||||
}
|
||||
else if (AvatarFile != null)
|
||||
{
|
||||
await Api.Profile.UpdateAvatarAsync(AvatarFile, AvatarAlt);
|
||||
AvatarAlt = null;
|
||||
await Api.Profile.UpdateAvatarAsync(AvatarFile, UserProfile.AvatarAlt);
|
||||
UserProfile.AvatarAlt = null;
|
||||
}
|
||||
|
||||
if (DelBanner)
|
||||
{
|
||||
await Api.Profile.DeleteBannerAsync();
|
||||
BannerAlt = null;
|
||||
UserProfile.BannerAlt = null;
|
||||
}
|
||||
else if (BannerFile != null)
|
||||
{
|
||||
await Api.Profile.UpdateBannerAsync(BannerFile, BannerAlt);
|
||||
BannerAlt = null;
|
||||
await Api.Profile.UpdateBannerAsync(BannerFile, UserProfile.BannerAlt);
|
||||
UserProfile.BannerAlt = null;
|
||||
}
|
||||
|
||||
await Api.Profile.UpdateProfileAsync(UserProfile, AvatarAlt, BannerAlt);
|
||||
await Api.Profile.UpdateProfileAsync(UserProfile);
|
||||
SaveButton.State = StateButton.StateEnum.Success;
|
||||
}
|
||||
catch (ApiException e)
|
||||
|
@ -248,14 +246,14 @@
|
|||
|
||||
private void OnAvatarFileChange(InputFileChangeEventArgs e)
|
||||
{
|
||||
AvatarFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/"));
|
||||
AvatarAlt = "";
|
||||
AvatarFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/"));
|
||||
UserProfile.AvatarAlt = "";
|
||||
}
|
||||
|
||||
private void OnBannerFileChange(InputFileChangeEventArgs e)
|
||||
{
|
||||
BannerFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/"));
|
||||
BannerAlt = "";
|
||||
BannerFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/"));
|
||||
UserProfile.BannerAlt = "";
|
||||
}
|
||||
|
||||
private void ToggleEmojiPicker()
|
||||
|
|
Loading…
Add table
Reference in a new issue