fix: properly find the most recent pop

Closes #2.
This commit is contained in:
insects 2025-03-31 23:38:45 +02:00
parent b21b6aa1a6
commit abbbf42715
2 changed files with 2 additions and 2 deletions

View file

@ -99,7 +99,7 @@ class InstanceController < ApplicationController
parent_instance = Instance.find_by(public_id: instance_id) parent_instance = Instance.find_by(public_id: instance_id)
if params[:mins] && params[:mins].to_i < 120 && params[:pwd] == parent_instance.password if params[:mins] && params[:mins].to_i < 120 && params[:pwd] == parent_instance.password
ts = Time.now.utc ts = Time.now.utc
pop = Pop.find_by(instance_id: parent_instance.id, name: nm) pop = Pop.find_by(instance_id: parent_instance.id, name: nm, created_at: 120.minutes.ago..Time.now)
pop.created_at = Time.at(ts - params[:mins].to_i.minutes).utc pop.created_at = Time.at(ts - params[:mins].to_i.minutes).utc
pop.save pop.save
@instance = Instance.includes(:pops, :fairies).find_by(public_id: instance_id) @instance = Instance.includes(:pops, :fairies).find_by(public_id: instance_id)

View file

@ -46,7 +46,7 @@
<div class="condition"> <div class="condition">
<% if nm[:is_popped] %> <% if nm[:is_popped] %>
<div class="pop-timer"> <div class="pop-timer">
<% pop = instance.pops.find { |pop| pop.name == nm[:name].parameterize } %> <% pop = instance.pops.find { |pop| (Time.now.utc - 120.minutes) <= pop.created_at and pop.name == nm[:name].parameterize } %>
<% mins = ActiveSupport::Duration.build(Time.current - pop.created_at) %> <% mins = ActiveSupport::Duration.build(Time.current - pop.created_at) %>
<div class="timer"> <div class="timer">
<div>» <%= (120.minutes - mins).in_minutes.ceil %>m</div> <div>» <%= (120.minutes - mins).in_minutes.ceil %>m</div>