Skip to content

Commit 709f256

Browse files
committed
feat: add button to create room with custom bet
1 parent de11f8d commit 709f256

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

lib/safira_web/components/button.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ defmodule SafiraWeb.Components.Button do
44
"""
55
use SafiraWeb, :component
66

7+
import SafiraWeb.CoreComponents
8+
79
attr :title, :string, default: ""
810
attr :subtitle, :string, default: ""
911
attr :disabled, :boolean, default: false
12+
attr :icon, :string, default: ""
1013
attr :class, :string, default: ""
1114

1215
attr :rest, :global,
@@ -21,6 +24,9 @@ defmodule SafiraWeb.Components.Button do
2124
disabled={@disabled}
2225
{@rest}
2326
>
27+
<%= if @icon != "" do %>
28+
<.icon name={@icon} />
29+
<% end %>
2430
<p class="uppercase font-terminal text-2xl"><%= @title %></p>
2531
<p class="font-terminal"><%= @subtitle %></p>
2632
</button>

lib/safira_web/live/app/coin_flip_live/index.ex

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ defmodule SafiraWeb.App.CoinFlipLive.Index do
2222
|> assign(:result, nil)
2323
|> assign(:wheel_active?, Minigames.wheel_active?())
2424
|> assign(:playing, false)
25+
|> assign(:bet, 10)
2526
|> stream(:room_list, Minigames.list_coin_flip_rooms())}
2627
end
2728

@@ -36,8 +37,11 @@ defmodule SafiraWeb.App.CoinFlipLive.Index do
3637
|> push_event("spin-wheel", %{})}
3738
end
3839

39-
def handle_event("create-room", params, socket) do
40-
params = Map.put(params, "player1_id", socket.assigns.current_user.attendee.id)
40+
def handle_event("create-room", _params, socket) do
41+
params = %{
42+
"player1_id" => socket.assigns.current_user.attendee.id,
43+
"bet" => socket.assigns.bet
44+
}
4145

4246
case Minigames.create_coin_flip_room(params) do
4347
{:ok, room} ->
@@ -93,6 +97,20 @@ defmodule SafiraWeb.App.CoinFlipLive.Index do
9397
|> stream_insert(:room_list, room)}
9498
end
9599

100+
@impl true
101+
def handle_event("decrease-bet", _params, socket) do
102+
{:noreply,
103+
socket
104+
|> assign(:bet, socket.assigns.bet - 10)}
105+
end
106+
107+
@impl true
108+
def handle_event("increase-bet", _params, socket) do
109+
{:noreply,
110+
socket
111+
|> assign(:bet, socket.assigns.bet + 10)}
112+
end
113+
96114
@impl true
97115
def handle_params(_params, _url, socket) do
98116
{:noreply, socket}

lib/safira_web/live/app/coin_flip_live/index.html.heex

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
<.page title={gettext("Coin Flip")} size={:xl} title_class="font-terminal uppercase">
22
<:actions>
3-
<.button phx-click="create-room" phx-value-bet={10}>+</.button>
43
<span class="text-semibold text-xl border-2 px-4 py-2 rounded-full font-terminal">
54
💰 <%= @attendee_tokens %>
65
</span>
76
</:actions>
8-
<div class="flex flex-row justify-center w-full pt-16">
9-
<%!-- <.action_button
10-
title={gettext("Spin")}
11-
subtitle={"💰 #{@wheel_price}"}
12-
class="w-64"
7+
<div class="flex justify-center w-full">
8+
<.action_button
9+
icon="hero-minus"
10+
class="rounded-r-lg pl-6 pr-5"
11+
disabled={false}
12+
phx-click="decrease-bet"
13+
/>
14+
<.action_button
15+
title={gettext("Play")}
16+
subtitle={"💰 #{@bet}"}
17+
class="rounded-none px-10"
1318
disabled={false}
1419
phx-click="create-room"
15-
phx-value-bet={10}
16-
/> --%>
20+
/>
21+
<.action_button
22+
icon="hero-plus"
23+
class="rounded-l-lg pr-6 pl-5"
24+
disabled={false}
25+
phx-click="increase-bet"
26+
/>
27+
</div>
28+
<div class="flex flex-row justify-center w-full pt-16">
1729
</div>
1830
<h2 class="text-3xl font-semibold font-terminal">Current games:</h2>
1931
<div
@@ -61,4 +73,4 @@
6173
show
6274
id="confirm"
6375
on_cancel={JS.push("close-modal")}
64-
/> --%>
76+
/> --%>

0 commit comments

Comments
 (0)