Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Used by "mix format"
[
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations"],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
import_deps: [:ecto, :ecto_sql, :phoenix]
]
17 changes: 14 additions & 3 deletions lib/slax_web/live/chat_room/helpers/room_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ defmodule SlaxWeb.Live.ChatRoom.Helpers.Room do
{:error, "Invalid input: max_rooms_supported must be a positive number"}

"""
def build_chat_room(max_rooms_supported) when is_number(max_rooms_supported) and max_rooms_supported > 0 do
def build_chat_room(max_rooms_supported)
when is_number(max_rooms_supported) and max_rooms_supported > 0 do
room_id = Enum.random(0..max_rooms_supported)
room_name = generate_room_name_random(room_id)

{:ok, %Room{room_id: room_id, room_name: room_name, user_connected_count: @initial_users_in_room}}
{:ok,
%Room{room_id: room_id, room_name: room_name, user_connected_count: @initial_users_in_room}}
end

# Error handling for invalid inputs (non-numbers or non-positive numbers)
Expand All @@ -66,7 +68,16 @@ defmodule SlaxWeb.Live.ChatRoom.Helpers.Room do
def anyone_connected?(chat_room), do: chat_room.user_connected_count > 0

defp generate_room_name_random(room_id) do
marvel_heroes_names = ["Iron man", "Spider-man", "Hawkeye", "Nick Furry", "Nebula", "Ant-man", "Phoenix", "Wanda"]
marvel_heroes_names = [
"Iron man",
"Spider-man",
"Hawkeye",
"Nick Furry",
"Nebula",
"Ant-man",
"Phoenix",
"Wanda"
]

# Ensure the list is not empty before attempting random selection
if length(marvel_heroes_names) == 0 do
Expand Down
2 changes: 1 addition & 1 deletion lib/slax_web/live/chat_room/page/room_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule SlaxWeb.Live.ChatRoom.Page do
<%= "You are among #{@chat_room_entity.user_connected_count - 1} users connected" %>
</div>
<% else %>
<div>No one else is connected here except for you 🥲 </div>
<div>No one else is connected here except for you 🥲</div>
<% end %>
</div>
"""
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule Slax.MixProject do
{:jason, "~> 1.2"},
{:dns_cluster, "~> 0.1.1"},
{:bandit, "~> 1.5"},
{:dotenv, "~> 3.0.0"},
{:dotenv, "~> 3.0.0"}
]
end

Expand Down