From d5ef4d64811f6d7b14a916280ddb4bb8e599df79 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Mon, 4 Nov 2019 05:06:03 -0800 Subject: [PATCH] Autoload game updates if not taking turn --- app/assets/javascripts/table-loader.js | 4 ++- app/views/tables/_seat.html.haml | 3 ++- app/views/tables/show.html.haml | 37 +++----------------------- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/app/assets/javascripts/table-loader.js b/app/assets/javascripts/table-loader.js index a9c7b498..f7391af3 100644 --- a/app/assets/javascripts/table-loader.js +++ b/app/assets/javascripts/table-loader.js @@ -1,5 +1,7 @@ $(document).ready(function(){ setInterval(function() { - $('#table-component').load(window.location.pathname +" #table-component"); + if ( $('.taking-turn.player[data-soft-token=' + soft_token + ']').length < 1 ) { + $('#table-component').load(window.location.pathname +" #table-component"); + } }, 5000); }); diff --git a/app/views/tables/_seat.html.haml b/app/views/tables/_seat.html.haml index 6a1cd6e8..fdc78c72 100644 --- a/app/views/tables/_seat.html.haml +++ b/app/views/tables/_seat.html.haml @@ -11,7 +11,8 @@ sit_seat_path(seat) - if seat.player - .player{class: @game.controlling_player == seat.player ? "taking-turn" : ""} + .player{class: @game.controlling_player == seat.player ? "taking-turn" : "", + data: {soft_token: seat.player.soft_token} } .user-name= seat.player.display_name - if @game.started? .inventory-count= seat.player.inventory.count diff --git a/app/views/tables/show.html.haml b/app/views/tables/show.html.haml index 4156f216..7b009d2b 100644 --- a/app/views/tables/show.html.haml +++ b/app/views/tables/show.html.haml @@ -5,8 +5,6 @@ -# #table-component-container-container= react_component 'Table', props = {url: "#{table_path @table}"}, html_options = {id: "table-component-container"} #table-component - - unless current_user.soft_token == @game.controlling_player.try("soft_token") - = javascript_include_tag 'table-loader' %p= @table.title @@ -17,37 +15,6 @@ - if @game.winner_player_id || @game.nil? = button_to 'New Game', new_game_table_path(@table) - -# .players - %b Players: - %ol - - @game.players.each do |player| - %li - = player.display_name - // Show the user which player they are - = "Me" if player.soft_token == current_user.soft_token - // Show whose turn it is - - if @game.controlling_player_id - %strong= "Taking Turn " if @game.controlling_player == player - // Show the players' cards - - if player.user == current_user && player.inventory.empty? == false - -##inventory - - -# TODO better logic, not in view - - unless @game.status == nil - .table - -# TODO better logic, not in view. Set play to beat = nil; instead of view logic - -# - if @game.play_to_beat && @game.player_to_beat != @game.controlling_player - - if @game.play_to_beat.play - %h1 - Hand to beat - %span.hand-type= @game.play_to_beat.play.hand_type - %div= @game.play_to_beat.play.to_s - - @game.play_to_beat.play.player_cards.each do |card| - = card.to_s - %span.player= @game.play_to_beat.play.player.display_name - -# - else - %h1 Open table - #game-component - if @game.winner_player_id %h1= @game.status @@ -64,3 +31,7 @@ #bot = render "seat", seat: @seats[3] + + :javascript + var soft_token = "#{current_user.soft_token}"; + = javascript_include_tag 'table-loader'