diff --git a/tutor/database.py b/tutor/database.py index 2bcc838..a72e4fe 100644 --- a/tutor/database.py +++ b/tutor/database.py @@ -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', *orderings, ] + elif sort_by == "created": + orderings = [ + "copies.created_date DESC", + *orderings, + ] params["last_update_key"] = "last_update" query = " ".join( [ diff --git a/www/src/Pages/Collection.elm b/www/src/Pages/Collection.elm index cedc3ce..117ff66 100644 --- a/www/src/Pages/Collection.elm +++ b/www/src/Pages/Collection.elm @@ -48,6 +48,7 @@ decodeStatistics = type SortBy = PriceDescending | RarityDescending + | CreatedDescending type alias Criteria = @@ -124,6 +125,9 @@ searchQuery criteria = RarityDescending -> "rarity" + + CreatedDescending -> + "created" in [ Url.Builder.string "q" criteria.query , Url.Builder.string "sort_by" (toString criteria.sortBy) @@ -173,6 +177,7 @@ parseUrl = (Dict.fromList [ ( "rarity", RarityDescending ) , ( "price", PriceDescending ) + , ( "created", CreatedDescending ) ] ) |> Url.Parser.Query.map (Maybe.withDefault PriceDescending) @@ -386,6 +391,9 @@ sortDropdown = RarityDescending -> "Rarity DESC" + CreatedDescending -> + "Created DESC" + selectAttrs = [ Background.color UI.colors.secondary , Border.width 1 @@ -421,7 +429,12 @@ sortDropdown = toString sortBy in Dropdown.basic - { itemsFromModel = always [ PriceDescending, RarityDescending ] + { itemsFromModel = + always + [ PriceDescending + , RarityDescending + , CreatedDescending + ] , selectionFromModel = .criteria >> .sortBy >> Just , dropdownMsg = DropdownMsg , onSelectMsg = SortSelected