Skip to content

Commit 8fb50ca

Browse files
committed
Now the users are able to create performances in karaokes when they have the status in 'ready'
1 parent 8d967eb commit 8fb50ca

File tree

6 files changed

+48
-42
lines changed

6 files changed

+48
-42
lines changed

lib/karaokium_web/live/admin/karaoke_live/show.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
</section>
176176
<div>
177177
<span>
178-
<%= live_patch("New Performance", to: Routes.admin_performance_new_path(@socket, :new, @karaoke.id)) %>
178+
<%= live_patch("New Performance", to: Routes.admin_performance_new_path(@socket, :new, @karaoke.id, "admin")) %>
179179
</span>
180180
</div>
181181
<% end %>

lib/karaokium_web/live/admin/performance_live/new.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ defmodule KaraokiumWeb.Admin.PerformanceLive.New do
1010
end
1111

1212
@impl true
13-
def handle_params(%{"karaoke_id" => karaoke_id}, _, socket) do
13+
def handle_params(%{"karaoke_id" => karaoke_id, "return_to" => return_to}, _, socket) do
1414
{:noreply,
1515
socket
1616
|> assign(:performance, %Performance{})
1717
|> assign(:page_title, "New Performance")
18-
|> assign(:karaoke_id, karaoke_id)}
18+
|> assign(:karaoke_id, karaoke_id)
19+
|> assign(:return_to, return_to)}
1920
end
2021
end
Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
<.live_component
2-
module={KaraokiumWeb.Admin.PerformanceLive.FormComponent}
3-
id={:new}
4-
karaoke_id={@karaoke_id}
5-
performance={@performance}
6-
title="New performance"
7-
action={:new}
8-
return_to={Routes.admin_karaoke_show_path(@socket, :show, @karaoke_id)}
9-
/>
1+
<%= if @return_to == "live" do %>
2+
<.live_component
3+
module={KaraokiumWeb.Admin.PerformanceLive.FormComponent}
4+
id={:new}
5+
karaoke_id={@karaoke_id}
6+
performance={@performance}
7+
title="New performance"
8+
action={:new}
9+
return_to={Routes.karaoke_show_path(@socket, :show, @karaoke_id)}
10+
/>
11+
<% else %>
12+
<.live_component
13+
module={KaraokiumWeb.Admin.PerformanceLive.FormComponent}
14+
id={:new}
15+
karaoke_id={@karaoke_id}
16+
performance={@performance}
17+
title="New performance"
18+
action={:new}
19+
return_to={Routes.admin_karaoke_show_path(@socket, :show, @karaoke_id)}
20+
/>
21+
<% end %>

lib/karaokium_web/live/karaoke_live/show.ex

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ defmodule KaraokiumWeb.KaraokeLive.Show do
9090
"""
9191
end
9292

93-
def status(%{karaoke: karaoke} = assigns) when karaoke.status == :ready do
94-
~H"""
95-
<.status
96-
img={Routes.static_path(KaraokiumWeb.Endpoint, "/karaokium/images/illustrations/undraw/happy_music.svg")}
97-
text={"#{@karaoke.name} - Starting soon"}
98-
/>
99-
"""
100-
end
101-
10293
def status(%{karaoke: karaoke} = assigns) when karaoke.status == :finished do
10394
~H"""
10495
<section>

lib/karaokium_web/live/karaoke_live/show.html.heex

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
<%= unless is_nil(@karaoke.performing_id) do %>
44
<section style="margin-top: -50px;">
55
<aside style="padding: 0;">
6-
<img
7-
id="cover-album"
8-
style="border-radius: 4px 4px 0 0;"
9-
alt={@karaoke.performing.song.album.name}
10-
src={hd(@karaoke.performing.song.album.images).url}
11-
height="285"
12-
/>
6+
<img id="cover-album" style="border-radius: 4px 4px 0 0;" height="285" />
137
<div style="padding: 0 0.5rem;">
14-
<h3 style="margin: 0;"><%= @karaoke.performing.song.name %></h3>
15-
<p>
16-
<strong><%= @karaoke.performing.song.album.name %></strong>
17-
</p>
188
<p>
199
<em><%= Enum.map(@karaoke.performing.song.artists, & &1.name) |> Enum.join(", ") %></em>
2010
</p>
21-
<center>
11+
<div class="text-center">
2212
<table style="padding: 0; margin-bottom: 10px;">
2313
<tbody>
2414
<tr>
@@ -33,7 +23,7 @@
3323
<% end %>
3424
</tbody>
3525
</table>
36-
</center>
26+
</div>
3727
</div>
3828
</aside>
3929
</section>
@@ -45,7 +35,7 @@
4535
<%= emoji %> <%= reaction_count(@reactions, emoji) %>
4636
</button>
4737
<% else %>
48-
<div class="button" onmousedown={"reactions(this, '#{emoji}')"}>
38+
<div class="button">
4939
<button
5040
phx-throttle="1000"
5141
phx-click="react"
@@ -64,15 +54,27 @@
6454
<header>
6555
<h2>Vote now!</h2>
6656
</header>
67-
<%= for pontuation <- 1..10 do %>
68-
<button phx-click="vote" phx-value-pontuation={pontuation} style="font-size: 30px; margin: 10px;">
69-
<%= pontuation %>
70-
</button>
71-
<% end %>
57+
<div class="text-center">
58+
<%= for pontuation <- 1..10 do %>
59+
<button phx-click="vote" phx-value-pontuation={pontuation} style="font-size: 30px; margin: 10px;">
60+
<%= pontuation %>
61+
</button>
62+
<% end %>
63+
</div>
7264
<% end %>
7365
</section>
7466
<% end %>
7567
<% else %>
76-
<.status karaoke={@karaoke} />
68+
<%= if @karaoke.status == :ready do %>
69+
<.status
70+
img={Routes.static_path(KaraokiumWeb.Endpoint, "/karaokium/images/illustrations/undraw/happy_music.svg")}
71+
text={"#{@karaoke.name} - Starting soon"}
72+
/>
73+
<span>
74+
<%= live_patch("Create Performance", to: Routes.admin_performance_new_path(@socket, :new, @karaoke.id, "live")) %>
75+
</span>
76+
<% else %>
77+
<.status karaoke={@karaoke} />
78+
<% end %>
7779
<% end %>
7880
</div>

lib/karaokium_web/router.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ defmodule KaraokiumWeb.Router do
101101
live "/:id/show/edit", KaraokeLive.Show, :edit
102102

103103
live "/:karaoke_id/performances", PerformanceLive.Index, :index
104-
live "/:karaoke_id/performances/new", PerformanceLive.New, :new
104+
live "/:karaoke_id/performances/new/:return_to", PerformanceLive.New, :new
105105
live "/:karaoke_id/performances/:id/edit", PerformanceLive.Edit, :edit
106106
live "/:karaoke_id/performances/:id", PerformanceLive.Show, :show
107107
live "/:karaoke_id/performances/:id/show/edit", PerformanceLive.Show, :edit

0 commit comments

Comments
 (0)