mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +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
|
||||
|
||||
def recent_and_user_filters(user) do
|
||||
recent_filter_ids =
|
||||
[user.current_filter_id | user.recent_filter_ids]
|
||||
|> Enum.take(10)
|
||||
|
||||
user_filters =
|
||||
Filter
|
||||
|> select([f], %{id: f.id, name: f.name, recent: ^"f"})
|
||||
|
@ -150,10 +154,9 @@ defmodule Philomena.Filters do
|
|||
recent_filters =
|
||||
Filter
|
||||
|> select([f], %{id: f.id, name: f.name, recent: ^"t"})
|
||||
|> where([f], f.id in ^user.recent_filter_ids)
|
||||
|> limit(10)
|
||||
|> where([f], f.id in ^recent_filter_ids)
|
||||
|
||||
union(recent_filters, ^user_filters)
|
||||
union_all(recent_filters, ^user_filters)
|
||||
|> Repo.all()
|
||||
|> Enum.sort_by(fn f ->
|
||||
Enum.find_index(user.recent_filter_ids, fn id -> f.id == id end)
|
||||
|
|
Loading…
Reference in a new issue