Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ayanahye/PlantSnap
Browse files Browse the repository at this point in the history
  • Loading branch information
layanb4 committed Nov 18, 2023
2 parents 1bee00e + cf010f6 commit 9fd6c3c
Show file tree
Hide file tree
Showing 16 changed files with 475 additions and 163 deletions.
109 changes: 109 additions & 0 deletions app/SampleData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"id": 1,
"common_name": "European Silver Fir",
"scientific_name": ["Abies alba"],
"other_name": ["Common Silver Fir"],
"family": null,
"origin": [
"Austria",
"Germany",
"Switzerland",
"France",
"Italy",
"Slovenia",
"Croatia",
"Bosnia and Herzegovina",
"Serbia",
"Montenegro",
"Albania",
"Bulgaria",
"Romania",
"Ukraine",
"Poland",
"Czech Republic",
"Slovakia",
"Hungary"
],
"type": "tree",
"dimension": "Height: 60 feet",
"dimensions": {
"type": "Height",
"min_value": 60,
"max_value": 60,
"unit": "feet"
},
"cycle": "Perennial",
"attracts": [],
"propagation": [
"Cutting",
"Grafting Propagation",
"Layering Propagation",
"Seed Propagation",
"Air Layering Propagation",
"Tissue Culture"
],
"hardiness": {
"min": "7",
"max": "7"
},
"hardiness_location": {
"full_url": "https://perenual.com/api/hardiness-map?species_id=1&size=og&key=sk-sZxb6546cce0783d62824",
"full_iframe": "<iframe frameborder=0 scrolling=yes seamless=seamless width=1000 height=550 style='margin:auto;' src='https://perenual.com/api/hardiness-map?species_id=1&size=og&key=sk-sZxb6546cce0783d62824'></iframe>"
},
"watering": "Frequent",
"depth_water_requirement": [],
"volume_water_requirement": [],
"watering_period": null,
"watering_general_benchmark": {
"value": "7-10",
"unit": "days"
},
"plant_anatomy": [],
"sunlight": ["full sun"],
"pruning_month": ["February", "March", "April"],
"pruning_count": [],
"seeds": 0,
"maintenance": null,
"care-guides": "http://perenual.com/api/species-care-guide-list?species_id=1&key=sk-sZxb6546cce0783d62824",
"soil": [],
"growth_rate": "High",
"drought_tolerant": false,
"salt_tolerant": false,
"thorny": false,
"invasive": false,
"tropical": false,
"indoor": false,
"care_level": "Medium",
"pest_susceptibility": [],
"pest_susceptibility_api": "Coming Soon",
"flowers": false,
"flowering_season": null,
"flower_color": "",
"cones": true,
"fruits": false,
"edible_fruit": false,
"edible_fruit_taste_profile": "Coming Soon",
"fruit_nutritional_value": "Coming Soon",
"fruit_color": [],
"harvest_season": null,
"leaf": true,
"leaf_color": ["green"],
"edible_leaf": false,
"cuisine": false,
"medicinal": true,
"poisonous_to_humans": 0,
"poisonous_to_pets": 0,
"description": "European Silver Fir (Abies alba) is an amazing coniferous species native to mountainous regions of central Europe and the Balkans. It is an evergreen tree with a narrow, pyramidal shape and long, soft needles. Its bark is scaly grey-brown and its branches are highly ornamental due to its conical-shaped silver-tinged needles. It is pruned for use as an ornamental evergreen hedging and screening plant, and is also popular for use as a Christmas tree. Young trees grow quickly and have strong, flexible branches which makes them perfect for use as windbreaks. The European Silver Fir is an impressive species, making it ideal for gardens and public spaces.",
"default_image": {
"license": 45,
"license_name": "Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)",
"license_url": "https://creativecommons.org/licenses/by-sa/3.0/deed.en",
"original_url": "https://perenual.com/storage/species_image/1_abies_alba/og/1536px-Abies_alba_SkalitC3A9.jpg",
"regular_url": "https://perenual.com/storage/species_image/1_abies_alba/regular/1536px-Abies_alba_SkalitC3A9.jpg",
"medium_url": "https://perenual.com/storage/species_image/1_abies_alba/medium/1536px-Abies_alba_SkalitC3A9.jpg",
"small_url": "https://perenual.com/storage/species_image/1_abies_alba/small/1536px-Abies_alba_SkalitC3A9.jpg",
"thumbnail": "https://perenual.com/storage/species_image/1_abies_alba/thumbnail/1536px-Abies_alba_SkalitC3A9.jpg"
},
"other_images": "Upgrade Plan To Supreme For Access https://perenual.com/subscription-api-pricing. I'm sorry"
}

