From 5b25c5b3aa07179c8462d82fea0a54e458177e41 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Mon, 8 Jun 2015 19:57:10 -0500 Subject: [PATCH] * enough to make sure I can build react stuff --- web/Gemfile | 4 ++- web/app/assets/javascripts/application.js | 5 +-- .../assets/javascripts/client_init.js.coffee | 11 ++++++ web/app/assets/javascripts/jam_rest.js | 2 -- .../assets/javascripts/react-components.js | 6 ++-- .../BroadcastNotification.jsx | 25 ++++++++++++++ .../actions/BroadcastNotificationActions.js | 8 +++++ .../BroadcastNotificationStore.js.coffee | 34 +++++++++++++++++++ web/app/views/clients/index.html.erb | 3 +- 9 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 web/app/assets/javascripts/react-components/BroadcastNotification.jsx create mode 100644 web/app/assets/javascripts/react-components/actions/BroadcastNotificationActions.js create mode 100644 web/app/assets/javascripts/react-components/stores/BroadcastNotificationStore.js.coffee diff --git a/web/Gemfile b/web/Gemfile index a141bc9ef..c407c7d6e 100644 --- a/web/Gemfile +++ b/web/Gemfile @@ -94,7 +94,9 @@ gem 'react-rails', '~> 1.0' gem "browserify-rails", "~> 0.7" source 'https://rails-assets.org' do - gem 'rails-assets-fluxxor' + #gem 'rails-assets-fluxxor' + gem 'rails-assets-es5-shim' + gem 'rails-assets-reflux' end group :development, :test do diff --git a/web/app/assets/javascripts/application.js b/web/app/assets/javascripts/application.js index 958491cb7..62d5148b5 100644 --- a/web/app/assets/javascripts/application.js +++ b/web/app/assets/javascripts/application.js @@ -38,8 +38,8 @@ //= require jquery.exists //= require jquery.payment //= require jquery.visible -//= require fluxxor -//= require react-components +//= require es5-shim +//= require reflux //= require howler.core.js //= require jstz //= require class @@ -52,6 +52,7 @@ //= require utils //= require subscription_utils //= require custom_controls +//= require react-components //= require web/signup_helper //= require web/signin_helper //= require web/signin diff --git a/web/app/assets/javascripts/client_init.js.coffee b/web/app/assets/javascripts/client_init.js.coffee index 20d0e76cc..9dd28a8d7 100644 --- a/web/app/assets/javascripts/client_init.js.coffee +++ b/web/app/assets/javascripts/client_init.js.coffee @@ -5,6 +5,8 @@ $ = jQuery context = window context.JK ||= {}; +broadcastActions = BroadcastNotificationActions # require('./react-components/actions/BroadcastNotificationActions') + context.JK.ClientInit = class ClientInit constructor: () -> @logger = context.JK.logger @@ -14,5 +16,14 @@ context.JK.ClientInit = class ClientInit if context.gon.isNativeClient this.nativeClientInit() + setTimeout(this.checkBroadcastNotification, 3000) + + checkBroadcastNotification: () => + console.log("broadcastActions", broadcastActions) + broadcastActions.load.triggerPromise() + + nativeClientInit: () => @gearUtils.bootstrapDefaultPlaybackProfile(); + + diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index a44e3b13d..820dd360c 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -1939,9 +1939,7 @@ this.createAlert = createAlert; this.signup = signup; this.portOverCarts = portOverCarts; - return this; }; - })(window,jQuery); diff --git a/web/app/assets/javascripts/react-components.js b/web/app/assets/javascripts/react-components.js index e534d5c8c..9b3a9c63e 100644 --- a/web/app/assets/javascripts/react-components.js +++ b/web/app/assets/javascripts/react-components.js @@ -3,7 +3,5 @@ React = require('react'); -// note that this is a global assignment, it will be discussed further below -DemoComponent = require('./components/DemoComponent'); - -// //= require_tree ./react-components +BroadcastNotificationActions = require('./react-components/actions/BroadcastNotificationActions') +BroadcastNotification = require('./react-components/BroadcastNotification') \ No newline at end of file diff --git a/web/app/assets/javascripts/react-components/BroadcastNotification.jsx b/web/app/assets/javascripts/react-components/BroadcastNotification.jsx new file mode 100644 index 000000000..841b3be4e --- /dev/null +++ b/web/app/assets/javascripts/react-components/BroadcastNotification.jsx @@ -0,0 +1,25 @@ +var React = require('react'); + +var BroadcastNotificationStore = require('./stores/BroadcastNotificationStore'); + +var BroadcastNotification = React.createClass({displayName: 'Broadcast Notification', + mixins: [Reflux.connect(BroadcastNotificationStore, 'notification')], + render: function() { + if(!this.state.notification) { + return
HAHAHAAH
+ } + + return
+
+
+ {this.state.notification.button_label} + not now, thanks +
+
+ + } +}); + +// each file will export exactly one component +module.exports = BroadcastNotification; \ No newline at end of file diff --git a/web/app/assets/javascripts/react-components/actions/BroadcastNotificationActions.js b/web/app/assets/javascripts/react-components/actions/BroadcastNotificationActions.js new file mode 100644 index 000000000..cf5e97b01 --- /dev/null +++ b/web/app/assets/javascripts/react-components/actions/BroadcastNotificationActions.js @@ -0,0 +1,8 @@ +//var rest = context.JK.Rest() + +var BroadcastNotificationActions = Reflux.createActions({ + load: {asyncResult: true} +}) + +module.exports = BroadcastNotificationActions + diff --git a/web/app/assets/javascripts/react-components/stores/BroadcastNotificationStore.js.coffee b/web/app/assets/javascripts/react-components/stores/BroadcastNotificationStore.js.coffee new file mode 100644 index 000000000..943dd5564 --- /dev/null +++ b/web/app/assets/javascripts/react-components/stores/BroadcastNotificationStore.js.coffee @@ -0,0 +1,34 @@ +$ = jQuery +context = window +logger = context.JK.logger +broadcastActions = BroadcastNotificationActions # require('../actions/BroadcastNotificationActions') + +rest = context.JK.Rest() + +# see if this shows up elsewhere +broadcastActions.blah = 'hahah' + +broadcastActions.load.listenAndPromise(rest.getBroadcastNotification); + +console.log("broadcastActions!!", broadcastActions) +BroadcastNotificationStore = Reflux.createStore( + { + listenables: broadcastActions + + init: () => + logger.debug("broadcast notification store init") + #this.listenTo(broadcastActions.load, 'onSync') + + onLoad: () => + logger.debug("loading broadcast notification...") + + onLoadCompleted: () => + logger.debug("broadcast notification sync completed") + + onLoadFailed: () => + logger.error("broadcast notification sync failed") + } +) + +module.exports = BroadcastNotificationStore + diff --git a/web/app/views/clients/index.html.erb b/web/app/views/clients/index.html.erb index 78f1547dc..804a1eb75 100644 --- a/web/app/views/clients/index.html.erb +++ b/web/app/views/clients/index.html.erb @@ -81,8 +81,7 @@ <%= render 'dialogs/dialogs' %>
-

/app/views/pages/index.html.erb

-<%= react_component 'DemoComponent', {} %> +<%= react_component 'BroadcastNotification', {} %>