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
0c715cb6
Commit
0c715cb6
authored
1 year ago
by
Holzheu Hannah
Browse files
Options
Downloads
Patches
Plain Diff
added logic for buttons to add plants to garden or wishlist
parent
374d40b4
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
+87
-11
87 additions, 11 deletions
growbros-frontend/src/components/PlantDetails.tsx
growbros-frontend/src/pages/Suche.tsx
+1
-0
1 addition, 0 deletions
growbros-frontend/src/pages/Suche.tsx
with
88 additions
and
11 deletions
growbros-frontend/src/components/PlantDetails.tsx
+
87
−
11
View file @
0c715cb6
import
"
../stylesheets/PlantDetails.css
"
;
import
"
font-awesome/css/font-awesome.min.css
"
;
import
{
use
Params
}
from
"
react
-router-dom
"
;
import
{
use
State
}
from
"
react
"
;
function
PlantDetails
(
props
:
any
)
{
const
plant
=
props
.
plant
;
...
...
@@ -64,27 +64,103 @@ function PlantDetails(props: any) {
margin
:
"
0 0 40px 0
"
,
}
}
>
<
ButtonAddToGarden
></
ButtonAddToGarden
>
<
ButtonAddToWishlist
></
ButtonAddToWishlist
>
<
ButtonAddToGarden
plantId
=
{
plant
.
id
}
></
ButtonAddToGarden
>
<
ButtonAddToWishlist
plantId
=
{
plant
.
id
}
></
ButtonAddToWishlist
>
</
div
>
</
div
>
</>
);
}
function
ButtonAddToGarden
()
{
function
ButtonAddToGarden
({
plantId
}:
any
)
{
const
[
status
,
setStatus
]
=
useState
<
null
|
String
>
(
null
);
const
token
:
String
=
""
;
const
handleButtonClick
=
async
()
=>
{
try
{
const
response
=
await
fetch
(
`http://localhost:8080/api/v1/garden/add/
${
plantId
}
`
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
Authorization
:
`Bearer
${
token
}
`
,
},
}
);
if
(
response
.
status
===
201
)
{
console
.
log
(
"
Pflanze wurde erfolgreich dem Garten hinzugefügt
"
);
}
else
{
setStatus
(
"
Pflanze konnte nicht dem Garten hinzugefügt werden
"
);
}
}
catch
(
error
)
{
console
.
error
(
"
Error
"
,
error
);
setStatus
(
"
Pflanze konnte nicht dem Garten hinzugefügt werden
"
);
}
};
return
(
<
button
>
<
i
className
=
"fa fa-leaf"
></
i
>
</
button
>
<>
{
status
&&
(
<
div
className
=
{
`status-message
${
status
.
includes
(
"
erfolgreich
"
)
?
"
success-message
"
:
"
error-message
"
}
`
}
>
{
status
}
</
div
>
)
}
<
button
onClick
=
{
handleButtonClick
}
>
<
i
className
=
"fa fa-leaf"
></
i
>
</
button
>
</>
);
}
function
ButtonAddToWishlist
()
{
//TODO css für status message
function
ButtonAddToWishlist
({
plantId
}:
any
)
{
const
[
status
,
setStatus
]
=
useState
<
null
|
String
>
(
null
);
const
token
:
String
=
""
;
const
handleButtonClick
=
async
()
=>
{
try
{
const
response
=
await
fetch
(
`http://localhost:8080/api/v1/wishlist/add/
${
plantId
}
`
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
Authorization
:
`Bearer
${
token
}
`
,
},
}
);
if
(
response
.
status
===
201
)
{
console
.
log
(
"
Pflanze wurde erfolgreich der Wunschliste hinzugefügt
"
);
}
else
{
setStatus
(
"
Pflanze konnte nicht der Wunschliste hinzugefügt werden
"
);
}
}
catch
(
error
)
{
console
.
error
(
"
Error
"
,
error
);
setStatus
(
"
Pflanze konnte nicht der Wunschliste hinzugefügt werden
"
);
}
};
return
(
<
button
>
<
i
className
=
"fa fa-heart"
></
i
>
</
button
>
<>
{
status
&&
(
<
div
className
=
{
`status-message
${
status
.
includes
(
"
erfolgreich
"
)
?
"
success-message
"
:
"
error-message
"
}
`
}
>
{
"
"
}
{
status
}
</
div
>
)
}
<
button
onClick
=
{
handleButtonClick
}
>
<
i
className
=
"fa fa-heart"
></
i
>
</
button
>
</>
);
}
...
...
This diff is collapsed.
Click to expand it.
growbros-frontend/src/pages/Suche.tsx
+
1
−
0
View file @
0c715cb6
...
...
@@ -4,6 +4,7 @@ import PlantsOverview from "../components/PlantsOverview";
import
{
useState
}
from
"
react
"
;
import
FilterPage
from
"
../components/FilterPage
"
;
function
Suche
()
{
return
(
<>
...
...
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