105 changes: 66 additions & 39 deletions app/filtering/filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default function Filter(props) {
}


const careGuides = [
'Care Guide',
];

const dataNames = [
'id',
Expand All @@ -35,19 +38,6 @@ export default function Filter(props) {
'seeds'
];

const dataCareReqs = [
'cycle',
'watering',
'watering_period',
'sunlight',
'care-guides',
'depth_water_requirement',
'volume_water_requirement',
'watering_general_benchmark',
'volume_water_requirement',
'indoor'
];

const dataMaintenance = [
'propagation',
'hardiness',
Expand Down Expand Up @@ -110,9 +100,12 @@ export default function Filter(props) {
}
})
}


console.log(selectedOptionNames);

const optionValues = Object.values(selectedOptionNames);

/*
const optionsArray = optionValues.map(valueOption => (
<div key={valueOption}>
Expand All @@ -121,6 +114,9 @@ export default function Filter(props) {
</div>
));
*/


/*
for (value in values) {
if (key === selectedOptionNames[id]) {
Expand Down Expand Up @@ -161,6 +157,7 @@ export default function Filter(props) {
<h2 className="right-align">Filters:</h2>
<div className="dropdowns">

<Dropdown data={careGuides} name="Care Guides" onOptionChange={handleOptionChange} id="option0"/>
<div class = "navigationfilterbox">

{/* filter options */}
Expand Down Expand Up @@ -239,32 +236,62 @@ export default function Filter(props) {
</div>
</div>

<div className="information">
<div class = "scroll-object1">


{optionValues.length > 0 ? (
optionValues.map((valueOption, index) => (
<div key={index}>

<strong>{valueOption}:</strong>{" "}
{props.speciesList[valueOption] !== undefined && props.speciesList[valueOption] !== null ? (
typeof props.speciesList[valueOption] === "object"
? Object.values(props.speciesList[valueOption]).join(", ")
: props.speciesList[valueOption]
) : (
"No data yet"
<div className="information">
<div class="scroll-object1">
{optionValues.length > 0 ? (
optionValues.map((valueOption, index) => (
<div key={index}>
{valueOption === "Care Guide" ? (
<p>
{props.speciesList["common_name"] && (
<span>The {props.speciesList["common_name"]} requires </span>
)}


</div>

))
) : (
<strong>Please use the filters to select the data you want.</strong>
)}
</div>
</div>
{props.speciesList["watering"] && (
<span>{props.speciesList["watering"].charAt(0).toLowerCase() + props.speciesList["watering"].slice(1)} watering. </span>
)}
{props.speciesList["sunlight"] && (
<span>The amount of sun the plant needs is {props.speciesList["sunlight"]}. </span>
)}
{props.speciesList["pruning_month"] && (
<span>The best month to prune the plant is {props.speciesList["pruning_month"]} and </span>
)}
{props.speciesList["maintenance"] && (
<span>the overall maintenance to care for this plant is {props.speciesList["maintenance"]}. </span>
)}
{props.speciesList["drought_tolerant"] !== null && (
<span>the plant {props.speciesList["drought_tolerant"] ? "is drought tolerant" : "is not drought tolerant"}. </span>
)}
{props.speciesList["salt_tolerant"] !== null && (
<span>Additionally, the plant {props.speciesList["drought_tolerant"] ? "is salt tolerant" : "is not salt tolerant"}. </span>
)}
{props.speciesList["fruits"] !== null && (
<span>Furthermore, the plant {props.speciesList["fruits"] ? "grows fruits" : "does not grow fruits"}. </span>
)}
{props.speciesList["indoor"] !== null && (
<span>The plant {props.speciesList["indoor"] ? "is an indoor plant" : "is not an indoor plant"}. </span>
)}
{props.speciesList["care_level"] !== null && (
<span>The overall care level of the plant is said to be {props.speciesList["care_level"].charAt(0).toLowerCase() + props.speciesList["care_level"].slice(1)}. </span>
)}
</p>
) : (
props.speciesList[valueOption] !== undefined && props.speciesList[valueOption] !== null ? (
typeof props.speciesList[valueOption] === "object"
? Object.values(props.speciesList[valueOption]).join(", ")
: props.speciesList[valueOption]
) : (
"No data yet"
)
)}
</div>
))
) : (
<strong>Please use the filters to select the data you want.</strong>
)}
</div>
</div>



</main>

Expand Down
46 changes: 28 additions & 18 deletions app/filtering/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,43 @@ import { useEffect, useState } from "react";
import React from 'react'
import Filter from './filter';
import "./Filter.css";
import {perenual_detail_test_value as data} from "../globalTypes";
import Data from '../SampleData.json'

function Filtering(props) {

const [speciesData, setSpeciesData] = useState(data);

//const plantId = localStorage.getItem('plantId');

/*

const plantId = props.id;
const [speciesData, setSpeciesData] = useState(Data);


useEffect(() => {
function sendData() {
fetch(`/.netlify/functions/filtering?q=${plantId}`)
.then((res) => res.json())
.then((data) => setSpeciesData(data))
.catch((error) => console.error("Error:", error));
}
sendData();
}, [])

// const [speciesList, setSpeciesList] = useState(Data);


return (
<div className="App">
<Filter speciesList={speciesData} />
</div>

)
}

export default Filtering

/*
useEffect(() => {
const getData = async () => {
Expand All @@ -80,19 +105,4 @@ function Filtering(props) {
}
getData();
}, [plantId]);
*/



// const [speciesList, setSpeciesList] = useState(Data);

return (
<div className="App">
<Filter speciesList={speciesData} />
</div>

)
}

export default Filtering
*/
Binary file added app/filtering/rose.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 17 additions & 12 deletions app/identify/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,23 @@ export default function Page() {
//same as search page
set_showload(true)
set_showinputo(false)
postData(form).then(data => {
let tmp: result[] = []
for (let r of data.results) {
tmp.push({
name: r.species.commonNames.length > 0 ? r.species.scientificNameWithoutAuthor : r.species.scientificNameWithoutAuthor,
image: {url: r.images[0].url.m, alt: r.species.commonNames.join(", ")},
score: r.score,
sciName: r.species.scientificNameWithoutAuthor
})
}
set_resultlst(tmp)
set_showresult(true)
fetch("/.netlify/functions/identify", {
body: form,
method: 'POST',
}).then(res => {
res.json().then(data => {
let tmp: result[] = []
for (let r of data.results) {
tmp.push({
name: r.species.commonNames.length > 0 ? r.species.scientificNameWithoutAuthor : r.species.scientificNameWithoutAuthor,
image: {url: r.images[0].url.m, alt: r.species.commonNames.join(", ")},
score: r.score,
sciName: r.species.scientificNameWithoutAuthor
})
}
set_resultlst(tmp)
set_showresult(true)
})
})
}

Expand Down
4 changes: 2 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export default function RootLayout({children,}: {
<Link className="nav-link" aria-current="page" href="/">Home</Link>
</li>
<li className="nav-item">
<Link className="nav-link" aria-current="page" href="/listings-text">Search</Link>
<Link className="nav-link" aria-current="page" href="/search">Search</Link>
</li>
<li className="nav-item">
<Link className="nav-link" aria-current="page" href="/listings-image">Identify</Link>
<Link className="nav-link" aria-current="page" href="/identify">Identify</Link>
</li>
<li className="nav-item">
<Link className="nav-link" aria-current="page" href="/filtering">Filter temp</Link>
Expand Down
Binary file added app/not-found-pic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9fd6c3c

Please sign in to comment.