diff --git a/app/assets/javascripts/components/inventory.js.jsx b/app/assets/javascripts/components/inventory.js.jsx
new file mode 100644
index 00000000..63dbfb36
--- /dev/null
+++ b/app/assets/javascripts/components/inventory.js.jsx
@@ -0,0 +1,50 @@
+var Inventory = React.createClass({
+ propTypes: {
+ cards: React.PropTypes.array
+ },
+
+ getInitialState: function() {
+ return {
+ cards: []
+ };
+ },
+
+ componentDidMount: function() {
+ $.get(this.props.source, function(result) {
+ if (this.isMounted()) {
+ this.setState({
+ cards: result
+ });
+ }
+ }.bind(this));
+ },
+
+ render: function() {
+ return (
+
+ );
+ }
+});
+
+$(document).on("page:change", function() {
+ if (document.getElementById("inventory") != null) {
+ React.render(
+ , document.getElementById('inventory')
+ );
+ }
+})
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
index f6d3e54b..81bc47cd 100644
--- a/app/controllers/games_controller.rb
+++ b/app/controllers/games_controller.rb
@@ -1,7 +1,7 @@
class GamesController < ApplicationController
before_action :set_game, only: [:show, :edit, :update, :destroy, :play_hand]
- respond_to :html
+ respond_to :html, :json
def index
@games = Game.all
@@ -115,6 +115,11 @@ class GamesController < ApplicationController
redirect_to(@game)
end
+ def my_inventory
+ @game = Game.find(params[:game_id])
+ @player = @game.players.find_by(user_id: current_user.id)
+ end
+
private
def set_game
diff --git a/app/views/games/my_inventory.json.jbuilder b/app/views/games/my_inventory.json.jbuilder
new file mode 100644
index 00000000..2d02f334
--- /dev/null
+++ b/app/views/games/my_inventory.json.jbuilder
@@ -0,0 +1,3 @@
+json.(@player.inventory) do |card|
+ json.extract! card, :id, :rank, :suit, :play_id
+end
diff --git a/app/views/games/show.html.haml b/app/views/games/show.html.haml
index 0b43303a..985ed87b 100644
--- a/app/views/games/show.html.haml
+++ b/app/views/games/show.html.haml
@@ -34,14 +34,7 @@
// Show the players' cards
- if player.user == current_user && player.inventory.empty? == false
- %ul.cards
- - player.inventory.each do |card|
- %li
- %label
- // If the cards belong to the user, allow them to select the cards to play as a hand
- = check_box_tag 'player_card_ids[]', card.id, false, form: "edit_game_#{@game.id}" if player.user == current_user
- // Show the card TODO hide values of cards of other players
- = card.to_s
+ #inventory
-# TODO better logic, not in view
- unless @game.status == nil
diff --git a/config/routes.rb b/config/routes.rb
index aa7d0de8..e0f32bd1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -4,6 +4,7 @@ Rails.application.routes.draw do
resources :games do
get 'start'
get 'join'
+ get 'my-inventory'
member do
patch 'play_hand'
end
diff --git a/spec/features/plays_spec.rb b/spec/features/plays_spec.rb
index 5aa6df53..a24a94c9 100644
--- a/spec/features/plays_spec.rb
+++ b/spec/features/plays_spec.rb
@@ -2,7 +2,7 @@ require 'rails_helper'
include Warden::Test::Helpers
Warden.test_mode!
-feature 'Play a hand', type: :feature do
+feature 'Play a hand', type: :feature, js: true do
# TODO: Implement a player / seat order. scenario 'active player rotates after a valid hand'
## fails without a consistent seat order. Workaround is to create a new game for each scenario
## with before :each instead of :all