Skip to content

Commit

Permalink
fix: little improvements
Browse files Browse the repository at this point in the history
- add missing event types colors and icons
- add skeleton for image loading in the "add plant" window
- little improvements
  • Loading branch information
MDeLuise committed Sep 11, 2023
1 parent e676f55 commit 39fd9c3
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 50 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ The application was developed with being used with Docker in mind, thus this met
1. Run the following command in the terminal inside the `frontend` folder
`npm start`

Then, the frontend of the system will be available at `http://localhost:3000`, and the backend at `http://localhost:8085/api`.
Then, the frontend of the system will be available at `http://localhost:3000`, and the backend at `http://localhost:8080/api`.


#### Change port binding
Expand Down Expand Up @@ -212,8 +212,8 @@ To fix a bug or create a feature, follow these steps:
* Commits should follow the [semantic commit](https://www.conventionalcommits.org/en/v1.0.0/) specification, although not mandatory.

#### Local environment
If you want to make some changes in the project, you can use the following commands:
* in order to run the frontend: `cd frontend`, then `npm run dev`.
* in order to run the backend: `cd backend`, then `./mvnw spring-boot:run -Dspring-boot.run.profiles=dev -DcopyFiles`. This enables the `dev` profile, which uses an embedded h2 database instead of one external mysql instance, and creates a user with username `user` and password `user` with a predefined plant's collection. Also a dummy user uploaded image is copied under `/tmp/plant-it/` directory.
If you want to test some changes in the project, you can use the following commands:
* in order to run the frontend: `cd frontend`, then `npm run dev` (available at `localhost:3000` by default).
* in order to run the backend: `cd backend`, then `./mvnw spring-boot:run -Dspring-boot.run.profiles=dev -DcopyFiles` (available at `localhost:8085` by default). This enables the `dev` profile, which uses an embedded h2 database instead of one external mysql instance, and creates a user with username `user` and password `user` with a predefined plant's collection. Also a dummy user uploaded image is copied under `/tmp/plant-it/` directory.

Consider that this environment speed up the developing process, but the app should be tested (at least for new big features) even without the `dev` backend profile and with a local docker deployment.
79 changes: 50 additions & 29 deletions frontend/src/components/AddPlant.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Button, Divider, Drawer, Switch, TextField } from "@mui/material";
import { Box, Button, Divider, Drawer, Skeleton, Switch, TextField } from "@mui/material";
import { AxiosInstance } from "axios";
import { botanicalInfo, plant } from "../interfaces";
import { useEffect, useState } from "react";
Expand All @@ -16,16 +16,17 @@ export default function AddPlant(props: {
name?: string,
printError: (err: any) => void;
}) {
const [plantName, setPlantName] = useState<string>();
const [plantName, setPlantName] = useState<string>("");
const [plantNameError, setPlantNameError] = useState<string>();
const [family, setFamily] = useState<string>();
const [genus, setGenus] = useState<string>();
const [species, setSpecies] = useState<string>();
const [date, setDate] = useState<Dayjs | null>(dayjs(new Date()));
const [family, setFamily] = useState<string>("");
const [genus, setGenus] = useState<string>("");
const [species, setSpecies] = useState<string>("");
const [date, setDate] = useState<Dayjs>(dayjs(new Date()));
const [useDate, setUseDate] = useState<boolean>(true);
const [selectedImage, setSelectedImage] = useState<File>();
const [downloadedImg, setDownloadedImg] = useState<string>();
const [imageDownloaded, setImageDownloaded] = useState<boolean>(false);
const [imageLoaded, setImageLoaded] = useState<boolean>(false);

const readImage = (imageUrl: string): void => {
props.requestor.get(`image/content${imageUrl}`)
Expand All @@ -47,6 +48,9 @@ export default function AddPlant(props: {
};

const setImageSrc = (): string => {
if (!props.open) {
return "";
}
return imageDownloaded ? `data:application/octet-stream;base64,${downloadedImg}` :
setAbsoluteImageUrl(props.entity?.imageUrl, process.env.PUBLIC_URL);
};
Expand Down Expand Up @@ -152,7 +156,7 @@ export default function AddPlant(props: {
scientificName: plantName,
family: family,
genus: genus,
species: species != undefined ? species : plantName,
species: species != "" ? species : plantName,
isSystemWide: false,
};
let plantToAdd = {
Expand Down Expand Up @@ -213,10 +217,12 @@ export default function AddPlant(props: {
};

const cleanup = (): void => {
setImageLoaded(false);
setSelectedImage(undefined);
setDownloadedImg(undefined);
setFamily(undefined);
setGenus(undefined);
setImageDownloaded(false);
setFamily("");
setGenus("");
setPlantName("");
setUseDate(true);
setDate(dayjs(new Date()));
Expand All @@ -230,7 +236,7 @@ export default function AddPlant(props: {

useEffect(() => {
setImageDownloaded(false);
setImageSrc();
props.open && setImageSrc();
setName();
}, [props.entity, props.name, props.open]);

Expand Down Expand Up @@ -279,18 +285,30 @@ export default function AddPlant(props: {
position: "relative",
}}>
{
props.entity != undefined &&
!imageLoaded && props.entity !== undefined &&
<Skeleton
variant="rounded"
animation="wave"
sx={{
width: "100%",
height: "100%",
}}
/>
}
{
props.entity != undefined && props.open &&
<img
src={imgSrc}
style={{
height: "100%",
width: "100%",
objectFit: "cover"
}}
onLoad={() => setImageLoaded(true)}
/>
}
{
selectedImage != undefined &&
selectedImage != undefined && props.open &&
<>
<Box
style={{
Expand All @@ -312,19 +330,22 @@ export default function AddPlant(props: {
</Box>
</>
}
<Box sx={{
backgroundColor: "primary.main",
width: "100%",
height: "100%",
justifyContent: "center",
alignItems: "center",
display: selectedImage == undefined ? "flex" : "none",
}}
onClick={() => {
document.getElementById("upload-image")?.click();
}}>
<AddPhotoAlternateOutlinedIcon fontSize="large" />
</Box>
{
props.entity == undefined &&
<Box sx={{
backgroundColor: "primary.main",
width: "100%",
height: "100%",
justifyContent: "center",
alignItems: "center",
display: selectedImage == undefined ? "flex" : "none",
}}
onClick={() => {
document.getElementById("upload-image")?.click();
}}>
<AddPhotoAlternateOutlinedIcon fontSize="large" />
</Box>
}

</Box>
<TextField
Expand Down Expand Up @@ -353,7 +374,7 @@ export default function AddPlant(props: {
label="Date of purchase"
value={date}
disabled={!useDate}
onChange={(newValue) => setDate(newValue)}
onChange={(newValue) => setDate(newValue != undefined ? newValue : dayjs(new Date()))}
sx={{
flexGrow: 1
}}
Expand All @@ -366,23 +387,23 @@ export default function AddPlant(props: {
disabled={props.entity != undefined}
label="Family"
fullWidth
value={props.entity?.family}
value={props.entity?.family != undefined ? props.entity?.family : ""}
onChange={(event) => setFamily(event.target.value)}
/>
<TextField
variant="outlined"
disabled={props.entity != undefined}
fullWidth
label="Genus"
value={props.entity?.genus}
value={props.entity?.genus != undefined ? props.entity?.genus : ""}
onChange={(event) => setGenus(event.target.value)}
/>
<TextField
variant="outlined"
disabled={props.entity != undefined}
fullWidth
label="Species"
value={props.entity?.species}
value={props.entity?.species != undefined ? props.entity?.species : ""}
onChange={(event) => setSpecies(event.target.value)}
/>

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Auth.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { AxiosError, AxiosInstance } from 'axios';
import { AxiosInstance } from 'axios';
import { NavigateFunction, useNavigate } from "react-router";
import secureLocalStorage from "react-secure-storage";
import Avatar from '@mui/material/Avatar';
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/components/LogEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import AutorenewOutlinedIcon from '@mui/icons-material/AutorenewOutlined';
import QuestionMarkOutlinedIcon from '@mui/icons-material/QuestionMarkOutlined';
import LunchDiningOutlinedIcon from '@mui/icons-material/LunchDiningOutlined';
import BatterySaverOutlinedIcon from '@mui/icons-material/BatterySaverOutlined';
import VisibilityOutlinedIcon from '@mui/icons-material/VisibilityOutlined';
import ShowerOutlinedIcon from '@mui/icons-material/ShowerOutlined';
import ScienceOutlinedIcon from '@mui/icons-material/ScienceOutlined';
import WavesOutlinedIcon from '@mui/icons-material/WavesOutlined';
import { MutableRefObject, ReactElement } from "react";
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
import { alpha } from "@mui/material";
Expand All @@ -23,6 +27,10 @@ export default function LogEntry(props: {
case "transplanting": return <AutorenewOutlinedIcon />;
case "fertilizing": return <LunchDiningOutlinedIcon />;
case "biostimulating": return <BatterySaverOutlinedIcon />;
case "observation": return <VisibilityOutlinedIcon />;
case "misting": return <ShowerOutlinedIcon />;
case "treatment": return <ScienceOutlinedIcon />;
case "water_changing": return <WavesOutlinedIcon />;
default: return <QuestionMarkOutlinedIcon />;
}
};
Expand All @@ -34,6 +42,10 @@ export default function LogEntry(props: {
case "transplanting": return "rgb(121, 72, 36)";
case "fertilizing": return "rgb(234, 94, 7)";
case "biostimulating": return "rgb(234, 147, 7)";
case "treatment": return "rgb(123, 152, 60)";
case "observation": return "rgb(92, 93, 94)";
case "misting": return "rgb(4, 34, 77)";
case "water_changing": return "rgb(149, 187, 241)";
default: return "rgb(226, 233, 243)";
}
};
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/components/PlantDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,14 @@ function PlantHeader(props: {
}}>
{
!imageLoaded && !checkedImages &&
<Skeleton variant="rounded" animation="wave" sx={{ width: "100%", height: "100%", }} />
<Skeleton
variant="rounded"
animation="wave"
sx={{
width: "100%",
height: "100%",
}}
/>
}
{
imageIds.length === 0 && checkedImages &&
Expand Down
40 changes: 25 additions & 15 deletions frontend/src/components/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@ function AddNewBotanicalInfo(props: {
}}
onClick={() => props.addClick()}
>
{!imageLoaded &&
<Skeleton variant="rounded" animation="wave" sx={{ width: "100%", height: "100%" }} />
{
!imageLoaded &&
<Skeleton
variant="rounded"
animation="wave"
sx={{
width: "100%",
height: "100%"
}}
/>
}

<Box sx={{
Expand Down Expand Up @@ -250,19 +258,21 @@ export default function SearchPage(props: {
/>
</>
}
{botanicalInfos.map(botanicalInfo => {
return <BotanicalEntity
entity={botanicalInfo}
requestor={props.requestor}
addClick={(arg: botanicalInfo) => {
setSelectedBotanicalInfo(arg);
setAddPlantOpen(true);
}}
addEntity={(en: plant) => props.plants.push(en)}
key={botanicalInfo.id}
printError={props.printError}
/>;
})}
{
botanicalInfos.map((botanicalInfo, index) => {
return <BotanicalEntity
entity={botanicalInfo}
requestor={props.requestor}
addClick={(arg: botanicalInfo) => {
setSelectedBotanicalInfo(arg);
setAddPlantOpen(true);
}}
addEntity={(en: plant) => props.plants.push(en)}
key={index}
printError={props.printError}
/>;
})
}
<AddNewBotanicalInfo addClick={() => {
setSelectedBotanicalInfo(undefined);
setAddPlantOpen(true);
Expand Down

0 comments on commit 39fd9c3

Please sign in to comment.