Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GrowBros
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tomato
GrowBros
Commits
67a0b4dc
Commit
67a0b4dc
authored
1 year ago
by
Holzheu Hannah
Browse files
Options
Downloads
Patches
Plain Diff
updated SearchPage and added fetching randomPlants from Endpoint
#12
parent
c07c3efd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!28
Closes #40 : Custom useGrowbrosFetcher hook to make calls to the backend.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
growbros-frontend/src/components/PlantDetails.tsx
+1
-0
1 addition, 0 deletions
growbros-frontend/src/components/PlantDetails.tsx
growbros-frontend/src/pages/Suche.tsx
+39
-2
39 additions, 2 deletions
growbros-frontend/src/pages/Suche.tsx
with
40 additions
and
2 deletions
growbros-frontend/src/components/PlantDetails.tsx
+
1
−
0
View file @
67a0b4dc
...
...
@@ -92,6 +92,7 @@ function ButtonAddToGarden({ plantId }: any) {
if
(
response
.
status
===
201
)
{
console
.
log
(
"
Pflanze wurde erfolgreich dem Garten hinzugefügt
"
);
}
else
{
console
.
log
(
"
Unexpected response status:
"
,
response
.
status
);
setStatus
(
"
Pflanze konnte nicht dem Garten hinzugefügt werden
"
);
}
}
catch
(
error
)
{
...
...
This diff is collapsed.
Click to expand it.
growbros-frontend/src/pages/Suche.tsx
+
39
−
2
View file @
67a0b4dc
import
"
font-awesome/css/font-awesome.min.css
"
;
import
"
../stylesheets/Suche.css
"
;
import
PlantsOverview
from
"
../components/PlantsOverview
"
;
import
{
useState
}
from
"
react
"
;
import
{
useState
,
useEffect
}
from
"
react
"
;
import
FilterPage
from
"
../components/FilterPage
"
;
function
Suche
()
{
const
[
randomPlants
,
setRandomPlants
]
=
useState
<
plant
[]
|
null
>
(
null
);
const
[
error
,
setError
]
=
useState
<
null
|
String
>
(
null
);
const
randomPlantsCount
:
number
=
30
;
const
token
:
String
=
""
;
const
fetchRandomPlants
=
async
()
=>
{
try
{
const
response
=
await
fetch
(
`http://localhost:8080/api/v1/plants/randomPlants/
${
randomPlantsCount
}
`
,
{
method
:
"
GET
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
Authorization
:
`Bearer
${
token
}
`
,
},
}
);
if
(
response
.
status
==
200
)
{
const
data
=
await
response
.
json
();
setRandomPlants
(
data
);
console
.
log
(
"
Succesfully fetched data
"
);
}
else
{
console
.
log
(
"
Unexpected response status:
"
,
response
.
status
);
setError
(
"
Error fetching data
"
);
}
}
catch
(
error
)
{
console
.
error
(
"
Error
"
,
error
);
setError
(
"
Error fetching data
"
);
}
};
useEffect
(()
=>
{
fetchRandomPlants
();
},
[]);
return
(
<>
<
SearchBar
/>
<
PlantsOverview
/>
<
div
>
{
error
?
<
div
>
{
error
}
</
div
>
:
<
PlantsOverview
plants
=
{
randomPlants
}
/>
}
</
div
>
</>
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment