Skip to content

Commit

Permalink
final touches to the operation of the chat
Browse files Browse the repository at this point in the history
  • Loading branch information
silviaherguedas committed Feb 4, 2023
1 parent bd2bd04 commit 0298d3f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
11 changes: 2 additions & 9 deletions lib/chat/lobby_genserver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Chat.LobbyGenserver do
GenServer.cast(__MODULE__, {:create_room, name})
end

@spec join(pid()) :: :ok
@spec join(pid()) :: term
def join(pid) do
GenServer.call(__MODULE__, {:join, pid})
end
Expand Down Expand Up @@ -51,14 +51,7 @@ defmodule Chat.LobbyGenserver do
def handle_call({:join, pid}, _from, state) do
state = %{state | pids: MapSet.put(state.pids, pid)}
IO.inspect(state, label: "LobbyGS.join.state")

{:reply, state.rooms, state}
# if pid not in state.pids do
# state = %{state | pids: [pid | state.pids]}
# IO.inspect(state, label: "LobbyGS.join.state")
# {:noreply, state}
# else
# IO.inspect(state, label: "LobbyGS.join.state")
# {:noreply, state}
# end
end
end
13 changes: 8 additions & 5 deletions lib/chat_web/live/lobby_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule ChatWeb.LobbyLive do
@impl Phoenix.LiveView
def handle_event("new_room", value, socket) do
IO.inspect(value, label: "LobbyLive.new_room.value")
IO.inspect(socket.assigns, label: "LobbyLive.new_room.socket")
IO.inspect(socket.assigns, label: "LobbyLive.new_room.socket.assigns")

LobbyGenserver.create_room(value["new_room"]["room"])

Expand All @@ -28,15 +28,18 @@ defmodule ChatWeb.LobbyLive do

@impl Phoenix.LiveView
def handle_event("new_user", value, socket) do
socket = assign(socket, :user, value["new_user"]["username"])
IO.inspect(value, label: "LobbyLive.new_user.value")
IO.inspect(socket, label: "LobbyLive.new_user.socket")
{:noreply, assign(socket, :user, value["new_user"]["username"])}
IO.inspect(socket.assigns, label: "LobbyLive.new_user.socket.assigns")
{:noreply, socket}
end

@impl Phoenix.LiveView
def handle_info({:create_room, name}, socket) do
IO.inspect(socket, label: "LobbyLive.create_room.socket")
socket = assign(socket, :rooms, MapSet.put(socket.assigns.rooms, name))

IO.inspect(socket.assigns, label: "LobbyLive.create_room.socket.assigns")

{:noreply, assign(socket, :rooms, [name | socket.assigns])}
{:noreply, socket}
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Chat.MixProject do
version: "0.1.0",
elixir: "~> 1.12",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:gettext] ++ Mix.compilers(),
compilers: Mix.compilers(),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps()
Expand Down

0 comments on commit 0298d3f

Please sign in to comment.