fix navigation between images being borked

This commit is contained in:
Luna D 2022-03-25 17:02:19 +01:00
parent b6248e22ee
commit 317a568521
No known key found for this signature in database
GPG key ID: 4B1C63448394F688
2 changed files with 7 additions and 0 deletions

View file

@ -9,6 +9,8 @@ defmodule PhilomenaWeb.ImageNavigator do
} }
def find_consecutive(conn, image, compiled_query, compiled_filter) do def find_consecutive(conn, image, compiled_query, compiled_filter) do
conn = update_in(conn.params, &Map.put_new(&1, "sf", "id"))
%{query: compiled_query, sorts: sorts} = ImageSorter.parse_sort(conn.params, compiled_query) %{query: compiled_query, sorts: sorts} = ImageSorter.parse_sort(conn.params, compiled_query)
sorts = sorts =

View file

@ -1,5 +1,6 @@
defmodule PhilomenaWeb.ImageSorter do defmodule PhilomenaWeb.ImageSorter do
@allowed_fields ~W( @allowed_fields ~W(
id
updated_at updated_at
first_seen_at first_seen_at
aspect_ratio aspect_ratio
@ -26,6 +27,10 @@ defmodule PhilomenaWeb.ImageSorter do
defp parse_sd(%{"sd" => sd}) when sd in ~W(asc desc), do: sd defp parse_sd(%{"sd" => sd}) when sd in ~W(asc desc), do: sd
defp parse_sd(_params), do: "desc" defp parse_sd(_params), do: "desc"
defp parse_sf(%{"sf" => sf}, sd, query) when sf == "id" do
%{query: query, sorts: [%{"id" => sd}]}
end
defp parse_sf(%{"sf" => sf}, sd, query) when sf in @allowed_fields do defp parse_sf(%{"sf" => sf}, sd, query) when sf in @allowed_fields do
%{query: query, sorts: [%{sf => sd}, %{"id" => sd}]} %{query: query, sorts: [%{sf => sd}, %{"id" => sd}]}
end end