From e74ea3be6afec3548df6a23a6da7d93e9776160f Mon Sep 17 00:00:00 2001 From: Nahlam4 Date: Mon, 10 Jun 2024 17:24:00 +0200 Subject: [PATCH] Fix React Build by fixing ProfilePictureService --- src/main/web/src/organisms/create-comment/CreateComment.tsx | 4 ++++ src/main/web/src/organisms/header/Header.tsx | 4 ++++ .../web/src/scenes/Home/components/create-post/CreatePost.tsx | 4 ++++ .../web/src/scenes/Home/components/create-post/PostDraft.tsx | 4 ++++ src/main/web/src/services/ProfilePictureService.tsx | 4 ++-- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/web/src/organisms/create-comment/CreateComment.tsx b/src/main/web/src/organisms/create-comment/CreateComment.tsx index 0a715632..3c8027ee 100644 --- a/src/main/web/src/organisms/create-comment/CreateComment.tsx +++ b/src/main/web/src/organisms/create-comment/CreateComment.tsx @@ -5,6 +5,7 @@ import {fetchUserImage} from "../../services/ProfilePictureService"; import config from "../../config/config"; import {isUserLoggedIn} from "../../services/AuthService"; import {Tooltip} from "react-tooltip"; +import {getDefaultOrRandomPicture} from "../../atoms/Pictures/PicturesComponent"; interface CreateCommentProps { onReplyClick: (newCommentText: string) => void; @@ -37,6 +38,9 @@ export const CreateComment: React.FC = ({ onReplyClick }) => if (image) { setUserImage(image); } + else { + setUserImage(getDefaultOrRandomPicture(true)); + } }; fetchUserProfileImage(); }, []); diff --git a/src/main/web/src/organisms/header/Header.tsx b/src/main/web/src/organisms/header/Header.tsx index 52a2694f..cb1d9891 100644 --- a/src/main/web/src/organisms/header/Header.tsx +++ b/src/main/web/src/organisms/header/Header.tsx @@ -11,6 +11,7 @@ import config from "../../config/config"; import {fetchUserImage} from "../../services/ProfilePictureService"; import {fetchNotifications} from "../../services/NotificationsService"; import {NotificationModel} from "./model/NotificationModel"; +import {getDefaultOrRandomPicture} from "../../atoms/Pictures/PicturesComponent"; export const Header = () => { const [notifications, setNotifications] = useState([]); @@ -29,6 +30,9 @@ export const Header = () => { if (image) { setUserImage(image); } + else { + setUserImage(getDefaultOrRandomPicture(true)); + } }; fetchUserProfileImage(); }, []); diff --git a/src/main/web/src/scenes/Home/components/create-post/CreatePost.tsx b/src/main/web/src/scenes/Home/components/create-post/CreatePost.tsx index 9dde47ff..009c9333 100644 --- a/src/main/web/src/scenes/Home/components/create-post/CreatePost.tsx +++ b/src/main/web/src/scenes/Home/components/create-post/CreatePost.tsx @@ -6,6 +6,7 @@ import {fetchUserImage} from "../../../../services/ProfilePictureService"; import {isUserLoggedIn} from "../../../../services/AuthService"; import {Tooltip} from "react-tooltip"; import config from "../../../../config/config"; +import {getDefaultOrRandomPicture} from "../../../../atoms/Pictures/PicturesComponent"; export const CreatePost = () => { const [draftOpen, setDraftOpen] = useState(false); @@ -23,6 +24,9 @@ export const CreatePost = () => { if (image) { setUserImage(image); } + else { + setUserImage(getDefaultOrRandomPicture(true)); + } }; fetchUserProfileImage(); }, []); diff --git a/src/main/web/src/scenes/Home/components/create-post/PostDraft.tsx b/src/main/web/src/scenes/Home/components/create-post/PostDraft.tsx index b5c30f90..2636c321 100644 --- a/src/main/web/src/scenes/Home/components/create-post/PostDraft.tsx +++ b/src/main/web/src/scenes/Home/components/create-post/PostDraft.tsx @@ -12,6 +12,7 @@ import config from "../../../../config/config"; import { getAccountId, getJWT } from "../../../../services/AuthService"; import { handleTagInput } from "../../../../services/TagService"; import {fetchUserImage} from "../../../../services/ProfilePictureService"; +import {getDefaultOrRandomPicture} from "../../../../atoms/Pictures/PicturesComponent"; interface PostDraftProps { draftOpen: boolean; @@ -40,6 +41,9 @@ export const PostDraft: React.FC = (props: PostDraftProps) => { if (image) { setUserImage(image); } + else { + setUserImage(getDefaultOrRandomPicture(true)); + } }; fetchUserProfileImage(); }, []); diff --git a/src/main/web/src/services/ProfilePictureService.tsx b/src/main/web/src/services/ProfilePictureService.tsx index 183ba225..5521bf8d 100644 --- a/src/main/web/src/services/ProfilePictureService.tsx +++ b/src/main/web/src/services/ProfilePictureService.tsx @@ -1,6 +1,5 @@ import config from "../config/config"; import { getJWT, getUserId, isUserLoggedIn } from "./AuthService"; -import {getDefaultOrRandomPicture} from "../atoms/Pictures/PicturesComponent"; export const fetchUserImage = async (): Promise => { const jwt: string | null = getJWT(); @@ -20,7 +19,8 @@ export const fetchUserImage = async (): Promise => { localStorage.setItem('userImage', data.imageData); return data.imageData; } else { - return (getDefaultOrRandomPicture(true)); + console.error("Failed to fetch user image"); + return null; } } catch (error) { console.error("Error fetching user image:", error);