[frontend] Add display name to profile settings

This commit is contained in:
pancakes 2024-11-27 23:17:42 +10:00 committed by Laura Hausmann
parent 6605997e80
commit 95cd3d2d33
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 12 additions and 0 deletions

View file

@ -10,4 +10,10 @@ internal class ProfileControllerModel(ApiClient api)
public Task UpdateProfileAsync(UserProfileEntity request) =>
api.CallAsync(HttpMethod.Put, "/profile", data: request);
public Task<string?> GetDisplayNameAsync() =>
api.CallNullableAsync<string>(HttpMethod.Get, "/profile/display_name");
public Task<string?> UpdateDisplayNameAsync(string displayName) =>
api.CallNullableAsync<string>(HttpMethod.Post, "/profile/display_name", data: displayName);
}

View file

@ -22,6 +22,9 @@
<div class="body">
@if (State is State.Loaded)
{
<div class="section">
<h3>@Loc["Display Name"]</h3><input class="input" @bind="@DisplayName"></input>
</div>
<div class="section">
<h3>@Loc["Profile Description"]</h3><textarea class="input" @bind="@UserProfile.Description"></textarea>
</div>
@ -84,6 +87,7 @@
private string FieldName { get; set; } = "";
private string FieldValue { get; set; } = "";
private StateButton SaveButton { get; set; } = null!;
private string DisplayName { get; set; } = "";
protected override async Task OnInitializedAsync()
{
@ -91,6 +95,7 @@
{
UserProfile = await Api.Profile.GetProfileAsync();
State = State.Loaded;
DisplayName = await Api.Profile.GetDisplayNameAsync() ?? "";
}
catch (ApiException e)
{
@ -117,6 +122,7 @@
{
SaveButton.State = StateButton.StateEnum.Loading;
await Api.Profile.UpdateProfileAsync(UserProfile);
await Api.Profile.UpdateDisplayNameAsync(DisplayName);
SaveButton.State = StateButton.StateEnum.Success;
}
catch (ApiException e)