From 2714af1eeb8f460b4d42c85ef7bec80b217dc3ea Mon Sep 17 00:00:00 2001 From: theiereman <141121240+theiereman@users.noreply.github.com> Date: Mon, 1 Jul 2024 12:30:27 +0200 Subject: [PATCH] impr(server): trim consecutive newlines when updating user profile (theiereman) (#5538) --- backend/src/api/controllers/user.ts | 2 +- backend/src/utils/misc.ts | 1 + frontend/src/ts/ape/endpoints/users.ts | 2 +- frontend/src/ts/modals/edit-profile.ts | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/src/api/controllers/user.ts b/backend/src/api/controllers/user.ts index 304cc8008..931b4a7f7 100644 --- a/backend/src/api/controllers/user.ts +++ b/backend/src/api/controllers/user.ts @@ -847,7 +847,7 @@ export async function updateProfile( await UserDAL.updateProfile(uid, profileDetailsUpdates, user.inventory); - return new MonkeyResponse("Profile updated"); + return new MonkeyResponse("Profile updated", profileDetailsUpdates); } export async function getInbox( diff --git a/backend/src/utils/misc.ts b/backend/src/utils/misc.ts index e5177a75d..46dc856ad 100644 --- a/backend/src/utils/misc.ts +++ b/backend/src/utils/misc.ts @@ -160,6 +160,7 @@ export function sanitizeString(str: string | undefined): string | undefined { return str .replace(/[\u0300-\u036F]/g, "") .trim() + .replace(/\n{3,}/g, "\n\n") .replace(/\s{3,}/g, " "); } diff --git a/frontend/src/ts/ape/endpoints/users.ts b/frontend/src/ts/ape/endpoints/users.ts index 1297745d7..f6b095b83 100644 --- a/frontend/src/ts/ape/endpoints/users.ts +++ b/frontend/src/ts/ape/endpoints/users.ts @@ -221,7 +221,7 @@ export default class Users { async updateProfile( profileUpdates: Partial, selectedBadgeId?: number - ): Ape.EndpointResponse { + ): Ape.EndpointResponse { return await this.httpClient.patch(`${BASE_PATH}/profile`, { payload: { ...profileUpdates, diff --git a/frontend/src/ts/modals/edit-profile.ts b/frontend/src/ts/modals/edit-profile.ts index c50af841c..b179968fb 100644 --- a/frontend/src/ts/modals/edit-profile.ts +++ b/frontend/src/ts/modals/edit-profile.ts @@ -158,7 +158,7 @@ async function updateProfile(): Promise { return; } - snapshot.details = updates; + snapshot.details = response.data ?? updates; snapshot.inventory?.badges.forEach((badge) => { if (badge.id === currentSelectedBadgeId) { badge.selected = true;