Thomas Dy 9 years ago
parent
commit
9197c501e4
6 changed files with 84 additions and 71 deletions
  1. 2 1
      assets/index.js
  2. 23 0
      assets/intents/contribute.js
  3. 16 44
      assets/templates/contribute.js
  4. 43 1
      assets/util.js
  5. 0 0
      public/bundle.js
  6. 0 25
      webpack-production.config.js

+ 2 - 1
assets/index.js

@@ -16,6 +16,7 @@ var nav = [
 function intent(drivers) {
 function intent(drivers) {
   var DOM = drivers.DOM;
   var DOM = drivers.DOM;
   return {
   return {
+    contribute: require('./intents/contribute')(drivers),
     route$: drivers.hash.map(function(route) {
     route$: drivers.hash.map(function(route) {
       return route || 'about';
       return route || 'about';
     }),
     }),
@@ -117,7 +118,7 @@ function model(actions) {
       status$: results.status$,
       status$: results.status$,
       error$: results.error$,
       error$: results.error$,
       chat$: input$,
       chat$: input$,
-      messages$: messages$
+      contribute$: actions.contribute.fields$
     }
     }
   };
   };
 }
 }

+ 23 - 0
assets/intents/contribute.js

@@ -0,0 +1,23 @@
+var _ = require('lodash');
+var util = require('../util');
+
+module.exports = function(drivers) {
+  var DOM = drivers.DOM;
+
+  function input(elem) {
+    return DOM.get('#'+elem, 'input').map(function(ev) { return ev.target.value }).startWith('');
+  }
+
+  var labels = ['inputWord'].concat([0,1,2,3,4].map(function(item) { return 'taboo'+item }));
+  var streams = labels.map(input);
+
+  var textFields$ = util.asObject(_.zipObject(labels, streams));
+
+  var submit$ = DOM.get('#cardForm', 'submit').doOnNext(function(ev) { ev.preventDefault() });
+  var form$ = util.sync(submit$, textFields$);
+
+  return {
+    fields$: textFields$,
+    form$: form$
+  };
+}

+ 16 - 44
assets/templates/contribute.js

@@ -1,6 +1,6 @@
 var h = require('cyclejs').h;
 var h = require('cyclejs').h;
 
 
-module.exports = function() {
+module.exports = function(props) {
   var submitting = false;
   var submitting = false;
   var exists = false;
   var exists = false;
   var thanks = false;
   var thanks = false;
@@ -16,56 +16,28 @@ h("div", [
         "Help make the game! Contribute words and make the game better. Also, please ",
         "Help make the game! Contribute words and make the game better. Also, please ",
         "original work only. Don't just blindly copy a card from any of the Taboo games."
         "original work only. Don't just blindly copy a card from any of the Taboo games."
       ]),
       ]),
