import React, {useState, useEffect} from 'react'; import {connect} from 'react-redux'; import {View, Icon, Button, Text} from 'native-base'; import {TextField} from 'react-native-material-textfield'; import FieldEditor from './field-editor'; import TextInput from './text-input'; import {ScrollView} from 'react-native'; import PickerList from './picker-list'; import {setFields} from '../../actions/anki-set-actions'; import { DEF_LIST1, DEF_LIST2, EXAMPLES, PRONUNCIATION, SOUND, WORD, } from '../../constants/anki-constants'; import {sendField} from '../../actions/form-actions'; import {addNote} from '../../actions/createAnkiLanModel'; const FieldList = (props) => { const [pronunciation, setPronunciation] = useState( props.response.pronunciation, ); const [sound, setSound] = useState(); const [examples, setExamples] = useState(); const [completedFields, setCompletedFields] = useState({ word: props.word, compounded: [{pos: '', tr: '', definition: ''}, {}], examples: '', pronunciation: '', sound: '', }); useEffect(() => { if ( props.response.sound && props.response.pronunciation && props.response.compounded && props.response.examples ) { // console.log("LOOOADED") } else { } }); useEffect(() => { setSound(props.response.sound); setPronunciation(props.response.pronunciation); setExamples(props.response.examples); console.log('DPEDDDDD', props.response.compounded); }, [props]); const [loadingState, setLoadingState] = useState(false); useEffect(() => { // console.log('STATE', examples, pronunciation, sound); if (examples && pronunciation && sound) { setLoadingState(true); } else { setLoadingState(false); } }); useEffect(() => {}, [pronunciation]); const submit = () => { props.setFields(props.fields); }; return ( {loadingState && props.loadingState ? ( {/**/} props.sendField({ text: c, role: EXAMPLES, }) } role={EXAMPLES} data={{ label: 'Usage example', values: props.response.examples || ['can not find the example'], }} /> props.sendField({ text: c, role: SOUND, }) } data={{values: [props.response.sound], label: 'Sound'}} role={SOUND} /> props.sendField({ text: c, role: PRONUNCIATION, }) } role={PRONUNCIATION} data={{ values: [props.response.pronunciation], label: 'Pronunciation', }} /> ) : ( Loading... )} ); }; export default connect( (state) => ({ response: state.api.parsedDictionary, word: state.api.availableApi.word, loadingState: state.api.apiIsLoaded, fields: state.anki.currentFields, pos1id: state.anki.pos1id, pos2id: state.anki.pos2id, }), { sendField, setFields, }, )(FieldList);