Skip to content

Commit

Permalink
Handle leading/trailing spaces in search input (#248)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonatan Kłosko <[email protected]>
  • Loading branch information
maxidragon and jonatanklosko authored Dec 26, 2024
1 parent 5f546f5 commit 6b7cd5f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function CompetitionSearch({ value = null, onChange, TextFieldProps = {} }) {
forcePopupIcon={false}
disableClearable={true}
renderInput={(params) => <TextField {...params} {...TextFieldProps} />}
filterOptions={(options) => options}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/wca_live/competitions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ defmodule WcaLive.Competitions do
defp filter_by_text(query, nil), do: query

defp filter_by_text(query, filter) do
filter = filter |> String.trim() |> String.replace(~r/\s+/, " ")
from c in query, where: ilike(c.name, ^"%#{filter}%")
end

Expand Down
6 changes: 6 additions & 0 deletions test/wca_live/competitions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ defmodule WcaLive.CompetitionsTest do
assert worlds.id in ids(list)
assert open.id not in ids(list)
assert euro.id in ids(list)

list = Competitions.list_competitions(%{filter: " championship 2020 "})

assert worlds.id in ids(list)
assert open.id not in ids(list)
assert euro.id in ids(list)
end

test "list_competitions/1 given :from returns competitions from that date inclusive" do
Expand Down

0 comments on commit 6b7cd5f

Please sign in to comment.