2020-04-03 06:32:26 +00:00
|
|
|
import React, {useState, useEffect, useRef} from 'react';
|
2020-04-03 05:14:18 +00:00
|
|
|
import {View} from 'native-base';
|
2020-04-03 06:32:26 +00:00
|
|
|
import {connect} from 'react-redux';
|
|
|
|
import PosPicker from './pos-picker';
|
|
|
|
import FieldEditor from './field-editor';
|
2020-04-11 16:49:25 +00:00
|
|
|
import {setDef} from '../../actions/anki-set-actions';
|
|
|
|
import {sendField} from '../../actions/form-actions';
|
2020-05-10 15:16:01 +00:00
|
|
|
import {setPosId} from '../../actions/anki-ui-actions';
|
2020-04-03 05:14:18 +00:00
|
|
|
/*
|
2020-04-03 06:32:26 +00:00
|
|
|
****************** props:*****************
|
|
|
|
* startId props.data[0] / [1] /[8] ...
|
|
|
|
* labelNum // Translate 1 / Translate 2 ...
|
|
|
|
* */
|
2020-05-10 15:16:01 +00:00
|
|
|
const PickerList = (props) => {
|
2020-04-11 16:49:25 +00:00
|
|
|
const [tr, setTr] = useState(props.data[props.id].definitions[0]);
|
|
|
|
const [def, setDef] = useState(props.data[props.id].definitions[0]);
|
|
|
|
const [pos, setPos] = useState(props.data[props.id].pos);
|
2020-04-03 06:32:26 +00:00
|
|
|
useEffect(() => {
|
2020-05-10 15:16:01 +00:00
|
|
|
// props.setPosId(props.id, props.id);
|
|
|
|
setPos(props.data[props.id].pos);
|
|
|
|
setDef(props.data[props.id].definitions[0]);
|
|
|
|
setTr(props.data[props.id].translates[0]);
|
|
|
|
console.log('emmit', props.id);
|
2020-04-03 11:51:00 +00:00
|
|
|
}, [props]);
|
2020-04-11 16:49:25 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2020-04-22 05:34:14 +00:00
|
|
|
props.sendField({
|
|
|
|
text: {
|
|
|
|
pos: pos,
|
|
|
|
tr: tr,
|
|
|
|
definition: def,
|
|
|
|
},
|
|
|
|
role: props.role,
|
|
|
|
});
|
2020-04-11 16:49:25 +00:00
|
|
|
}, [tr, def, pos]);
|
|
|
|
|
2020-05-10 15:16:01 +00:00
|
|
|
const updateData = (c) => {
|
2020-04-22 05:34:14 +00:00
|
|
|
console.log('HDFLSDKFJ SDF', {
|
|
|
|
text: {
|
|
|
|
pos: pos,
|
|
|
|
tr: tr,
|
|
|
|
definition: def,
|
|
|
|
},
|
|
|
|
role: props.role,
|
|
|
|
});
|
2020-04-03 11:51:00 +00:00
|
|
|
};
|
2020-04-11 16:49:25 +00:00
|
|
|
|
2020-04-03 06:32:26 +00:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<PosPicker
|
|
|
|
labelNum={props.labelNum}
|
2020-04-11 16:49:25 +00:00
|
|
|
defaultId={props.id}
|
2020-05-10 15:16:01 +00:00
|
|
|
onSelect={(id) => {
|
|
|
|
props.setPosId(props.labelNum - 1, id);
|
|
|
|
}}
|
2020-04-03 06:32:26 +00:00
|
|
|
/>
|
2020-04-03 11:51:00 +00:00
|
|
|
<FieldEditor
|
2020-05-10 15:16:01 +00:00
|
|
|
hasChanged={(c) => {
|
2020-04-11 16:49:25 +00:00
|
|
|
setTr(c);
|
2020-04-22 05:34:14 +00:00
|
|
|
updateData(c);
|
2020-04-11 16:49:25 +00:00
|
|
|
}}
|
|
|
|
pos={pos}
|
|
|
|
data={{
|
|
|
|
label: `Translate ${props.labelNum}`,
|
2020-05-10 15:16:01 +00:00
|
|
|
values: props.data[props.id].translates,
|
2020-04-11 16:49:25 +00:00
|
|
|
}}
|
2020-04-03 11:51:00 +00:00
|
|
|
/>
|
|
|
|
<FieldEditor
|
2020-05-10 15:16:01 +00:00
|
|
|
hasChanged={(c) => {
|
2020-04-11 16:49:25 +00:00
|
|
|
setDef(c);
|
|
|
|
updateData(c);
|
|
|
|
}}
|
|
|
|
pos={pos}
|
|
|
|
data={{
|
|
|
|
label: `Definition ${props.labelNum}`,
|
2020-05-10 15:16:01 +00:00
|
|
|
values: props.data[props.id].definitions,
|
2020-04-11 16:49:25 +00:00
|
|
|
}}
|
2020-04-03 11:51:00 +00:00
|
|
|
/>
|
2020-04-03 06:32:26 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
2020-04-11 16:49:25 +00:00
|
|
|
export default connect(
|
2020-05-10 15:16:01 +00:00
|
|
|
(state) => ({
|
2020-04-11 16:49:25 +00:00
|
|
|
data: state.api.parsedDictionary.compounded,
|
|
|
|
word: state.api.availableApi.word,
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
setDef,
|
|
|
|
sendField,
|
2020-05-10 15:16:01 +00:00
|
|
|
setPosId,
|
2020-04-11 16:49:25 +00:00
|
|
|
},
|
|
|
|
)(PickerList);
|