Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check backend connection only on windows load #24

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getBotanicalInfoImg = (requestor: AxiosInstance, imageUrl?: string)

export const isBackendReachable = (requestor: AxiosInstance): Promise<boolean> => {
return new Promise((resolve, _reject) => {
requestor.get("/info/ping")
requestor.get("info/ping")
.then((_res) => resolve(true))
.catch((_err) => resolve(false));
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Box
Expand Down
21 changes: 19 additions & 2 deletions frontend/src/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Settings from "./Settings";
import secureLocalStorage from "react-secure-storage";
import EditEvent from "./EditEvent";
import PlantDetails from "./PlantDetails";
import { isBackendReachable } from "../common";
import ErrorDialog from "./ErrorDialog";


function UserTopBar(props: {}) {
Expand Down Expand Up @@ -165,13 +167,14 @@ export default function Home(props: { isLoggedIn: () => boolean, requestor: Axio
const [plants, setplants] = useState<plant[]>([]);
const [logEntries, setLogEntries] = useState<diaryEntry[]>([]);
const [activeTab, setActiveTab] = useState<number>(0);
const [error, setError] = useState<string>();
const [allEventTypes, setAllEventTypes] = useState<string[]>([]);
const logPageSize = 5;
const [editEventVisible, setEditEventVisible] = useState<boolean>(false);
const [eventToEdit, setEventToEdit] = useState<diaryEntry>();
const [plantDetailsOpen, setPlantDetailsOpen] = useState<boolean>(false);
const [plantDetails, setPlantDetails] = useState<plant>();
const [errorDialogShown, setErrorDialogShown] = useState<boolean>(false);
const [errorDialogText, setErrorDialogText] = useState<string>();

const getAllEntities = (): void => {
props.requestor.get("plant/_count")
Expand Down Expand Up @@ -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();
Expand All @@ -237,6 +247,13 @@ export default function Home(props: { isLoggedIn: () => boolean, requestor: Axio

return (
<>

<ErrorDialog
text={errorDialogText}
open={errorDialogShown}
close={() => setErrorDialogShown(false)}
/>

<EditEvent
requestor={props.requestor}
plants={plants}
Expand Down Expand Up @@ -303,7 +320,7 @@ export default function Home(props: { isLoggedIn: () => boolean, requestor: Axio
</Box>

<Box sx={{ display: activeTab === 3 ? "visible" : "none" }}>
<Settings requestor={props.requestor} visibility={activeTab === 3}/>
<Settings requestor={props.requestor} visibility={activeTab === 3} />
</Box>
</Box>

Expand Down
Loading