From b44e43a5b6dc80cbe002b20925735377a5372dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Tue, 2 Jul 2024 15:19:20 +0200 Subject: [PATCH] fix(frontend): do not use backend url in (#2424) * fronted: do not use backend url in * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../src/components/headerComponent/index.tsx | 27 ++++--------------- .../chatView/fileComponent/index.tsx | 5 +--- .../fileComponent/utils/handle-download.tsx | 7 +---- .../hooks/use-preload-images.tsx | 8 ++---- .../profilePictureChooserComponent/index.tsx | 10 ++----- 5 files changed, 11 insertions(+), 46 deletions(-) diff --git a/src/frontend/src/components/headerComponent/index.tsx b/src/frontend/src/components/headerComponent/index.tsx index 52818f9407c..d03ff4f9507 100644 --- a/src/frontend/src/components/headerComponent/index.tsx +++ b/src/frontend/src/components/headerComponent/index.tsx @@ -5,7 +5,6 @@ import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; import AlertDropdown from "../../alerts/alertDropDown"; import profileCircle from "../../assets/profile-circle.png"; import { - BACKEND_URL, BASE_URL_API, LOCATIONS_TO_RETURN, USER_PROJECTS_HEADER, @@ -50,11 +49,9 @@ export default function Header(): JSX.Element { const routeHistory = useLocationStore((state) => state.routeHistory); const profileImageUrl = - `${BACKEND_URL.slice( - 0, - BACKEND_URL.length - 1, - )}${BASE_URL_API}files/profile_pictures/${userData?.profile_image}` ?? - profileCircle; + `${BASE_URL_API}files/profile_pictures/${ + userData?.profile_image ?? "Space/046-rocket.svg" + }` ?? profileCircle; async function checkForChanges(): Promise { if (nodes.length === 0) { await removeFlow(id!); @@ -202,14 +199,7 @@ export default function Header(): JSX.Element { className="shrink-0" > @@ -220,14 +210,7 @@ export default function Header(): JSX.Element {
diff --git a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx index fa9c505ea1e..17708aa3f89 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx @@ -27,10 +27,7 @@ export default function FileCard({ const fileWrapperClasses = getClasses(isHovered); - const imgSrc = `${BACKEND_URL.slice( - 0, - BACKEND_URL.length - 1, - )}${BASE_URL_API}files/images/${content}`; + const imgSrc = `${BASE_URL_API}files/images/${content}`; if (showFile) { if (imgTypes.has(fileType)) { diff --git a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/utils/handle-download.tsx b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/utils/handle-download.tsx index a4be91d5044..53a9cf7705f 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/utils/handle-download.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/utils/handle-download.tsx @@ -17,12 +17,7 @@ export default async function handleDownload({ try { isDownloading = true; - const response = await fetch( - `${BACKEND_URL.slice( - 0, - BACKEND_URL.length - 1, - )}${BASE_URL_API}files/download/${content}`, - ); + const response = await fetch(`${BASE_URL_API}files/download/${content}`); if (!response.ok) { throw new Error("Network response was not ok"); } diff --git a/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/components/profilePictureChooserComponent/hooks/use-preload-images.tsx b/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/components/profilePictureChooserComponent/hooks/use-preload-images.tsx index abc8587d20a..df1ee2dd23d 100644 --- a/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/components/profilePictureChooserComponent/hooks/use-preload-images.tsx +++ b/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/components/profilePictureChooserComponent/hooks/use-preload-images.tsx @@ -1,8 +1,5 @@ import { useEffect } from "react"; -import { - BACKEND_URL, - BASE_URL_API, -} from "../../../../../../../../../constants/constants"; +import { BASE_URL_API } from "../../../../../../../../../constants/constants"; const usePreloadImages = ( profilePictures: { [key: string]: string[] }, @@ -24,12 +21,11 @@ const usePreloadImages = ( useEffect(() => { const imageArray: string[] = []; - const firstUrl = `${BACKEND_URL.slice(0, BACKEND_URL.length - 1)}`; Object.keys(profilePictures).flatMap((folder) => profilePictures[folder].map((path) => imageArray.push( - `${firstUrl}${BASE_URL_API}files/profile_pictures/${folder}/${path}`, + `${BASE_URL_API}files/profile_pictures/${folder}/${path}`, ), ), ); diff --git a/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/components/profilePictureChooserComponent/index.tsx b/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/components/profilePictureChooserComponent/index.tsx index ac6a215be90..3b00d236570 100644 --- a/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/components/profilePictureChooserComponent/index.tsx +++ b/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/components/profilePictureChooserComponent/index.tsx @@ -1,10 +1,7 @@ import { useEffect, useRef, useState } from "react"; import { Button } from "../../../../../../../../components/ui/button"; import Loading from "../../../../../../../../components/ui/loading"; -import { - BACKEND_URL, - BASE_URL_API, -} from "../../../../../../../../constants/constants"; +import { BASE_URL_API } from "../../../../../../../../constants/constants"; import { useDarkStore } from "../../../../../../../../stores/darkStore"; import { cn } from "../../../../../../../../utils/utils"; import usePreloadImages from "./hooks/use-preload-images"; @@ -55,10 +52,7 @@ export default function ProfilePictureChooserComponent({ >