Ankilan/src/components/anki-form.jsx

65 lines
1.6 KiB
React
Raw Normal View History

2020-03-20 15:19:09 +00:00
import React, {useEffect, useState} from 'react';
2020-03-10 04:22:42 +00:00
import {connect} from 'react-redux';
2020-03-07 14:30:26 +00:00
import DeckPicker from './view/deck-picker';
2020-03-11 03:31:37 +00:00
import {Form, Container, Item} from 'native-base';
2020-03-08 11:17:42 +00:00
import {checkAnkiLanModelForExisting} from '../actions/anki-get-actions';
2020-03-11 03:31:37 +00:00
import InputWord from './view/translatable-word';
import SubmitButton from './view/submit-button';
2020-03-31 07:54:08 +00:00
import {wordInfo} from '../actions/api/dictionary';
import FieldEditor from './view/field-editor';
2020-03-07 14:30:26 +00:00
2020-03-08 11:17:42 +00:00
const AnkiForm = props => {
2020-03-31 07:54:08 +00:00
const [target, setTarget] = useState('');
const [fields, setFields] = useState({});
const [submitted, setSubmitted] = useState(true);
useEffect(() => {
// props.wordInfo('Urge');
// props.wordInfo('Maze');
// props.wordInfo('Ramification');
// props.wordInfo('Dare');
// props.wordInfo('Entrepreneurship');
// props.wordInfo('meagre');
// props.wordInfo('meager');
}, []);
const getWord = word => {
setTarget(word);
};
const submit = () => {
props.wordInfo(target);
setSubmitted(true);
};
2020-03-31 07:54:08 +00:00
return (
<Container style={{padding: 20}}>
<Form>
<DeckPicker />
<InputWord word={getWord} onSubmit={submit} />
{submitted ? (
<FieldEditor
data={{
type: 'part of speech',
values: ['1', '2', '3','5',],
}}
/>
) : (
<SubmitButton onSubmit={submit} />
)}
</Form>
</Container>
);
2020-03-10 04:22:42 +00:00
};
2020-03-07 14:30:26 +00:00
2020-03-10 04:22:42 +00:00
export default connect(
2020-03-31 07:54:08 +00:00
state => ({
ankiLanModelExists: state.anki.ankiLanModelIsAlreadyExists,
modelName: state.anki.ankiLanModelName,
modelList: state.anki.modelList,
creator: state.anki.noteCreator,
data: state
}),
{
checkAnkiLanModelForExisting,
wordInfo,
},
2020-03-10 04:22:42 +00:00
)(AnkiForm);