Skip to content

Commit

Permalink
new features
Browse files Browse the repository at this point in the history
  • Loading branch information
ogeobubu committed Oct 22, 2024
1 parent 9fad7fc commit 9516193
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
1 change: 0 additions & 1 deletion client/src/pages/homepage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import Button from "../../components/button";
import bgImage from "../../assets/leaf-bg.png";

Expand Down
27 changes: 9 additions & 18 deletions client/src/pages/upload/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useState } from "react";
import axios from "axios";
import { useMutation } from "@tanstack/react-query";
import { useMutation, UseMutationResult } from "@tanstack/react-query";
import Button from "../../components/button";
import bgImage from "../../assets/leaf-bg.png";
import { LeafResponse } from "../../typings";
Expand All @@ -9,26 +9,21 @@ const uploadImage = async (file: File): Promise<LeafResponse> => {
const formData = new FormData();
formData.append("image", file);

const response = await axios.post(
`/api/images/upload`,
formData,
{
headers: {
"Content-Type": "multipart/form-data",
},
}
);
const response = await axios.post(`/api/images/upload`, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});

return response.data;
};

const ImageUpload: React.FC = () => {
const [selectedFile, setSelectedFile] = useState<File | null>(null);
const [modalVisible, setModalVisible] = useState(false);
const [classificationResult, setClassificationResult] =
useState<LeafResponse | null>(null);
const [classificationResult, setClassificationResult] = useState<LeafResponse | null>(null);

const mutation = useMutation<LeafResponse, Error, File>({
const mutation: UseMutationResult<LeafResponse, Error, File> = useMutation({
mutationFn: uploadImage,
onSuccess: (data) => {
console.log("Upload success:", data);
Expand Down Expand Up @@ -137,10 +132,6 @@ const ImageUpload: React.FC = () => {
Leaf Classification Result
</h2>

{/* <p className="mb-2">
<strong>Species:</strong> {classificationResult.leaf.species}
</p> */}

<img
src={`${classificationResult.leaf.imageUrl}`}
alt="Leaf"
Expand Down Expand Up @@ -169,4 +160,4 @@ const ImageUpload: React.FC = () => {
);
};

export default ImageUpload;
export default ImageUpload;
1 change: 1 addition & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{

"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
Expand Down

0 comments on commit 9516193

Please sign in to comment.