diff options
| author | Elizabeth (Lizzy) Hunt <elizabeth.hunt@simponic.xyz> | 2023-05-29 16:28:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-29 16:28:27 -0700 |
| commit | eec32aa38a8762eccc8575a37a628bd5ae2cc1d0 (patch) | |
| tree | 27f656780f5d25325c9ac0ec3db3557d774bf414 /lib/chessh/ssh/client/menus/select_joinable_game.ex | |
| parent | 8a5a2f358cb1f63a255b2daf6908536583986448 (diff) | |
| download | chessh-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/select_joinable_game.ex')
| -rw-r--r-- | lib/chessh/ssh/client/menus/select_joinable_game.ex | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/chessh/ssh/client/menus/select_joinable_game.ex b/lib/chessh/ssh/client/menus/select_joinable_game.ex index f2b7b1f..b0d0cbe 100644 --- a/lib/chessh/ssh/client/menus/select_joinable_game.ex +++ b/lib/chessh/ssh/client/menus/select_joinable_game.ex @@ -1,7 +1,8 @@ defmodule Chessh.SSH.Client.SelectJoinableGame do alias Chessh.{Utils, Repo, Game, PlayerSession} - alias Chessh.SSH.Client.GameSelector + alias Chessh.SSH.Client.Selector import Ecto.Query + require Logger use Chessh.SSH.Client.SelectPaginatePoller @@ -12,18 +13,20 @@ defmodule Chessh.SSH.Client.SelectJoinableGame do def dynamic_options(), do: true def get_player_joinable_games_with_id(player_id, current_id \\ nil, direction \\ :desc) do - GameSelector.paginate_ish_query( + Selector.paginate_ish_query( Game |> where([g], g.status == :continue) |> where( [g], (is_nil(g.dark_player_id) or is_nil(g.light_player_id)) and - (g.dark_player_id != ^player_id or g.light_player_id != ^player_id) + (g.dark_player_id != ^player_id or g.light_player_id != ^player_id) and + is_nil(g.bot_id) ) |> limit(^max_displayed_options()), current_id, direction ) + |> Repo.preload([:light_player, :dark_player, :bot]) end def format_game_selection_tuple(%Game{id: game_id} = game) do @@ -60,6 +63,8 @@ defmodule Chessh.SSH.Client.SelectJoinableGame do end def initial_options(%State{player_session: %PlayerSession{player_id: player_id}}) do + Logger.info(player_id) + get_player_joinable_games_with_id(player_id) |> Enum.map(&format_game_selection_tuple/1) end @@ -71,7 +76,7 @@ defmodule Chessh.SSH.Client.SelectJoinableGame do previous_last_game_id = case List.last(options) do {_label, id} -> id - _ -> 0 + _ -> 1 end current_screen_games = |
