Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
Fix React Build by fixing ProfilePictureService
Browse files Browse the repository at this point in the history
  • Loading branch information
Nahlam4 committed Jun 10, 2024
1 parent c1794e5 commit e74ea3b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/web/src/organisms/create-comment/CreateComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,6 +38,9 @@ export const CreateComment: React.FC<CreateCommentProps> = ({ onReplyClick }) =>
if (image) {
setUserImage(image);
}
else {
setUserImage(getDefaultOrRandomPicture(true));
}
};
fetchUserProfileImage();
}, []);
Expand Down
4 changes: 4 additions & 0 deletions src/main/web/src/organisms/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<NotificationModel[]>([]);
Expand All @@ -29,6 +30,9 @@ export const Header = () => {
if (image) {
setUserImage(image);
}
else {
setUserImage(getDefaultOrRandomPicture(true));
}
};
fetchUserProfileImage();
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -23,6 +24,9 @@ export const CreatePost = () => {
if (image) {
setUserImage(image);
}
else {
setUserImage(getDefaultOrRandomPicture(true));
}
};
fetchUserProfileImage();
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +41,9 @@ export const PostDraft: React.FC<PostDraftProps> = (props: PostDraftProps) => {
if (image) {
setUserImage(image);
}
else {
setUserImage(getDefaultOrRandomPicture(true));
}
};
fetchUserProfileImage();
}, []);
Expand Down
4 changes: 2 additions & 2 deletions src/main/web/src/services/ProfilePictureService.tsx
Original file line number Diff line number Diff line change
@@ -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<string | null> => {
const jwt: string | null = getJWT();
Expand All @@ -20,7 +19,8 @@ export const fetchUserImage = async (): Promise<string | null> => {
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);
Expand Down

0 comments on commit e74ea3b

Please sign in to comment.