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
201817c2
Commit
201817c2
authored
1 year ago
by
Blersch Lara
Browse files
Options
Downloads
Patches
Plain Diff
#16
when dropDownFilter is changed, plants are fetch with the current sort parameter
parent
cfa431f7
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/components/DropDownFilter.tsx
+4
-0
4 additions, 0 deletions
growbros-frontend/src/components/DropDownFilter.tsx
growbros-frontend/src/pages/Wunschliste.tsx
+65
-50
65 additions, 50 deletions
growbros-frontend/src/pages/Wunschliste.tsx
with
69 additions
and
50 deletions
growbros-frontend/src/components/DropDownFilter.tsx
+
4
−
0
View file @
201817c2
import
{
useState
}
from
"
react
"
;
import
"
../pages/Wunschliste.tsx
"
;
function
DropDownFilter
(
props
:
PropsDropDownFilter
)
{
...
...
@@ -7,8 +8,10 @@ function DropDownFilter(props: PropsDropDownFilter) {
const
topic
=
props
.
topic
;
const
[
selectedOption
,
setSelectedOption
]
=
useState
(
""
);
const
handleOptionChange
=
(
event
:
any
)
=>
{
setSelectedOption
(
event
.
target
.
value
);
props
.
filterOnChange
(
event
.
target
.
value
);
};
return
(
...
...
@@ -29,6 +32,7 @@ function DropDownFilter(props: PropsDropDownFilter) {
type
PropsDropDownFilter
=
{
options
:
Array
<
string
>
;
topic
:
string
;
filterOnChange
:
(
selectedOption
:
string
)
=>
void
;
};
export
default
DropDownFilter
\ No newline at end of file
This diff is collapsed.
Click to expand it.
growbros-frontend/src/pages/Wunschliste.tsx
+
65
−
50
View file @
201817c2
...
...
@@ -3,66 +3,81 @@ import PlantCard from "../components/PlantCard.tsx";
import
DropDownFilter
from
"
../components/DropDownFilter.tsx
"
;
function
Wunschliste
()
{
const
[
plants
,
setPlants
]
=
useState
<
any
[]
>
([]);
const
[
error
,
setError
]
=
useState
();
const
[
plants
,
setPlants
]
=
useState
<
any
[]
>
([]);
const
[
error
,
setError
]
=
useState
();
let
sort
=
""
const
token
:
String
=
""
;
useEffect
(()
=>
{
fetch
(
"
http://localhost:8080/api/v1/wishlist
"
,
{
method
:
'
GET
'
,
body
:
sort
})
.
then
((
res
)
=>
res
.
json
())
.
then
((
plants
)
=>
setPlants
(
plants
))
.
catch
((
err
)
=>
setError
(
err
));
},
[
setPlants
]);
const
[
currentSort
,
setCurrentSort
]
=
useState
<
string
>
(
""
)
const
handleClearWishList
=
async
()
=>
{
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
"
)
useEffect
(()
=>
{
fetch
(
"
http://localhost:8080/api/v1/wishlist?
"
+
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
]);
},
[
setPlants
,
currentSort
]);
const
handleClearWishList
=
async
()
=>
{
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
"
)
.
then
((
res
)
=>
res
.
json
())
.
then
((
plants
)
=>
setPlants
(
plants
))
.
catch
((
err
)
=>
setError
(
err
));
},
[
setPlants
]);
}
}
}
/*const handleSortOptions = async () => {
//sort = DropDownFilter.options.value;
//todo: how to get current selected option?
}*/
const
handleSortOptions
=
async
(
selectedOption
:
string
)
=>
{
switch
(
selectedOption
)
{
case
"
neueste zuerst
"
:
setCurrentSort
(
"
createdAt
"
);
break
;
case
"
als nächstes anpflanzbar
"
:
setCurrentSort
(
"
plantDate
"
);
break
;
case
"
jetzt anpflanzbar
"
:
setCurrentSort
(
"
currentPlantable
"
);
break
;
default
:
setCurrentSort
(
""
);
}
}
return
(
return
(
<>
<
div
>
<
h2
>
Deine Wunschliste
</
h2
>
<
DropDownFilter
topic
=
{
"
Sortierung der Pflanzen in der Wunschliste
"
}
options
=
{
[
"
neueste zuerst
"
,
"
als nächstes anpflanzbar
"
,
"
jetzt anpflanzbar
"
,
]
}
// o
nChange={handleSortOptions
()} todo: how?s
/>
<
button
onClick
=
{
handleClearWishList
}
>
Wunschliste 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
>
)
}
</>
);
<>
<
div
>
<
h2
>
Deine Wunschliste
</
h2
>
<
DropDownFilter
topic
=
{
"
Sortierung der Pflanzen in der Wunschliste
"
}
options
=
{
[
"
neueste zuerst
"
,
"
als nächstes anpflanzbar
"
,
"
jetzt anpflanzbar
"
,
]
}
filterO
nChange
=
{
handleSortOptions
}
/>
<
button
onClick
=
{
handleClearWishList
}
>
Wunschliste 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
>
)
}
</>
);
}
...
...
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