diff --git a/lib/alternis/engines/dictionary_engine_impl.ex b/lib/alternis/engines/dictionary_engine_impl.ex
index 1870765..5a271e7 100644
--- a/lib/alternis/engines/dictionary_engine_impl.ex
+++ b/lib/alternis/engines/dictionary_engine_impl.ex
@@ -32,7 +32,7 @@ defmodule Alternis.Engines.DictionaryEngine.Impl do
where: ^condition,
where: d.language == ^language,
select_merge: %{language: d.language},
- order_by: w.frequency,
+ order_by: fragment("RANDOM()"),
limit: 1
)
end
diff --git a/lib/alternis/guess.ex b/lib/alternis/guess.ex
index b87fbcc..09b440b 100644
--- a/lib/alternis/guess.ex
+++ b/lib/alternis/guess.ex
@@ -31,6 +31,10 @@ defmodule Alternis.Guess do
|> validate_required([:word, :bulls, :cows, :exact?])
end
+ def priority(guess) do
+ length(guess.bulls) * 10 + length(guess.cows)
+ end
+
def validate_word(attrs \\ %{}) do
%Guess{}
|> cast(attrs, [:word])
diff --git a/lib/alternis_web/live/game_live/game_component.ex b/lib/alternis_web/live/game_live/game_component.ex
index 1085348..20e66a3 100644
--- a/lib/alternis_web/live/game_live/game_component.ex
+++ b/lib/alternis_web/live/game_live/game_component.ex
@@ -2,6 +2,7 @@ defmodule AlternisWeb.GameLive.GameComponent do
use Phoenix.Component
attr :guesses, :list, required: true
+ attr :update, :string, default: "append"
slot :header
slot :footer
@@ -9,7 +10,7 @@ defmodule AlternisWeb.GameLive.GameComponent do
~H"""
<%= render_slot(@header) %>
-
+
<%= for guess <- @guesses do %>
-
<%= guess.user.username %>: <%= guess.word %> - bulls: <%= length(guess.bulls) %>, cows: <%= length(
diff --git a/lib/alternis_web/live/game_live/index.html.heex b/lib/alternis_web/live/game_live/index.html.heex
index af148a6..eed4347 100644
--- a/lib/alternis_web/live/game_live/index.html.heex
+++ b/lib/alternis_web/live/game_live/index.html.heex
@@ -24,4 +24,4 @@
-<%= live_redirect "New Game", to: ~p"/games/new" %>
+<.link navigate={~p"/games/new"}>New Game
diff --git a/lib/alternis_web/live/game_live/show.ex b/lib/alternis_web/live/game_live/show.ex
index 1e80053..83e221d 100644
--- a/lib/alternis_web/live/game_live/show.ex
+++ b/lib/alternis_web/live/game_live/show.ex
@@ -5,6 +5,7 @@ defmodule AlternisWeb.GameLive.Show do
alias Alternis.Landing
alias Alternis.Game.GameState.{Expired, Finished}
+ alias Alternis.Guess
@game_ended_event "game_ended"
@guess_placed_event "guess_placed"
@@ -25,6 +26,7 @@ defmodule AlternisWeb.GameLive.Show do
{:ok,
socket
|> assign(:game, game)
+ |> assign(:update, "append")
|> assign(:current_user, user)
|> assign(:players, online_players(game.id))
|> assign(:guesses, game.guesses), temporary_assigns: [guesses: []]}
@@ -33,7 +35,10 @@ defmodule AlternisWeb.GameLive.Show do
@impl true
def handle_info(%{event: @guess_placed_event, payload: %{guess: guess}}, socket) do
- {:noreply, assign(socket, :guesses, [guess])}
+ {:noreply,
+ socket
+ |> assign(:update, "append")
+ |> assign(:guesses, [guess])}
end
def handle_info(%{event: @game_ended_event}, socket) do
@@ -44,6 +49,22 @@ defmodule AlternisWeb.GameLive.Show do
{:noreply, socket |> assign(:players, online_players(game_id))}
end
+ @impl true
+ def handle_event("order_top", %{"game_id" => game_id}, socket) do
+ case Landing.get_game!(game_id) do
+ nil ->
+ raise AlternisWeb.GameLive.GameNotFoundError
+
+ game ->
+ sorted = Enum.sort(game.guesses, &(Guess.priority(&1) > Guess.priority(&2)))
+
+ {:noreply,
+ socket
+ |> assign(:update, "replace")
+ |> assign(:guesses, sorted)}
+ end
+ end
+
@impl true
def handle_params(_params, _session, socket = %{assigns: %{game: game}}) do
case game.state do
diff --git a/lib/alternis_web/live/game_live/show.html.heex b/lib/alternis_web/live/game_live/show.html.heex
index fe0e63f..cff4780 100644
--- a/lib/alternis_web/live/game_live/show.html.heex
+++ b/lib/alternis_web/live/game_live/show.html.heex
@@ -22,13 +22,15 @@
<% end %>
- <.timeline guesses={@guesses}>
+ <.timeline guesses={@guesses} update={@update}>
<:header>
Language:
<%= Recase.to_pascal(@game.language.value) %>
Secret:
<%= String.pad_leading("", String.length(@game.secret), "*") %>
+
+
<:footer>
<%= if @game.in_progress? do %>