mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
always include user's current filter in recent filter list
fixes derpibooru/philomena#223 fixes furbooru/philomena#29 fixes furbooru/philomena#53
This commit is contained in:
parent
63bb8285d9
commit
26f280a3d2
1 changed files with 6 additions and 3 deletions
|
@ -141,6 +141,10 @@ defmodule Philomena.Filters do
|
||||||
end
|
end
|
||||||
|
|
||||||
def recent_and_user_filters(user) do
|
def recent_and_user_filters(user) do
|
||||||
|
recent_filter_ids =
|
||||||
|
[user.current_filter_id | user.recent_filter_ids]
|
||||||
|
|> Enum.take(10)
|
||||||
|
|
||||||
user_filters =
|
user_filters =
|
||||||
Filter
|
Filter
|
||||||
|> select([f], %{id: f.id, name: f.name, recent: ^"f"})
|
|> select([f], %{id: f.id, name: f.name, recent: ^"f"})
|
||||||
|
@ -150,10 +154,9 @@ defmodule Philomena.Filters do
|
||||||
recent_filters =
|
recent_filters =
|
||||||
Filter
|
Filter
|
||||||
|> select([f], %{id: f.id, name: f.name, recent: ^"t"})
|
|> select([f], %{id: f.id, name: f.name, recent: ^"t"})
|
||||||
|> where([f], f.id in ^user.recent_filter_ids)
|
|> where([f], f.id in ^recent_filter_ids)
|
||||||
|> limit(10)
|
|
||||||
|
|
||||||
union(recent_filters, ^user_filters)
|
union_all(recent_filters, ^user_filters)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.sort_by(fn f ->
|
|> Enum.sort_by(fn f ->
|
||||||
Enum.find_index(user.recent_filter_ids, fn id -> f.id == id end)
|
Enum.find_index(user.recent_filter_ids, fn id -> f.id == id end)
|
||||||
|
|
Loading…
Reference in a new issue