diff --git a/lib/radiator_web/live/admin_live/index.ex b/lib/radiator_web/live/admin_live/index.ex index bdc20149..8e5e5078 100644 --- a/lib/radiator_web/live/admin_live/index.ex +++ b/lib/radiator_web/live/admin_live/index.ex @@ -8,6 +8,7 @@ defmodule RadiatorWeb.AdminLive.Index do @impl true def mount(_params, _session, socket) do socket + |> assign(:action, nil) |> assign(:page_title, "Admin Dashboard") |> assign(:page_description, "Tools to create and manage your prodcasts") |> assign(:networks, Podcast.list_networks(preload: :shows)) @@ -15,6 +16,52 @@ defmodule RadiatorWeb.AdminLive.Index do |> reply(:ok) end + @impl true + def handle_event("new", _params, socket) do + network = %Podcast.Network{} + changeset = Podcast.change_network(network) + + socket + |> assign(:action, :new) + |> assign(:network, network) + |> assign(:form, to_form(changeset)) + |> reply(:noreply) + end + + def handle_event("validate", %{"network" => params}, socket) do + changeset = + socket.assigns.network + |> Podcast.change_network(params) + |> Map.put(:action, :validate) + + socket + |> assign(:form, to_form(changeset)) + |> reply(:noreply) + end + + def handle_event("save", %{"network" => params}, socket) do + case Podcast.create_network(params) do + {:ok, _network} -> + socket + |> put_flash(:info, "Network created successfully") + |> reply(:noreply) + + {:error, %Ecto.Changeset{} = changeset} -> + socket + |> assign(:form, to_form(changeset)) + |> reply(:noreply) + end + end + + def handle_event("delete", %{"id" => id}, socket) do + network = Podcast.get_network!(id) + {:ok, _} = Podcast.delete_network(network) + + socket + # |> stream_delete(:networks, network)} + |> reply(:noreply) + end + defp get_bookmarklet(api_uri, socket) do token = socket.assigns.current_user diff --git a/lib/radiator_web/live/admin_live/index.html.heex b/lib/radiator_web/live/admin_live/index.html.heex index 8e9655b3..eda5a877 100644 --- a/lib/radiator_web/live/admin_live/index.html.heex +++ b/lib/radiator_web/live/admin_live/index.html.heex @@ -1,7 +1,13 @@