Skip to content

Commit

Permalink
Check for existing accolade
Browse files Browse the repository at this point in the history
  • Loading branch information
jauggy committed Jan 9, 2025
1 parent 59e4fec commit e535cc9
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 22 deletions.
27 changes: 17 additions & 10 deletions assets/scss/custom/_styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
margin: 0;
}

html, body {
html,
body {
min-height: 100%;
height: 100%;
}

body {
overflow-x: hidden;
overflow-x: auto;
margin: 0;
}

Expand All @@ -25,7 +26,8 @@ body {
border-bottom: 1px solid $top-nav-bottom-border-colour;
}

#top-nav .navbar-brand, #top-nav .nav-item a {
#top-nav .navbar-brand,
#top-nav .nav-item a {
color: $top-nav-item-colour;
}

Expand All @@ -49,9 +51,11 @@ body {
.alert p {
margin-bottom: 0;
}

.alert:empty {
display: none;
}

.invalid-feedback {
color: $invalid-feedback;
display: block;
Expand All @@ -69,24 +73,25 @@ body {
transition: opacity 1s ease-out;
}

.phx-disconnected{
.phx-disconnected {
cursor: wait;
}
.phx-disconnected *{

.phx-disconnected * {
pointer-events: none;
}

.phx-modal {
opacity: 1!important;
opacity: 1 !important;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
}

.phx-modal-content {
Expand Down Expand Up @@ -123,7 +128,8 @@ body {
transition: all 300ms linear;
}

.menu-card a, .menu-card span {
.menu-card a,
.menu-card span {
/*border: 1px solid #000;*/

display: block;
Expand All @@ -147,7 +153,8 @@ body {
transition: all 200ms linear;
}

.menu-card a:hover, .menu-card span:hover {
.menu-card a:hover,
.menu-card span:hover {
color: $menu-card-link-colour-hover;

cursor: pointer;
Expand Down
15 changes: 15 additions & 0 deletions lib/teiserver/account/libs/accolade_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,19 @@ defmodule Teiserver.Account.AccoladeLib do
[[count]] = results.rows
count
end

def does_accolade_exist?(giver_id, recipient_id, match_id) do
query = """
select count(*) from teiserver_account_accolades taa
where taa.giver_id = $1
and taa.recipient_id = $2
and taa.match_id = $3
"""

results =
Ecto.Adapters.SQL.query!(Repo, query, [giver_id, recipient_id, match_id])

[[count]] = results.rows
count > 0
end
end
2 changes: 1 addition & 1 deletion lib/teiserver/libs/teiserver_configs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule Teiserver.TeiserverConfigs do
type: "integer",
permissions: ["Server"],
description: "The number of accolades you can gift within the allocated window.",
default: 10
default: 20
})

add_site_config_type(%{
Expand Down
38 changes: 30 additions & 8 deletions lib/teiserver_web/live/battles/match/give_accolade/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,39 @@ defmodule TeiserverWeb.Battle.GiveAccoladeLive.Index do
user_id = socket.assigns.current_user.id
gift_count = AccoladeLib.get_number_of_gifted_accolades(user_id, gift_window)
gift_limit = socket.assigns.gift_limit
recipient_id = socket.assigns.user.id
match_id = socket.assigns.match_id

if gift_count >= gift_limit do
socket
|> assign(
:failure_reason,
"You can only gift #{gift_limit} accolades every #{gift_window} days."
)
|> assign(:stage, :not_allowed)
else
with :ok <- check_gift_count(user_id, gift_limit, gift_window),
:ok <- check_already_gifted(user_id, recipient_id, match_id) do
socket
|> assign(:gift_count, gift_count)
else
{:error, reason} ->
socket
|> assign(
:failure_reason,
reason
)
|> assign(:stage, :not_allowed)
end
end

defp check_gift_count(user_id, gift_limit, gift_window) do
gift_count = AccoladeLib.get_number_of_gifted_accolades(user_id, gift_window)

if gift_count >= gift_limit do
{:error, "You can only give #{gift_limit} accolades every #{gift_window} days."}
else
:ok
end
end

defp check_already_gifted(user_id, recipient_id, match_id) do
if AccoladeLib.does_accolade_exist?(user_id, recipient_id, match_id) do
{:error, "You have already given an accolade to this user for this match."}
else
:ok
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
</div>

<div :if={@stage == :form} class="card-footer">
You can give this player an accolade if you feel they deserve to be acknowledged for their positive behaviour in a match. You can only give <%= @gift_limit %> accolades every <%= @gift_window %> days.
(You have gifted <%= @gift_count %> accolades over the past <%= @gift_window %> days.)
You can give this player an accolade if you feel they deserve to be acknowledged for their positive behaviour in a match. You can give <%= @gift_limit %> accolades in a rolling <%= @gift_window %>-day window.
(You have given <%= @gift_count %> accolades over the past <%= @gift_window %> days.)
<br /><br />

<table class="table table-sm">
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/live/battles/match/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<% end %>
</div>

<div :if={@tab == :players} class="p-4" style="overflow-x:auto">
<div :if={@tab == :players} class="p-4">
<table class="table table-sm">
<thead>
<tr>
Expand Down

0 comments on commit e535cc9

Please sign in to comment.