diff --git a/assets/js/app.js b/assets/js/app.js index fa0eb3a..dcebec6 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -1,5 +1,6 @@ import "phoenix_html" import {Socket} from "phoenix" +// import {LiveSocket} from "./phoenix_live_view" import {LiveSocket} from "phoenix_live_view" import topbar from "../vendor/topbar" diff --git a/lib/live_beats_web/live/live_helpers.ex b/lib/live_beats_web/live/live_helpers.ex index 1c434ec..976f9e1 100644 --- a/lib/live_beats_web/live/live_helpers.ex +++ b/lib/live_beats_web/live/live_helpers.ex @@ -9,6 +9,60 @@ defmodule LiveBeatsWeb.LiveHelpers do Routes.song_index_path(socket, :index, socket.assigns.current_user.username) end + def flash(%{kind: :error} = assigns) do + ~H""" + <%= if live_flash(@flash, @kind) do %> +
+
+
+ <.icon name={:check_circle} solid /> +
+
+

+ <%= live_flash(@flash, @kind) %> +

+
+
+
+ +
+
+
+
+ <% end %> + """ + end + + def flash(%{kind: :info} = assigns) do + ~H""" + <%= if live_flash(@flash, @kind) do %> +
+
+
+ <.icon name={:check_circle} solid /> +
+
+

+ <%= live_flash(@flash, @kind) %> +

+
+
+
+ +
+
+
+
+ <% end %> + """ + end + def spinner(assigns) do ~H""" diff --git a/lib/live_beats_web/live/song_live/upload_form_component.ex b/lib/live_beats_web/live/song_live/upload_form_component.ex index c9c1512..7bf0716 100644 --- a/lib/live_beats_web/live/song_live/upload_form_component.ex +++ b/lib/live_beats_web/live/song_live/upload_form_component.ex @@ -41,6 +41,10 @@ defmodule LiveBeatsWeb.SongLive.UploadFormComponent do {:noreply, apply_params(socket, params, :validate)} end + def handle_event("validate", %{"_target" => ["mp3"]}, socket) do + {:noreply, drop_invalid_uploads(socket)} + end + def handle_event("save", %{"songs" => params}, socket) do socket = apply_params(socket, params, :insert) %{current_user: current_user} = socket.assigns @@ -62,6 +66,10 @@ defmodule LiveBeatsWeb.SongLive.UploadFormComponent do end end + def handle_event("save", %{} = _params, socket) do + {:noreply, socket} + end + defp pending_stats?(socket) do Enum.find(socket.assigns.changesets, fn {_ref, chset} -> !chset.changes[:duration] end) end diff --git a/lib/live_beats_web/templates/layout/live.html.heex b/lib/live_beats_web/templates/layout/live.html.heex index f0e1fd0..3981d81 100644 --- a/lib/live_beats_web/templates/layout/live.html.heex +++ b/lib/live_beats_web/templates/layout/live.html.heex @@ -1,17 +1,12 @@ -
+
<.live_component module={LiveBeatsWeb.LayoutComponent} id="layout" /> <%= if @current_user do %> <%= live_render(@socket, LiveBeatsWeb.PlayerLive, id: "player", session: %{}, sticky: true) %> <% end %> -
- - + <.flash flash={@flash} kind={:info}/> + <.flash flash={@flash} kind={:error}/> <%= @inner_content %> diff --git a/mix.exs b/mix.exs index 7b474a0..1e92211 100644 --- a/mix.exs +++ b/mix.exs @@ -39,8 +39,8 @@ defmodule LiveBeats.MixProject do {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 3.0"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, - # {:phoenix_live_view, path: "~/oss/phoenix_live_view", override: true}, - {:phoenix_live_view, github: "phoenixframework/phoenix_live_view", branch: "cm-sticky-live-render", override: true}, + {:phoenix_live_view, path: "~/oss/phoenix_live_view", override: true}, + # {:phoenix_live_view, github: "phoenixframework/phoenix_live_view", branch: "cm-sticky-live-render", override: true}, {:floki, ">= 0.30.0", only: :test}, {:phoenix_live_dashboard, "~> 0.5"}, {:esbuild, "~> 0.2", runtime: Mix.env() == :dev},