-      h("form#cardForm", {
-          "role": "form",
-          "ng-submit": "submit()"
-      }, [
+      h("form#cardForm", { "role": "form" }, [
         h("div.form-group", [
         h("div.form-group", [
-          h("label", {
-              "for": "inputWord"
-          }, [ "Word" ]),
+          h("label", { "htmlFor": "inputWord" }, [ "Word" ]),
           h("input#inputWord.form-control", {
           h("input#inputWord.form-control", {
               "type": "text",
               "type": "text",
-              "ng-model": "card.word",
               "placeholder": "Word",
               "placeholder": "Word",
-              "ng-change": "check()",
-              "required": ""
+              "required": "true"
           }),
           }),
           exists ? h("span", [ "We already have this word" ]) : null
           exists ? h("span", [ "We already have this word" ]) : null
         ]),
         ]),
-        h("div.form-group", [
-          h("label", [ "Taboo Words" ]),
-          h("input.form-control", {
-              "type": "text",
-              "ng-model": "card.taboos[0]",
-              "placeholder": "Taboo Word",
-              "required": ""
-          }),
-          h("input.form-control", {
-              "type": "text",
-              "ng-model": "card.taboos[1]",
-              "placeholder": "Taboo Word",
-              "required": ""
-          }),
-          h("input.form-control", {
-              "type": "text",
-              "ng-model": "card.taboos[2]",
-              "placeholder": "Taboo Word",
-              "required": ""
-          }),
-          h("input.form-control", {
-              "type": "text",
-              "ng-model": "card.taboos[3]",
-              "placeholder": "Taboo Word",
-              "required": ""
-          }),
-          h("input.form-control", {
-              "type": "text",
-              "ng-model": "card.taboos[4]",
-              "placeholder": "Taboo Word",
-              "required": ""
-          })
-        ]),
+        h("div.form-group",
+          [ h("label", [ "Taboo Words" ]) ]
+          .concat([0,1,2,3,4].map(function(item) {
+            return h('input.form-control', {
+              id: 'taboo'+item,
+              type: 'text',
+              placeholder: 'Taboo Word',
+              value: props.contribute['taboo'+item],
+              required: true
+            });
+          }))
+        ),
         h("input.btn.btn-primary", {
         h("input.btn.btn-primary", {
             "disabled": submitting,
             "disabled": submitting,
             "type": "submit",
             "type": "submit",

+ 43 - 1
assets/util.js

@@ -35,13 +35,55 @@ function log(label) {
   return _.bind(console.log, console, label);
   return _.bind(console.log, console, label);
 }
 }
 
 
+function flatten(obj) {
+  var ret = {};
+  _.forEach(obj, function(val, key) {
+    if(_.isPlainObject(val)) {
+      var o = flatten(val);
+      _.forEach(o, function(val, innerKey) {
+        ret[key+'.'+innerKey] = val;
+      });
+    }
+    else {
+      ret[key] = val;
+    }
+  });
+  return ret;
+}
+
+function _set(obj, key, val) {
+  var pos = key.indexOf('.');
+  if(pos < 0) {
+    obj[key] = val;
+  }
+  else {
+    var parent = key.substr(0, pos);
+    if(!obj[parent]) {
+      obj[parent] = {};
+    }
+
+    var rest = key.substr(pos+1);
+    _set(obj[parent], rest, val);
+  }
+}
+
+function unflatten(obj) {
+  var ret = {};
+  var set = _.bind(_set, null, ret);
+  _.forEach(obj, function(val, key) {
+    set(key, val);
+  });
+  return ret;
+}
+
 function asObject(params) {
 function asObject(params) {
+  params = flatten(params);
   var keys = _.keys(params).map(function(key) {
   var keys = _.keys(params).map(function(key) {
     return key.replace(/\$$/, '');
     return key.replace(/\$$/, '');
   });
   });
   var vals = _.values(params);
   var vals = _.values(params);
   return Rx.Observable.combineLatest(vals, function() {
   return Rx.Observable.combineLatest(vals, function() {
-    return _.zipObject(keys, arguments);
+    return unflatten(_.zipObject(keys, arguments));
   });
   });
 }
 }
 
 

File diff suppressed because it is too large
+ 0 - 0
public/bundle.js


+ 0 - 25
webpack-production.config.js

@@ -2,29 +2,4 @@ var webpack = require('webpack');
 
 
 module.exports = [
 module.exports = [
     require('./webpack-base.config.js')(true),
     require('./webpack-base.config.js')(true),
-    {
-        entry: './assets/server',
-        output: {
-            path: 'public',
-            publicPath: '/assets/',
-            filename: 'server.js'
-        },
-        resolve: {
-            extensions: ['', '.js', '.jsx']
-        },
-        plugins: [
-            new webpack.IgnorePlugin(/reqwest/),
-            new webpack.optimize.UglifyJsPlugin(),
-            new webpack.DefinePlugin({
-                "process.env": {
-                    NODE_ENV: JSON.stringify("production")
-                }
-            })
-        ],
-        module: {
-            loaders: [
-                { test: /\.jsx$/, loader: 'jsx' }
-            ]
-        }
-    }
 ]
 ]

Some files were not shown because too many files changed in this diff