Skip to content

Commit

Permalink
Merge pull request #398 from euanwm/feature/search_result_fix
Browse files Browse the repository at this point in the history
fixed 0 search results bug
  • Loading branch information
euanwm authored Sep 1, 2024
2 parents 42de008 + 83f0d9a commit a114002
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion backend/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@ func SearchName(c *gin.Context) {
if len(results.Names) > maxResults {
results.Names = results.Names[:maxResults]
}
c.JSON(http.StatusOK, results)
// todo: bug here as an empty struct is returned if no results are found higher up in the stack
if len(results.Names) > 1 {
c.JSON(http.StatusOK, results)
} else if len(results.Names) == 1 {
if len(results.Names[0].Name) > 0 {
c.JSON(http.StatusOK, results)
} else {
c.JSON(http.StatusNoContent, nil)
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/components/organisms/searchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function SearchPage() {
placeholder="Search for a lifter..."
onChange={async e => setInputSearch(e.target.value)}
/>
Number of lifters found: {data?.total}, showing {data?.names.length}
Number of lifters found: {(data?.total) || 0}, showing {(data?.names.length) || 0}
<br />
{data && (
<Listbox aria-label='Lifter search results'>
Expand Down

0 comments on commit a114002

Please sign in to comment.