add links
This commit is contained in:
parent
3842798968
commit
e2b802f968
54 changed files with 4984 additions and 6 deletions
37
lib/zoeyscomputer_web/live/link_live/new.ex
Normal file
37
lib/zoeyscomputer_web/live/link_live/new.ex
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
defmodule ZoeyscomputerWeb.LinkLive.New do
|
||||
use ZoeyscomputerWeb, :live_view
|
||||
|
||||
alias Zoeyscomputer.Links
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
changeset = Links.Link.changeset(%Links.Link{})
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> 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
|
||||
|> put_flash(:info, "Link created successfully")
|
||||
|> push_navigate(to: ~p"/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