diff --git a/lib/chat/lobby_genserver.ex b/lib/chat/lobby_genserver.ex index bae8852..97383d2 100644 --- a/lib/chat/lobby_genserver.ex +++ b/lib/chat/lobby_genserver.ex @@ -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 @@ -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 diff --git a/lib/chat_web/live/lobby_live.ex b/lib/chat_web/live/lobby_live.ex index 07ae91a..bced971 100644 --- a/lib/chat_web/live/lobby_live.ex +++ b/lib/chat_web/live/lobby_live.ex @@ -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"]) @@ -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 diff --git a/mix.exs b/mix.exs index ea497e1..7f06e64 100644 --- a/mix.exs +++ b/mix.exs @@ -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()