feat: implement suggesting a fairy despawned

This commit is contained in:
insects 2025-03-11 18:31:50 +01:00
parent f9527c330c
commit 5ed1cc91ae
4 changed files with 39 additions and 10 deletions

View file

@ -131,11 +131,11 @@ button.action:hover {
}
.needs_pwd {
display: none;
display: none !important;
}
.needs_pwd.shown {
display: block;
display: block !important;
}
.action.shown {
@ -265,3 +265,10 @@ span#password {
.fairy-dot.unclaimed:hover {
cursor: pointer;
}
.despawn-note {
color: tomato;
font-size: 10px;
font-weight: normal;
margin-bottom: 5px;
}

View file

@ -2,15 +2,13 @@ class FairyController < ApplicationController
def mark
instance_id, location = mark_params
instance = Instance.find_by(public_id: instance_id)
fairy = Fairy.new(location: location, instance_id: instance.id)
unless params[:pwd]
fairy.is_suggested = true
if params[:pwd]
fairy = Fairy.new(location: location, instance_id: instance.id)
fairy.save
end
if fairy.save
new_instance = Instance.includes(:fairies).find(instance.id)
render partial: "instance/fairies", locals: { instance: new_instance }
end
new_instance = Instance.includes(:fairies).find(instance.id)
render partial: "instance/fairies", locals: { instance: new_instance }
end
def unmark
@ -24,6 +22,15 @@ class FairyController < ApplicationController
end
def despawn
instance_id, location = mark_params
instance = Instance.find_by(public_id: instance_id)
fairy = Fairy.find_by(instance_id: instance.id, location: location)
unless fairy.is_despawned
fairy.is_despawned = true
fairy.save
new_instance = Instance.includes(:fairies).find(instance.id)
render partial: "instance/fairies", locals: { instance: new_instance }
end
end
private

View file

@ -72,10 +72,24 @@
hx-select="#fairies"
>
remove</div>
<% unless instance.fairies[idx].is_despawned %>
<div
class="copyable action no_pwd"
hx-post="/fairy/despawn?instance=<%= instance.public_id %>&location=<%= instance.fairies[idx].location %>"
hx-swap="outerHTML"
hx-target="#fairies"
hx-select="#fairies"
>
gone?
</div>
<% end %>
</div>
</div>
<% if instance.fairies[idx].is_despawned %>
<span class="despawn-note">potentially despawned!</span>
<% end %>
<% end %>
<div class="note">Click on a black dot to mark another Elemental.</div>
<div class="needs_pwd note">Click on a black dot to mark another Elemental.</div>
<div class="note">
<div
class="copyable"

View file

@ -7,6 +7,7 @@ Rails.application.routes.draw do
post "/auth", to: "instance#authenticate", as: :authenticate_to_instance
post "/fairy/mark", to: "fairy#mark", as: :mark_fairy
post "/fairy/unmark", to: "fairy#unmark", as: :unmark_fairy
post "/fairy/despawn", to: "fairy#despawn", as: :despawn_fairy
get "/:public_id", to: "instance#show", as: :show_instance
get "up" => "rails/health#show", as: :rails_health_check