-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49cf096
commit edc5a21
Showing
5 changed files
with
164 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
defmodule SafiraWeb.App.WheelLive.Components.Awards do | ||
@moduledoc """ | ||
Lucky wheel awards component. | ||
""" | ||
use SafiraWeb, :component | ||
|
||
attr :entries, :list, default: [] | ||
|
||
def awards(assigns) do | ||
~H""" | ||
<table class="w-full"> | ||
<tr class="border-b-2"> | ||
<th class="px-4 text-lg text-left">Name</th> | ||
<th class="px-4 text-lg text-center">Stock</th> | ||
<th class="px-4 text-lg text-center">Max. / Attendee</th> | ||
<th class="px-4 text-lg text-right">Probability</th> | ||
</tr> | ||
<%= for entry <- @entries do %> | ||
<tr> | ||
<td class="px-4 py-2 font-bold text-left"><%= entry_name(entry) %></td> | ||
<td class="px-4 py-2 font-bold text-center"><%= entry_stock(entry) %></td> | ||
<td class="px-4 py-2 text-center"><%= entry.max_per_attendee %></td> | ||
<td class="px-4 py-2 text-accent font-bold text-right"> | ||
<%= format_probability(entry.probability) %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
""" | ||
end | ||
|
||
defp entry_stock(drop) do | ||
if is_nil(drop.prize) do | ||
"∞" | ||
else | ||
drop.prize.stock | ||
end | ||
end | ||
|
||
defp format_probability(probability) do | ||
"#{probability * 100} %" | ||
end | ||
|
||
defp entry_name(drop) do | ||
cond do | ||
not is_nil(drop.prize) -> | ||
drop.prize.name | ||
|
||
not is_nil(drop.badge) -> | ||
drop.badge.name | ||
|
||
drop.entries > 0 -> | ||
"#{drop.entries} Entries" | ||
|
||
drop.tokens > 0 -> | ||
"#{drop.tokens} Tokens" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters