update things
This commit is contained in:
parent
984a193c5d
commit
b2f2f57029
6 changed files with 27 additions and 9 deletions
|
|
@ -88,7 +88,7 @@ defmodule ZoeyscomputerWeb.GistLive.FormComponent do
|
|||
end
|
||||
|
||||
defp save_gist(socket, :new, gist_params) do
|
||||
case Gists.create_gist(gist_params) do
|
||||
case Gists.create_gist(socket.assigns.current_user, gist_params) do
|
||||
{:ok, gist} ->
|
||||
notify_parent({:saved, gist})
|
||||
|
||||
|
|
@ -98,6 +98,7 @@ defmodule ZoeyscomputerWeb.GistLive.FormComponent do
|
|||
|> push_patch(to: socket.assigns.patch)}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
IO.inspect(changeset)
|
||||
{:noreply, assign(socket, form: to_form(changeset))}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,13 @@ defmodule ZoeyscomputerWeb.GistLive.Index do
|
|||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, stream(socket, :gists, Gists.list_gists())}
|
||||
socket = socket |> assign(:current_user, socket.assigns.current_user)
|
||||
|
||||
if connected?(socket) && socket.assigns.current_user do
|
||||
{:ok, stream(socket, :gists, Gists.list_gists())}
|
||||
else
|
||||
{:ok, stream(socket, :gists, [])}
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
|
@ -18,12 +24,14 @@ defmodule ZoeyscomputerWeb.GistLive.Index do
|
|||
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Edit Gist")
|
||||
|> assign(:current_user, socket.assigns.current_user)
|
||||
|> assign(:gist, Gists.get_gist!(id))
|
||||
end
|
||||
|
||||
defp apply_action(socket, :new, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "New Gist")
|
||||
|> assign(:current_user, socket.assigns.current_user)
|
||||
|> assign(:gist, %Gist{
|
||||
code: "",
|
||||
lang: nil
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
id={@gist.id || :new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
current_user={@current_user}
|
||||
gist={@gist}
|
||||
patch={~p"/gists"}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
<%= @gist.title || "Gist: #{@gist.id}" %>
|
||||
<:subtitle>This is a gist record from your database.</:subtitle>
|
||||
<:actions>
|
||||
<.link patch={~p"/gists/#{@gist}/show/edit"} phx-click={JS.push_focus()}>
|
||||
<.button>Edit gist</.button>
|
||||
</.link>
|
||||
<%= if(@current_user && @gist.author.email == @current_user.email) do %>
|
||||
<.link patch={~p"/gists/#{@gist}/show/edit"} phx-click={JS.push_focus()}>
|
||||
<.button>Edit gist</.button>
|
||||
</.link>
|
||||
<% end %>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue