From a07a16b38b7012e0ca496cf8caaa1dbd8757bbed Mon Sep 17 00:00:00 2001 From: AndreiD049 <52671223+AndreiD049@users.noreply.github.com> Date: Mon, 25 Oct 2021 22:06:32 +0300 Subject: [PATCH] fix: added possibility to revert back to default profile picture (#43962) * added possibility to revert to default profile picture * removed required from picture input * remove addPlaceholderImage and replaced with empty string * added test for empty string to avatar-renderer --- api-server/src/server/utils/index.js | 3 --- api-server/src/server/utils/publicUserProps.js | 3 +-- client/src/components/helpers/avatar-renderer.tsx | 2 +- client/src/components/settings/about.tsx | 6 ++++-- 4 files changed, 6 insertions(+), 8 deletions(-) delete mode 100644 api-server/src/server/utils/index.js diff --git a/api-server/src/server/utils/index.js b/api-server/src/server/utils/index.js deleted file mode 100644 index 22a76d5bbc..0000000000 --- a/api-server/src/server/utils/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.addPlaceholderImage = function addPlaceholderImage(name) { - return `https://example.com/${name}.png`; -}; diff --git a/api-server/src/server/utils/publicUserProps.js b/api-server/src/server/utils/publicUserProps.js index e73e1be05d..cd8199bc07 100644 --- a/api-server/src/server/utils/publicUserProps.js +++ b/api-server/src/server/utils/publicUserProps.js @@ -5,7 +5,6 @@ import { calcCurrentStreak, calcLongestStreak } from '../utils/user-stats'; -import { addPlaceholderImage } from './'; export const publicUserProps = [ 'about', @@ -62,7 +61,7 @@ export const userPropsForSession = [ export function normaliseUserFields(user) { const about = user.bio && !user.about ? user.bio : user.about; - const picture = user.picture || addPlaceholderImage(user.username); + const picture = user.picture || ''; const twitter = user.twitter && isURL(user.twitter) ? user.twitter diff --git a/client/src/components/helpers/avatar-renderer.tsx b/client/src/components/helpers/avatar-renderer.tsx index 362390d3fd..c72e2b6bae 100644 --- a/client/src/components/helpers/avatar-renderer.tsx +++ b/client/src/components/helpers/avatar-renderer.tsx @@ -33,7 +33,7 @@ function AvatarRenderer({ const isPlaceHolderImage = !isPictureValid || - /example.com|identicon.org/.test(picture) || + /example.com|identicon.org|^$/.test(picture) || picture === defaultUserImage; return ( diff --git a/client/src/components/settings/about.tsx b/client/src/components/settings/about.tsx index 6055ab50de..bfff042cfa 100644 --- a/client/src/components/settings/about.tsx +++ b/client/src/components/settings/about.tsx @@ -139,7 +139,10 @@ class AboutSettings extends Component { } loadEvent = () => this.setState({ isPictureUrlValid: true }); - errorEvent = () => this.setState({ isPictureUrlValid: false }); + errorEvent = () => + this.setState(state => ({ + isPictureUrlValid: state.formValues.picture === '' + })); handlePictureChange = (e: React.FormEvent) => { const value = (e.target as HTMLInputElement).value.slice(0); @@ -214,7 +217,6 @@ class AboutSettings extends Component {