Dev #4
|
@ -5,9 +5,10 @@ import {StyleSheet, TextInput} from 'react-native';
|
||||||
import {View, Text, Button, Picker} from 'native-base';
|
import {View, Text, Button, Picker} from 'native-base';
|
||||||
import Icon from 'react-native-vector-icons/FontAwesome5';
|
import Icon from 'react-native-vector-icons/FontAwesome5';
|
||||||
import IconedButton from '../view/iconed-button.jsx';
|
import IconedButton from '../view/iconed-button.jsx';
|
||||||
|
import {POS_PICKER} from '../../constants/component-types';
|
||||||
const FieldEditor = props => {
|
const FieldEditor = props => {
|
||||||
const [data, setData] = useState({});
|
const [data, setData] = useState({});
|
||||||
const [editing, setEditing] = useState(true);
|
const [editing, setEditing] = useState(false);
|
||||||
const label = props.data.label;
|
const label = props.data.label;
|
||||||
const [selectedValue, setSelectedValue] = useState(props.data.values[0]);
|
const [selectedValue, setSelectedValue] = useState(props.data.values[0]);
|
||||||
const [userTyped, setUserTyped] = useState('');
|
const [userTyped, setUserTyped] = useState('');
|
||||||
|
@ -17,8 +18,14 @@ const FieldEditor = props => {
|
||||||
console.log(props.data)
|
console.log(props.data)
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const selectValue = value => {
|
const selectValue = selected => {
|
||||||
setSelectedValue(value);
|
setSelectedValue(selected);
|
||||||
|
if(props.type === POS_PICKER){
|
||||||
|
data.values.forEach((value, id) => {
|
||||||
|
if(value === selected)
|
||||||
|
props.onSelect(id)
|
||||||
|
})
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const typing = text => {
|
const typing = text => {
|
||||||
console.log(text);
|
console.log(text);
|
||||||
|
@ -74,7 +81,8 @@ const FieldEditor = props => {
|
||||||
<TextField
|
<TextField
|
||||||
lineType={'none'}
|
lineType={'none'}
|
||||||
multiline={true}
|
multiline={true}
|
||||||
label={data.type}
|
label={props.data.label}
|
||||||
|
|
||||||
value={selectedValue}
|
value={selectedValue}
|
||||||
editable={true}
|
editable={true}
|
||||||
ref={input}
|
ref={input}
|
||||||
|
@ -82,7 +90,7 @@ const FieldEditor = props => {
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<View>
|
<View>
|
||||||
<Text style={styles.pickerLabel}>{'label'}</Text>
|
<Text style={styles.pickerLabel}>{props.data.label}</Text>
|
||||||
<Picker
|
<Picker
|
||||||
selectedValue={selectedValue}
|
selectedValue={selectedValue}
|
||||||
onValueChange={value => selectValue(value)}>
|
onValueChange={value => selectValue(value)}>
|
||||||
|
|
|
@ -17,18 +17,18 @@ const FieldList = props => {
|
||||||
},[props.response])
|
},[props.response])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(sound, pronunciation)
|
console.log(sound, pronunciation)
|
||||||
console.log("EXFSDFS", examples)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<PickerList/>
|
<PickerList labelNum={1}/>
|
||||||
<TextInput value={sound} label={'Sound'}/>
|
<PickerList labelNum={2}/>
|
||||||
<TextInput value={pronunciation} label={'Transcription'}/>
|
|
||||||
<FieldEditor data={{
|
<FieldEditor data={{
|
||||||
label: 'Usage example',
|
label: 'Usage example',
|
||||||
values: examples || ['can not find the example']
|
values: examples || ['can not find the example']
|
||||||
}}/>
|
}}/>
|
||||||
|
<TextInput value={sound} label={'Sound'}/>
|
||||||
|
<TextInput value={pronunciation} label={'Transcription'}/>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,38 @@
|
||||||
import React,{useState, useEffect, useRef} from 'react'
|
import React, {useState, useEffect, useRef} from 'react';
|
||||||
import {View} from 'native-base';
|
import {View} from 'native-base';
|
||||||
import {connect} from 'react-redux'
|
import {connect} from 'react-redux';
|
||||||
|
import PosPicker from './pos-picker';
|
||||||
|
import FieldEditor from './field-editor';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
****************** props:*****************
|
****************** props:*****************
|
||||||
* startId props.data[0] / [1] /[8] ...
|
* startId props.data[0] / [1] /[8] ...
|
||||||
* labelNum // Translate 1 / Translate 2 ...
|
* labelNum // Translate 1 / Translate 2 ...
|
||||||
* */
|
* */
|
||||||
const PickerList = props => {
|
const PickerList = props => {
|
||||||
return(
|
const [data, setData] = useState({translates: [], definitions: []});
|
||||||
<View>
|
useEffect(() => {
|
||||||
|
console.log('PROPPPPS', props);
|
||||||
</View>
|
});
|
||||||
)
|
const setId = id => {
|
||||||
}
|
console.log(id);
|
||||||
|
};
|
||||||
|
const selectDef = id => {
|
||||||
|
console.log(props.data[id])
|
||||||
|
setData(props.data[id])
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<PosPicker
|
||||||
|
labelNum={props.labelNum}
|
||||||
|
onSelect={id => selectDef(id)}
|
||||||
|
// getId={id => setId(id)}
|
||||||
|
/>
|
||||||
|
<FieldEditor data={{label:`Translate ${props.labelNum}`, values: data.translates}}/>
|
||||||
|
<FieldEditor data={{label: `Definition ${props.labelNum}`, values: data.definitions}}/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
export default connect(state => ({
|
export default connect(state => ({
|
||||||
data: state.api.parsedDictionary.compounded
|
data: state.api.parsedDictionary.compounded,
|
||||||
}))(PickerList)
|
}))(PickerList);
|
||||||
|
|
38
src/components/Form/pos-picker.jsx
Normal file
38
src/components/Form/pos-picker.jsx
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import React, {useState, useEffect} from 'react';
|
||||||
|
import {connect} from 'react-redux';
|
||||||
|
import {View} from 'native-base';
|
||||||
|
import FieldEditor from './field-editor';
|
||||||
|
import {POS_PICKER} from '../../constants/component-types';
|
||||||
|
|
||||||
|
const PosPicker = props => {
|
||||||
|
const [ready, setReady] = useState(false);
|
||||||
|
const [poses, setPoses] = useState([]);
|
||||||
|
useEffect(() => {
|
||||||
|
console.log('PRT', props.parts);
|
||||||
|
if (props.parts) {
|
||||||
|
let posArray = props.parts.map((part, id) => part.pos);
|
||||||
|
console.log('ARRRRAY', posArray);
|
||||||
|
setPoses(posArray);
|
||||||
|
setReady(true);
|
||||||
|
}
|
||||||
|
}, [props]);
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
{ready ? (
|
||||||
|
<FieldEditor
|
||||||
|
data={{
|
||||||
|
label: `Part of speech ${props.labelNum} `,
|
||||||
|
values: poses,
|
||||||
|
}}
|
||||||
|
type={POS_PICKER}
|
||||||
|
onSelect={(value) => props.onSelect(value)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<View />
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default connect(state => ({
|
||||||
|
parts: state.api.parsedDictionary.compounded,
|
||||||
|
}))(PosPicker);
|
|
@ -6,8 +6,6 @@ const TextInput = props => {
|
||||||
const input = useRef();
|
const input = useRef();
|
||||||
const [text, setText] = useState(props.value);
|
const [text, setText] = useState(props.value);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('changing');
|
|
||||||
console.log(props.value);
|
|
||||||
setText(props.value);
|
setText(props.value);
|
||||||
input.current.setValue(props.value);
|
input.current.setValue(props.value);
|
||||||
}, [props, props.value]);
|
}, [props, props.value]);
|
||||||
|
|
|
@ -10,57 +10,57 @@ import FieldEditor from './Form/field-editor';
|
||||||
import FieldList from './Form/field-list';
|
import FieldList from './Form/field-list';
|
||||||
|
|
||||||
const AnkiForm = props => {
|
const AnkiForm = props => {
|
||||||
const [target, setTarget] = useState('');
|
const [target, setTarget] = useState('');
|
||||||
const [fields, setFields] = useState({});
|
const [fields, setFields] = useState({});
|
||||||
const [submitted, setSubmitted] = useState(true);
|
const [submitted, setSubmitted] = useState(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// props.wordInfo('Urge');
|
// props.wordInfo('Urge');
|
||||||
// props.wordInfo('Maze');
|
// props.wordInfo('Maze');
|
||||||
// props.wordInfo('Ramification');
|
// props.wordInfo('Ramification');
|
||||||
// props.wordInfo('Dare');
|
// props.wordInfo('Dare');
|
||||||
// props.wordInfo('Entrepreneurship');
|
// props.wordInfo('Entrepreneurship');
|
||||||
// props.wordInfo('meagre');
|
// props.wordInfo('meagre');
|
||||||
// props.wordInfo('meager');
|
// props.wordInfo('meager');
|
||||||
}, []);
|
}, []);
|
||||||
const getWord = word => {
|
const getWord = word => {
|
||||||
setTarget(word);
|
setTarget(word);
|
||||||
};
|
};
|
||||||
const submit = () => {
|
const submit = () => {
|
||||||
props.wordInfo(target);
|
props.wordInfo(target);
|
||||||
setSubmitted(true);
|
setSubmitted(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container style={{padding: 20}}>
|
<Container style={{padding: 20}}>
|
||||||
<Form>
|
<Form>
|
||||||
<DeckPicker />
|
<DeckPicker />
|
||||||
<InputWord word={getWord} onSubmit={submit} />
|
<InputWord word={getWord} onSubmit={submit} />
|
||||||
{submitted ? (
|
{submitted ? (
|
||||||
// <FieldEditor
|
// <FieldEditor
|
||||||
// data={{
|
// data={{
|
||||||
// type: 'part of speech',
|
// type: 'part of speech',
|
||||||
// values: ['1', '2', '3','5',],
|
// values: ['1', '2', '3','5',],
|
||||||
// }}
|
// }}
|
||||||
// />
|
// />
|
||||||
<FieldList/>
|
<FieldList />
|
||||||
) : (
|
) : (
|
||||||
<SubmitButton onSubmit={submit} />
|
<SubmitButton onSubmit={submit} />
|
||||||
)}
|
)}
|
||||||
</Form>
|
</Form>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
state => ({
|
state => ({
|
||||||
ankiLanModelExists: state.anki.ankiLanModelIsAlreadyExists,
|
ankiLanModelExists: state.anki.ankiLanModelIsAlreadyExists,
|
||||||
modelName: state.anki.ankiLanModelName,
|
modelName: state.anki.ankiLanModelName,
|
||||||
modelList: state.anki.modelList,
|
modelList: state.anki.modelList,
|
||||||
creator: state.anki.noteCreator,
|
creator: state.anki.noteCreator,
|
||||||
data: state
|
data: state,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
checkAnkiLanModelForExisting,
|
checkAnkiLanModelForExisting,
|
||||||
wordInfo,
|
wordInfo,
|
||||||
},
|
},
|
||||||
)(AnkiForm);
|
)(AnkiForm);
|
||||||
|
|
1
src/constants/component-types.js
Normal file
1
src/constants/component-types.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export const POS_PICKER = 'POS_PICKER'
|
Loading…
Reference in a new issue