Add sort by created date

This commit is contained in:
Correl Roush 2024-02-09 23:43:29 -05:00
parent 1358f38419
commit 2554900554
2 changed files with 19 additions and 1 deletions

View file

@ -194,6 +194,11 @@ async def advanced_search(
'CAST(COALESCE(CASE WHEN "copies"."isFoil" THEN cards.price_usd_foil ELSE cards.price_usd END, 0) as decimal) DESC', 'CAST(COALESCE(CASE WHEN "copies"."isFoil" THEN cards.price_usd_foil ELSE cards.price_usd END, 0) as decimal) DESC',
*orderings, *orderings,
] ]
elif sort_by == "created":
orderings = [
"copies.created_date DESC",
*orderings,
]
params["last_update_key"] = "last_update" params["last_update_key"] = "last_update"
query = " ".join( query = " ".join(
[ [

View file

@ -48,6 +48,7 @@ decodeStatistics =
type SortBy type SortBy
= PriceDescending = PriceDescending
| RarityDescending | RarityDescending
| CreatedDescending
type alias Criteria = type alias Criteria =
@ -124,6 +125,9 @@ searchQuery criteria =
RarityDescending -> RarityDescending ->
"rarity" "rarity"
CreatedDescending ->
"created"
in in
[ Url.Builder.string "q" criteria.query [ Url.Builder.string "q" criteria.query
, Url.Builder.string "sort_by" (toString criteria.sortBy) , Url.Builder.string "sort_by" (toString criteria.sortBy)
@ -173,6 +177,7 @@ parseUrl =
(Dict.fromList (Dict.fromList
[ ( "rarity", RarityDescending ) [ ( "rarity", RarityDescending )
, ( "price", PriceDescending ) , ( "price", PriceDescending )
, ( "created", CreatedDescending )
] ]
) )
|> Url.Parser.Query.map (Maybe.withDefault PriceDescending) |> Url.Parser.Query.map (Maybe.withDefault PriceDescending)
@ -386,6 +391,9 @@ sortDropdown =
RarityDescending -> RarityDescending ->
"Rarity DESC" "Rarity DESC"
CreatedDescending ->
"Created DESC"
selectAttrs = selectAttrs =
[ Background.color UI.colors.secondary [ Background.color UI.colors.secondary
, Border.width 1 , Border.width 1
@ -421,7 +429,12 @@ sortDropdown =
toString sortBy toString sortBy
in in
Dropdown.basic Dropdown.basic
{ itemsFromModel = always [ PriceDescending, RarityDescending ] { itemsFromModel =
always
[ PriceDescending
, RarityDescending
, CreatedDescending
]
, selectionFromModel = .criteria >> .sortBy >> Just , selectionFromModel = .criteria >> .sortBy >> Just
, dropdownMsg = DropdownMsg , dropdownMsg = DropdownMsg
, onSelectMsg = SortSelected , onSelectMsg = SortSelected