defmodule ChirpWeb.PostLive.PostComponent do use ChirpWeb, :live_component @spec render(any) :: Phoenix.LiveView.Rendered.t() def render(assigns) do #IO.inspect(assigns.post.__meta__.state) ~H"""
<%= @post.username %>
<%= @post.body %>
<.link navigate={~p"/posts/#{@post}"} class="inline-flex items-center text-blue-600 hover:underline"> Show
<.link phx-click="like" phx-value-id={@post.id} phx-target={@myself}> <%= @post.likes_count %>
<.link phx-click="repost" phx-value-id={@post.id} phx-target={@myself}>
<%= @post.reposts_count %>
<.link patch={~p"/posts/#{@post}/edit"}>Edit
<.link phx-click={JS.push("delete", value: %{id: @post.id})} phx-target={@myself} data-confirm="Are you sure?"> Delete
""" end def handle_event("like", _, socket) do Chirp.Timeline.inc_likes(socket.assigns.post) {:noreply,socket} end def handle_event("repost", _, socket) do Chirp.Timeline.inc_reposts(socket.assigns.post) {:noreply,socket} end def handle_event("delete", %{"id" => id}, socket) do post = Chirp.Timeline.get_post!(id) {:ok, _} = Chirp.Timeline.delete_post(post) {:noreply, socket} end end