diff --git a/frontend/src/common.ts b/frontend/src/common.ts index a6190b26..f05485f4 100644 --- a/frontend/src/common.ts +++ b/frontend/src/common.ts @@ -33,7 +33,7 @@ export const getBotanicalInfoImg = (requestor: AxiosInstance, imageUrl?: string) export const isBackendReachable = (requestor: AxiosInstance): Promise => { return new Promise((resolve, _reject) => { - requestor.get("/info/ping") + requestor.get("info/ping") .then((_res) => resolve(true)) .catch((_err) => resolve(false)); }); diff --git a/frontend/src/components/Auth.tsx b/frontend/src/components/Auth.tsx index 7b934d84..ee27e052 100644 --- a/frontend/src/components/Auth.tsx +++ b/frontend/src/components/Auth.tsx @@ -131,11 +131,11 @@ export default function (props: { requestor: AxiosInstance; }) { isBackendReachable(props.requestor) .then((res) => { if (!res) { - setErrorDialogText("Backend not reachable"); + setErrorDialogText("Cannot connect to the backend"); setErrorDialogShown(true); } }); - }, [username, password]); + }, []); return ( boolean, requestor: Axio const [plants, setplants] = useState([]); const [logEntries, setLogEntries] = useState([]); const [activeTab, setActiveTab] = useState(0); - const [error, setError] = useState(); const [allEventTypes, setAllEventTypes] = useState([]); const logPageSize = 5; const [editEventVisible, setEditEventVisible] = useState(false); const [eventToEdit, setEventToEdit] = useState(); const [plantDetailsOpen, setPlantDetailsOpen] = useState(false); const [plantDetails, setPlantDetails] = useState(); + const [errorDialogShown, setErrorDialogShown] = useState(false); + const [errorDialogText, setErrorDialogText] = useState(); const getAllEntities = (): void => { props.requestor.get("plant/_count") @@ -225,6 +228,13 @@ export default function Home(props: { isLoggedIn: () => boolean, requestor: Axio if (!props.isLoggedIn()) { navigate("/auth"); } else { + isBackendReachable(props.requestor) + .then((res) => { + if (!res) { + setErrorDialogText("Cannot connect to the backend"); + setErrorDialogShown(true); + } + }); getDiaryEvents(); getAllEntities(); getLog(); @@ -237,6 +247,13 @@ export default function Home(props: { isLoggedIn: () => boolean, requestor: Axio return ( <> + + setErrorDialogShown(false)} + /> + boolean, requestor: Axio - +