Skip to content

Commit

Permalink
feature: sort plant alphabetically in homepage (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeLuise authored Sep 10, 2023
1 parent bcafd36 commit 2fe88b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public ResponseEntity<Page<PlantDTO>> getAll(@RequestParam(defaultValue = "0", r
@RequestParam(defaultValue = "id", required = false) String sortBy,
@RequestParam(defaultValue = "DESC", required = false)
Sort.Direction sortDir) {
final Pageable pageable = PageRequest.of(pageNo, pageSize, sortDir, sortBy);
final Sort ignoreCaseSort = Sort.by(new Sort.Order(sortDir, sortBy).ignoreCase());
final Pageable pageable = PageRequest.of(pageNo, pageSize, ignoreCaseSort);
final Page<Plant> result = plantService.getAll(pageable);
return ResponseEntity.ok(result.map(plantDTOConverter::convertToDTO));
}
Expand Down
18 changes: 15 additions & 3 deletions frontend/src/components/AddPlant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ export default function AddPlant(props: {
})
.then((res) => {
props.setOpen(false);
props.plants.push(res);
let insertHere = props.plants.findIndex((pl) => {
return pl.personalName.toLowerCase() > res.personalName.toLowerCase();
});
insertHere = Math.max(0, insertHere);
props.plants.splice(insertHere, 0, res);
props.entity!.id = res.botanicalInfo.id;
setName();
cleanup();
Expand Down Expand Up @@ -167,7 +171,11 @@ export default function AddPlant(props: {
.then((imgRes) => {
props.setOpen(false);
res.botanicalInfo.imageUrl = "/" + imgRes.data.id;
props.plants.push(res);
let insertHere = props.plants.findIndex((pl) => {
return pl.personalName.toLowerCase() > res.personalName.toLowerCase();
});
insertHere = Math.max(0, insertHere);
props.plants.splice(insertHere, 0, res);
setName();
cleanup();
})
Expand All @@ -176,7 +184,11 @@ export default function AddPlant(props: {
});
} else {
props.setOpen(false);
props.plants.push(res);
let insertHere = props.plants.findIndex((pl) => {
return pl.personalName.toLowerCase() > res.personalName.toLowerCase();
});
insertHere = Math.max(0, insertHere);
props.plants.splice(insertHere, 0, res);
setName();
cleanup();
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default function Home(props: { isLoggedIn: () => boolean, requestor: Axio
};

const getEntities = (count: number): void => {
props.requestor.get(`plant?pageSize=${count}`)
props.requestor.get(`plant?sortBy=personalName&sortDir=ASC&pageSize=${count}`)
.then((res) => {
let newEntities: plant[] = [];
res.data.content.forEach((en: plant) => {
Expand Down

0 comments on commit 2fe88b5

Please sign in to comment.