diff --git a/src/LexEdit.tsx b/src/LexEdit.tsx index 31a2649..31f2462 100644 --- a/src/LexEdit.tsx +++ b/src/LexEdit.tsx @@ -1,11 +1,6 @@ import * as React from 'react'; import * as _ from 'lodash'; -import { - textInput, - selectInput, - imagePreview, - listInput -} from './LexSingleInput'; +import { componentForType} from './LexSingleInput'; import { Card, Button @@ -38,31 +33,11 @@ export class LexEdit extends React.Component { let origValue = fieldMeta.get(this.props.lexItem); let options = fieldMeta.options; let changed = !_.isEqual(value, origValue) && this.props.existing; - let sh = (e: any) => { - let eventData = {}; - eventData[field] = e.target.value; - this.handleOnChange(eventData); + let sh = (v: any) => { + this.handleOnChange({ field, value: v }); }; let params = { field, sh, value, options, langSelOpts, changed }; - switch (fieldMeta.type) { - case 'text': { - return textInput(params); - } - case 'select': { - return selectInput(params); - } - case 'preview': { - return imagePreview(params); - } - case 'list': { - return listInput(params); - } - default: { - console.log('type discarded :', fieldMeta.type); - console.log('values discarded :', fieldMeta.get(li)); - return null; - } - } + return componentForType(fieldMeta.type, params); }); return ( @@ -131,9 +106,8 @@ export class LexEdit extends React.Component { } private handleOnChange(event: any) { - let type = _.keys(event)[0]; - let value = _.values(event)[0] as string; - let meta = this.props.fieldMetaMap[type]; + let { field, value } = event; + let meta = this.props.fieldMetaMap[field]; let lexItem = meta.set(this.state.lexItem, value); this.setState({ lexItem }); } diff --git a/src/LexSetup.tsx b/src/LexSetup.tsx index 742996d..b9b5842 100644 --- a/src/LexSetup.tsx +++ b/src/LexSetup.tsx @@ -39,7 +39,7 @@ function simpleAttrAccessor(attrPred: any) { }); _.set(prop, '[0]._', value); } else { - _.set(lexItem, lens, def(value)); + _.set(lexItem, lens, [def(value)]); } return lexItem; } diff --git a/src/LexSingleInput.tsx b/src/LexSingleInput.tsx index 17ed8d6..4a7c572 100644 --- a/src/LexSingleInput.tsx +++ b/src/LexSingleInput.tsx @@ -4,6 +4,7 @@ import { Label, Form } from 'semantic-ui-react'; const { Flex, Box } = require('reflexbox'); import { Input, + Dropdown, Image } from 'semantic-ui-react'; @@ -38,9 +39,7 @@ function changedLabel(changed: boolean, text: string) { ); } -const imageRoot = '/png/'; - -export function textInput(params: any) { +function textInput(params: any) { let { field, sh, value, changed } = params; return ( { sh(d.value); }} value={value} placeholder={field} type="text" @@ -59,29 +58,31 @@ export function textInput(params: any) { ); } -export function selectInput(params: any) { +function selectInput(params: any) { let { field, sh, value, options, langSelOpts, changed } = params; let staticOpts = options; let fieldOpts = _.get(langSelOpts, field, []); let selOpts = staticOpts ? staticOpts : fieldOpts; + let dropOptions = selOpts.map((k: any, i: any, c: any) => { + return { key: i, value: k, text: k }; + }); return ( - + compact={true} + selection={true} + style={{ width: '10em' }} + /> ); } -export function imagePreview(params: any) { +function imagePreview(params: any) { let { field, value, changed } = params; - let imageSrc = imageRoot + value; + let imageSrc = '/png/' + value; return value !== '' ? ( @@ -89,7 +90,7 @@ export function imagePreview(params: any) { ) : textInput(params); } -export function listInput(params: any) { +function listInput(params: any) { let { field, value, changed } = params; console.log('field: ', field, 'value: ', value); return ( @@ -98,3 +99,25 @@ export function listInput(params: any) { ); } + +export function componentForType(type: string, params: any) { + switch (type) { + case 'text': { + return textInput(params); + } + case 'select': { + return selectInput(params); + } + case 'preview': { + return imagePreview(params); + } + case 'list': { + return listInput(params); + } + default: { + console.log('type discarded :', type); + // console.log('values discarded :', fieldMeta.get(li)); + return null; + } + } +} diff --git a/walle_server.py b/walle_server.py index 445feb0..95ea78f 100644 --- a/walle_server.py +++ b/walle_server.py @@ -1,6 +1,6 @@ from flask import Flask,send_from_directory,request app = Flask(__name__,static_url_path='',static_folder='build') -# from freespeech_walle.get_morph_rule import get_morph +from freespeech_walle.get_morph_rule import get_morph # from freespeech_walle.wizard_helpers import get_morph_rule,get_frequency import json @@ -21,7 +21,7 @@ def walle_morph(): word = request.args.get('word','water') pos_req = request.args.get('pos','N') pos = pos_req if pos_req != '' else 'N'; - return json.dumps(get_morph_rule.get_morph(word,pos)) + return json.dumps(get_morph(word,pos)) # hmr streaming # import requests