1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-03 13:30:02 +00:00

Use turbo streams for the bout board instead of auto refreshing every 30 seconds.

This commit is contained in:
2026-02-20 19:20:33 -05:00
parent dc50efe8fc
commit 654cb84827
14 changed files with 324 additions and 87 deletions

View File

@@ -9,6 +9,7 @@ class Mat < ApplicationRecord
QUEUE_SLOTS = %w[queue1 queue2 queue3 queue4].freeze
after_save :clear_queue_matches_cache
after_commit :broadcast_up_matches_board, on: :update, if: :up_matches_queue_changed?
def assign_next_match
slot = first_empty_queue_slot
@@ -276,4 +277,12 @@ class Mat < ApplicationRecord
)
end
def broadcast_up_matches_board
Tournament.broadcast_up_matches_board(tournament_id)
end
def up_matches_queue_changed?
saved_change_to_queue1? || saved_change_to_queue2? || saved_change_to_queue3? || saved_change_to_queue4?
end
end

View File

@@ -17,6 +17,7 @@ class Match < ApplicationRecord
# update mat show with correct match if bout board is reset
# this is done with a turbo stream
after_commit :broadcast_mat_assignment_change, if: :saved_change_to_mat_id?, on: [:create, :update]
after_commit :broadcast_up_matches_board, on: :update, if: :saved_change_to_mat_id?
# Enqueue advancement and related actions after the DB transaction has committed.
# Using after_commit ensures any background jobs enqueued inside these callbacks
@@ -371,4 +372,8 @@ class Match < ApplicationRecord
)
end
end
def broadcast_up_matches_board
Tournament.broadcast_up_matches_board(tournament_id)
end
end

View File

@@ -69,6 +69,32 @@ class Tournament < ApplicationRecord
end
end
def up_matches_unassigned_matches
matches
.where("mat_id is NULL and (finished != 1 or finished is NULL)")
.where("loser1_name != ? OR loser1_name IS NULL", "BYE")
.where("loser2_name != ? OR loser2_name IS NULL", "BYE")
.order("bout_number ASC")
.limit(10)
.includes({ wrestler1: :school }, { wrestler2: :school }, { weight: :matches })
end
def up_matches_mats
mats.includes(:matches)
end
def self.broadcast_up_matches_board(tournament_id)
tournament = find_by(id: tournament_id)
return unless tournament
Turbo::StreamsChannel.broadcast_replace_to(
tournament,
target: "up_matches_board",
partial: "tournaments/up_matches_board",
locals: { tournament: tournament }
)
end
def destroy_all_matches
matches.destroy_all
end