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
4d9a9c91
Commit
4d9a9c91
authored
1 year ago
by
Blersch Lara
Browse files
Options
Downloads
Patches
Plain Diff
#15
when filter option is selected, the page is reloaded; added button to clear the garden
parent
7fe1162c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!41
Wishlist frontend
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
growbros-frontend/src/pages/Garten.tsx
+88
-7
88 additions, 7 deletions
growbros-frontend/src/pages/Garten.tsx
growbros-frontend/src/pages/Wunschliste.tsx
+14
-4
14 additions, 4 deletions
growbros-frontend/src/pages/Wunschliste.tsx
with
102 additions
and
11 deletions
growbros-frontend/src/pages/Garten.tsx
+
88
−
7
View file @
4d9a9c91
import
PlantsOverview
from
"
../components/PlantsOverview
"
;
import
{
useState
,
useEffect
}
from
"
react
"
;
import
PlantCard
from
"
../components/PlantCard.tsx
"
;
import
DropDownFilter
from
"
../components/DropDownFilter.tsx
"
;
function
Garten
()
{
return
(
<
div
>
<
h2
>
Dein Garten
</
h2
>
<
PlantsOverview
/>
</
div
>
);
const
[
plants
,
setPlants
]
=
useState
<
any
[]
>
([]);
const
[
error
,
setError
]
=
useState
();
const
token
:
String
=
""
;
const
[
currentSort
,
setCurrentSort
]
=
useState
<
string
>
(
""
)
useEffect
(()
=>
{
fetch
(
"
http://localhost:8080/api/v1/garden?
"
+
new
URLSearchParams
({
sort
:
currentSort
}),
{
method
:
'
GET
'
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
Authorization
:
`Bearer
${
token
}
`
,
},
})
.
then
((
res
)
=>
res
.
json
())
.
then
((
plants
)
=>
setPlants
(
plants
))
.
catch
((
err
)
=>
setError
(
err
));
},
[
setPlants
,
currentSort
]);
const
handleClearGarden
=
async
()
=>
{
if
(
confirm
(
"
Möchtest du wirklich alle Pflanzen aus deinem Garten entfernen?
"
+
"
\n
"
+
"
Diese Aktion kann nicht rückgängig gemacht werden.
"
))
{
useEffect
(()
=>
{
fetch
(
"
http://localhost:8080/api/v1/garden/remove/all
"
,
{
method
:
'
GET
'
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
Authorization
:
`Bearer
${
token
}
`
,
},
})
.
then
((
res
)
=>
res
.
json
())
.
then
((
plants
)
=>
setPlants
(
plants
))
.
catch
((
err
)
=>
setError
(
err
));
},
[
setPlants
]);
}
}
const
handleSortOptions
=
async
(
selectedOption
:
string
)
=>
{
switch
(
selectedOption
)
{
case
"
neueste zuerst
"
:
setCurrentSort
(
"
createdAt
"
);
break
;
case
"
als nächstes anpflanzbar
"
:
setCurrentSort
(
"
plantDate
"
);
break
;
case
"
als nächstes erntbar
"
:
setCurrentSort
(
"
harvestDate
"
);
break
;
default
:
setCurrentSort
(
""
);
}
}
return
(
<>
<
div
>
<
h2
>
Deine Wunschliste
</
h2
>
<
DropDownFilter
topic
=
{
"
Sortierung der Pflanzen im Garten
"
}
options
=
{
[
"
neueste zuerst
"
,
"
als nächstes anpflanzbar
"
,
"
als nächstes erntbar
"
,
]
}
filterOnChange
=
{
handleSortOptions
}
/>
<
button
onClick
=
{
handleClearGarden
}
>
Garten leeren
</
button
>
</
div
>
{
error
?
(
<
p
>
Error fetching data
</
p
>
)
:
(
<
ul
style
=
{
{
display
:
"
flex
"
,
gap
:
"
1rem
"
,
width
:
"
100%
"
}
}
>
{
plants
?.
map
((
plant
)
=>
(
<
PlantCard
plant
=
{
plant
}
key
=
{
plant
.
id
}
/>
))
}
</
ul
>
)
}
</>
);
}
export
default
Garten
;
This diff is collapsed.
Click to expand it.
growbros-frontend/src/pages/Wunschliste.tsx
+
14
−
4
View file @
4d9a9c91
...
...
@@ -28,7 +28,17 @@ function Wunschliste() {
if
(
confirm
(
"
Möchtest du wirklich alle Pflanzen aus deiner Wunschliste entfernen?
"
+
"
\n
"
+
"
Diese Aktion kann nicht rückgängig gemacht werden.
"
))
{
useEffect
(()
=>
{
fetch
(
"
http://localhost:8080/api/v1/wishlist/remove/all
"
)
fetch
(
"
http://localhost:8080/api/v1/wishlist/remove/all
"
,
{
method
:
'
GET
'
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
Authorization
:
`Bearer
${
token
}
`
,
},
})
.
then
((
res
)
=>
res
.
json
())
.
then
((
plants
)
=>
setPlants
(
plants
))
.
catch
((
err
)
=>
setError
(
err
));
...
...
@@ -47,7 +57,8 @@ function Wunschliste() {
case
"
jetzt anpflanzbar
"
:
setCurrentSort
(
"
currentPlantable
"
);
break
;
default
:
setCurrentSort
(
""
);
default
:
setCurrentSort
(
""
);
}
}
...
...
@@ -81,5 +92,4 @@ function Wunschliste() {
}
export
default
Wunschliste
;
export
default
Wunschliste
;
\ No newline at end of file
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