add links
This commit is contained in:
parent
3842798968
commit
e2b802f968
54 changed files with 4984 additions and 6 deletions
39
lib/zoeyscomputer_web/live/link_live/index.ex
Normal file
39
lib/zoeyscomputer_web/live/link_live/index.ex
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
defmodule ZoeyscomputerWeb.LinkLive.Index do
|
||||
use ZoeyscomputerWeb, :live_view
|
||||
|
||||
alias Zoeyscomputer.Links
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
user_id = socket.assigns.current_user.id
|
||||
|
||||
changeset = Links.Link.changeset(%Links.Link{})
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> assign(:links, Links.list_links(user_id))
|
||||
|> assign(:form, to_form(changeset))
|
||||
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
def handle_event("submit", %{"link" => link_params}, socket) do
|
||||
params =
|
||||
link_params
|
||||
|> Map.put("user_id", socket.assigns.current_user.id)
|
||||
|
||||
case Links.create_link(params) do
|
||||
{:ok, link} ->
|
||||
socket =
|
||||
socket
|
||||
|> assign(:links, [link | socket.assigns.links])
|
||||
|
||||
{:noreply, socket}
|
||||
|
||||
{:error, changeset} ->
|
||||
socket
|
||||
|> assign(:form, to_form(changeset))
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue