Skip to content

Commit

Permalink
Merge pull request #1042 from phaleth/patch-9
Browse files Browse the repository at this point in the history
Fix inconsistencies in PicChat Messages and Auth readings
  • Loading branch information
BrooklinJazz authored Oct 12, 2023
2 parents 0833375 + 162ca07 commit 753b1ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion reading/pic_chat_authentication.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ For now, we'll implement a very simple solution. Hide the delete button if the m
```elixir
# Index.html.heex
<%= if assigns[:current_user] && @current_user == message.user_id do %>
<%= if assigns[:current_user] && @current_user.id == message.user_id do %>
<.link
phx-click={JS.push("delete", value: %{id: message.id}) |> hide("##{id}")}
data-confirm="Are you sure?"
Expand Down
11 changes: 9 additions & 2 deletions reading/pic_chat_messages.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Use the [LiveView Generators](https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Live.
<!-- livebook:{"force_markdown":true} -->

```elixir
mix phx.gen.live Messages Message messages content:text
mix phx.gen.live Chat Message messages content:text
```

<!-- livebook:{"break_markdown":true} -->
Expand Down Expand Up @@ -275,7 +275,14 @@ Elements are inserted into or removed from the stream.

```elixir
@impl true
def handle_info({PicChatWeb.MessageLive.FormComponent, {:saved, message}}, socket) do
def handle_info({PicChatWeb.MessageLive.FormComponent, {:new, message}}, socket) do
# prepends the new message
{:noreply, stream_insert(socket, :messages, message, at: 0)}
end

@impl true
def handle_info({PicChatWeb.MessageLive.FormComponent, {:edit, message}}, socket) do
# updates the new message in its current position
{:noreply, stream_insert(socket, :messages, message)}
end

Expand Down

0 comments on commit 753b1ea

Please sign in to comment.