diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 31c8875d..a30c05a5 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -162,9 +162,9 @@ def set_attributes_for_turbo_stream @row, @track_list = catch(:abort) do @schedule_table.days.each do |day| - table = @schedule_table[day] - table.rows.each do |row| - throw :abort, [row, table.track_list] if row.schedules.map(&:id).include?(target_schedule_id) + @table = @schedule_table[day] + @table.rows.each do |row| + throw :abort, [row, @table.track_list] if row.schedules.map(&:id).include?(target_schedule_id) end end end diff --git a/app/models/schedule/table.rb b/app/models/schedule/table.rb index 8275b352..2acaccff 100644 --- a/app/models/schedule/table.rb +++ b/app/models/schedule/table.rb @@ -2,9 +2,10 @@ class Schedule class Table - attr_reader :track_list, :rows + attr_reader :track_list, :rows, :day - def initialize(schedules) + def initialize(schedules, day = nil) + @day = day @track_list = schedules.map(&:track).uniq.sort_by(&:position).map(&:name) grouped_schedules = schedules.group_by do |s| diff --git a/app/models/schedule/tables.rb b/app/models/schedule/tables.rb index a4112c01..bb1933a2 100644 --- a/app/models/schedule/tables.rb +++ b/app/models/schedule/tables.rb @@ -6,8 +6,8 @@ class Tables def initialize(schedules) @schedules = schedules - @map = @schedules.group_by { _1.start_at.strftime(DATE_FORMAT) }.transform_values do |v| - Schedule::Table.new(v) + @map = @schedules.group_by { _1.start_at.strftime(DATE_FORMAT) }.to_h do |k, v| + [k, Schedule::Table.new(v, k)] end end diff --git a/app/views/plans/update.turbo_stream.erb b/app/views/plans/update.turbo_stream.erb index 6d71a3d1..de2dac87 100644 --- a/app/views/plans/update.turbo_stream.erb +++ b/app/views/plans/update.turbo_stream.erb @@ -1,3 +1,8 @@ <%= turbo_stream.replace @row.turbo_stream_id do %> <%= render partial: 'schedules/table_row', locals: { row: @row, plan: @plan, track_list: @track_list} %> <% end %> +<%= turbo_stream.update "mobile-table-#{@table.day}" do %> + <% @table.rows.each do |row| %> + <%= render partial: 'schedules/mobile_table_row', locals: { row: row, plan: @plan, track_list: @table.track_list } %> + <% end %> +<% end %> diff --git a/app/views/schedules/_card.html.erb b/app/views/schedules/_card.html.erb index 9f01ac2a..b1d5df9b 100644 --- a/app/views/schedules/_card.html.erb +++ b/app/views/schedules/_card.html.erb @@ -1,6 +1,6 @@ <%= turbo_frame_tag schedule do %>