summaryrefslogtreecommitdiff
path: root/lib/chessh/ssh/client/menus/selector.ex
diff options
context:
space:
mode:
authorElizabeth (Lizzy) Hunt <elizabeth.hunt@simponic.xyz>2023-05-29 16:28:27 -0700
committerGitHub <noreply@github.com>2023-05-29 16:28:27 -0700
commiteec32aa38a8762eccc8575a37a628bd5ae2cc1d0 (patch)
tree27f656780f5d25325c9ac0ec3db3557d774bf414 /lib/chessh/ssh/client/menus/selector.ex
parent8a5a2f358cb1f63a255b2daf6908536583986448 (diff)
downloadchessh-eec32aa38a8762eccc8575a37a628bd5ae2cc1d0.tar.gz
chessh-eec32aa38a8762eccc8575a37a628bd5ae2cc1d0.zip
Bots (#23)
* squash all the things for bots * fix warnings * change colors a bit and README updates * fix frontend warnings
Diffstat (limited to 'lib/chessh/ssh/client/menus/selector.ex')
-rw-r--r--lib/chessh/ssh/client/menus/selector.ex23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/chessh/ssh/client/menus/selector.ex b/lib/chessh/ssh/client/menus/selector.ex
new file mode 100644
index 0000000..225c41f
--- /dev/null
+++ b/lib/chessh/ssh/client/menus/selector.ex
@@ -0,0 +1,23 @@
+defmodule Chessh.SSH.Client.Selector do
+ import Ecto.Query
+ alias Chessh.Repo
+
+ def paginate_ish_query(query, current_id, direction) do
+ sorted_query =
+ if direction == :desc,
+ do: from(g in query, order_by: [desc: g.id]),
+ else: from(g in query, order_by: [asc: g.id])
+
+ results =
+ if !is_nil(current_id) do
+ if direction == :desc,
+ do: from(g in sorted_query, where: g.id < ^current_id),
+ else: from(g in sorted_query, where: g.id > ^current_id)
+ else
+ sorted_query
+ end
+ |> Repo.all()
+
+ if direction == :desc, do: results, else: Enum.reverse(results)
+ end
+end