[frontend/pages] Add update avatar and banner to profile settings
This commit is contained in:
parent
d56b7760df
commit
6656fbac18
2 changed files with 25 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
using Iceshrimp.Frontend.Core.Services;
|
using Iceshrimp.Frontend.Core.Services;
|
||||||
using Iceshrimp.Shared.Schemas.Web;
|
using Iceshrimp.Shared.Schemas.Web;
|
||||||
|
using Microsoft.AspNetCore.Components.Forms;
|
||||||
|
|
||||||
namespace Iceshrimp.Frontend.Core.ControllerModels;
|
namespace Iceshrimp.Frontend.Core.ControllerModels;
|
||||||
|
|
||||||
|
@ -14,12 +15,18 @@ internal class ProfileControllerModel(ApiClient api)
|
||||||
public Task<string> GetAvatarUrlAsync() =>
|
public Task<string> GetAvatarUrlAsync() =>
|
||||||
api.CallAsync<string>(HttpMethod.Get, "/profile/avatar");
|
api.CallAsync<string>(HttpMethod.Get, "/profile/avatar");
|
||||||
|
|
||||||
|
public Task UpdateAvatarAsync(IBrowserFile file) =>
|
||||||
|
api.CallAsync(HttpMethod.Post, "/profile/avatar", data: file);
|
||||||
|
|
||||||
public Task DeleteAvatarAsync() =>
|
public Task DeleteAvatarAsync() =>
|
||||||
api.CallAsync(HttpMethod.Delete, "/profile/avatar");
|
api.CallAsync(HttpMethod.Delete, "/profile/avatar");
|
||||||
|
|
||||||
public Task<string> GetBannerUrlAsync() =>
|
public Task<string> GetBannerUrlAsync() =>
|
||||||
api.CallAsync<string>(HttpMethod.Get, "/profile/banner");
|
api.CallAsync<string>(HttpMethod.Get, "/profile/banner");
|
||||||
|
|
||||||
|
public Task UpdateBannerAsync(IBrowserFile file) =>
|
||||||
|
api.CallAsync(HttpMethod.Post, "/profile/banner", data: file);
|
||||||
|
|
||||||
public Task DeleteBannerAsync() =>
|
public Task DeleteBannerAsync() =>
|
||||||
api.CallAsync(HttpMethod.Delete, "/profile/banner");
|
api.CallAsync(HttpMethod.Delete, "/profile/banner");
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
<label for="delete-banner">@Loc["Remove Banner"]</label>
|
<label for="delete-banner">@Loc["Remove Banner"]</label>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
<InputFile class="input" OnChange="OnBannerFileChange" accept="image/*" disabled="@DelBanner"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h3>@Loc["Avatar"]</h3>
|
<h3>@Loc["Avatar"]</h3>
|
||||||
|
@ -43,6 +44,7 @@
|
||||||
<label for="delete-avatar">@Loc["Remove Avatar"]</label>
|
<label for="delete-avatar">@Loc["Remove Avatar"]</label>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
<InputFile class="input" OnChange="OnAvatarFileChange" accept="image/*" disabled="@DelAvatar"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h3>@Loc["Display Name"]</h3><input class="input" @bind="@DisplayName"/>
|
<h3>@Loc["Display Name"]</h3><input class="input" @bind="@DisplayName"/>
|
||||||
|
@ -109,8 +111,10 @@
|
||||||
private string FieldName { get; set; } = "";
|
private string FieldName { get; set; } = "";
|
||||||
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 string? AvatarUrl { get; set; } = null;
|
private string? AvatarUrl { get; set; } = null;
|
||||||
private bool DelAvatar { get; set; } = false;
|
private bool DelAvatar { get; set; } = false;
|
||||||
|
private IBrowserFile? BannerFile { get; set; } = null;
|
||||||
private string? BannerUrl { get; set; } = null;
|
private string? BannerUrl { get; set; } = null;
|
||||||
private bool DelBanner { get; set; } = false;
|
private bool DelBanner { get; set; } = false;
|
||||||
private string DisplayName { get; set; } = "";
|
private string DisplayName { get; set; } = "";
|
||||||
|
@ -153,8 +157,12 @@
|
||||||
await Api.Profile.UpdateDisplayNameAsync(DisplayName);
|
await Api.Profile.UpdateDisplayNameAsync(DisplayName);
|
||||||
if (DelAvatar)
|
if (DelAvatar)
|
||||||
await Api.Profile.DeleteAvatarAsync();
|
await Api.Profile.DeleteAvatarAsync();
|
||||||
|
else if (AvatarFile != null)
|
||||||
|
await Api.Profile.UpdateAvatarAsync(AvatarFile);
|
||||||
if (DelBanner)
|
if (DelBanner)
|
||||||
await Api.Profile.DeleteBannerAsync();
|
await Api.Profile.DeleteBannerAsync();
|
||||||
|
else if (BannerFile != null)
|
||||||
|
await Api.Profile.UpdateBannerAsync(BannerFile);
|
||||||
SaveButton.State = StateButton.StateEnum.Success;
|
SaveButton.State = StateButton.StateEnum.Success;
|
||||||
}
|
}
|
||||||
catch (ApiException e)
|
catch (ApiException e)
|
||||||
|
@ -163,4 +171,14 @@
|
||||||
SaveButton.State = StateButton.StateEnum.Failed;
|
SaveButton.State = StateButton.StateEnum.Failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnAvatarFileChange(InputFileChangeEventArgs e)
|
||||||
|
{
|
||||||
|
AvatarFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBannerFileChange(InputFileChangeEventArgs e)
|
||||||
|
{
|
||||||
|
BannerFile = e.GetMultipleFiles().First(p => p.ContentType.StartsWith("image/"));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue