Dev #9

Merged
Horhik merged 7 commits from dev into master 2020-05-10 23:17:38 +00:00
9 changed files with 81 additions and 69 deletions
Showing only changes of commit 5bf46fd5fa - Show all commits

View file

@ -68,12 +68,10 @@ const setModelList = res => {
export const getModelList = () => async dispatch => { export const getModelList = () => async dispatch => {
try { try {
const [err, res] = await AnkiDroid.getModelList(); const [err, res] = await AnkiDroid.getModelList();
console.log('RESRES', res);
if (err) { if (err) {
throw err; throw err;
} }
await dispatch(setModelList(res)); await dispatch(setModelList(res));
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
@ -105,23 +103,22 @@ const setExistingOfAnkiLanModel = existing => {
}; };
}; };
export const checkAnkiLanModelForExisting = name => async dispatch => { export const checkAnkiLanModelForExisting = name => async dispatch => {
setTimeout( async () => { setTimeout(async () => {
try { try {
const [error, modelList] = await AnkiDroid.getModelList() const [error, modelList] = await AnkiDroid.getModelList();
console.log('CECKCKC', name, modelList); for (let model of modelList) {
for (let model of modelList) { if (model.name === name) {
if (model.name === name) { await dispatch(setExistingOfAnkiLanModel(true));
await dispatch(setExistingOfAnkiLanModel(true)); return true;
return true; }
} }
const err = 'Model not found. Displaying message...';
throw err;
} catch (err) {
console.log(err);
await dispatch(setExistingOfAnkiLanModel(false));
} }
const err = 'Model not found. Displaying message...'; }, 2000);
throw err;
} catch (err) {
console.log(err);
await dispatch(setExistingOfAnkiLanModel(false));
}
}, 2000)
}; };
export const getModelId = (models, name) => { export const getModelId = (models, name) => {

View file

@ -0,0 +1,12 @@
import {SELECT_POS_ID} from '../constants/anki-constants';
export const setPosId = (id, value) => {
console.log('setPosId');
console.log(id);
console.log(value);
return {
type: SELECT_POS_ID,
payload: value,
id,
};
};

View file

@ -12,3 +12,8 @@ export const sendField = field => ({
payload: field.text, payload: field.text,
role: field.role, role: field.role,
}); });
export const selectCertainFormValue = (
unicName = String,
value = String,
) => ({});

View file

@ -6,7 +6,7 @@ import IconedButton from '../view/iconed-button.jsx';
import {POS_PICKER} from '../../constants/component-types'; import {POS_PICKER} from '../../constants/component-types';
import set from '@babel/runtime/helpers/esm/set'; import set from '@babel/runtime/helpers/esm/set';
const FieldEditor = props => { const FieldEditor = (props) => {
const label = props.data.label; const label = props.data.label;
const constantValues = props.pos | ''; const constantValues = props.pos | '';
const [values, setValues] = useState(props.data.values); const [values, setValues] = useState(props.data.values);
@ -24,19 +24,19 @@ const FieldEditor = props => {
const [] = useState(); const [] = useState();
const [] = useState(); const [] = useState();
const select = value => { const select = (value) => {
setSelectedValue(value); setSelectedValue(value);
setFiniteValue(value); setFiniteValue(value);
setEditingValue(value); setEditingValue(value);
}; };
const typing = text => { const typing = (text) => {
setEditingValue(text); setEditingValue(text);
}; };
const setTyped = () => { const setTyped = () => {
try { try {
let valuesSet = new Set(values); let valuesSet = new Set(props.data.values);
valuesSet.add(editingValue); valuesSet.add(editingValue);
const valuesArray = Array.from(valuesSet).slice(); const valuesArray = Array.from(valuesSet).slice();
setValues(valuesArray); setValues(valuesArray);
@ -51,7 +51,7 @@ const FieldEditor = props => {
useEffect(() => { useEffect(() => {
if (props.type === POS_PICKER) { if (props.type === POS_PICKER) {
values.forEach((value, id) => { props.data.values.forEach((value, id) => {
if (value === finiteValue) { if (value === finiteValue) {
props.hasChanged(id); props.hasChanged(id);
} }
@ -62,7 +62,6 @@ const FieldEditor = props => {
}, [finiteValue]); }, [finiteValue]);
useEffect(() => { useEffect(() => {
setValues(props.data.values); setValues(props.data.values);
setSelectedValue(props.data.values[0]);
console.log('EXECUTIN'); console.log('EXECUTIN');
}, [constantValues]); }, [constantValues]);
@ -119,8 +118,8 @@ const FieldEditor = props => {
<Text style={styles.pickerLabel}>{props.data.label}</Text> <Text style={styles.pickerLabel}>{props.data.label}</Text>
<Picker <Picker
selectedValue={selectedValue} selectedValue={selectedValue}
onValueChange={value => select(value)}> onValueChange={(value) => select(value)}>
{values.map((value, id) => { {props.data.values.map((value, id) => {
return <Picker.Item value={value} label={value} key={id} />; return <Picker.Item value={value} label={value} key={id} />;
})} })}
</Picker> </Picker>
@ -137,7 +136,7 @@ const FieldEditor = props => {
label={label} label={label}
value={editingValue} value={editingValue}
editable={true} editable={true}
onChangeText={text => typing(text)} onChangeText={(text) => typing(text)}
autoFocus={true} autoFocus={true}
/> />
<View style={styles.hr} /> <View style={styles.hr} />
@ -147,8 +146,8 @@ const FieldEditor = props => {
<Text style={styles.pickerLabel}>{props.data.label}</Text> <Text style={styles.pickerLabel}>{props.data.label}</Text>
<Picker <Picker
selectedValue={selectedValue} selectedValue={selectedValue}
onValueChange={value => select(value)}> onValueChange={(value) => select(value)}>
{values.map((value, id) => { {props.data.values.map((value, id) => {
return ( return (
<Picker.Item value={value} label={value} key={id} /> <Picker.Item value={value} label={value} key={id} />
); );

View file

@ -18,7 +18,7 @@ import {
import {sendField} from '../../actions/form-actions'; import {sendField} from '../../actions/form-actions';
import {addNote} from '../../actions/createAnkiLanModel'; import {addNote} from '../../actions/createAnkiLanModel';
const FieldList = props => { const FieldList = (props) => {
const [pronunciation, setPronunciation] = useState( const [pronunciation, setPronunciation] = useState(
props.response.pronunciation, props.response.pronunciation,
); );
@ -46,10 +46,11 @@ const FieldList = props => {
setSound(props.response.sound); setSound(props.response.sound);
setPronunciation(props.response.pronunciation); setPronunciation(props.response.pronunciation);
setExamples(props.response.examples); setExamples(props.response.examples);
console.log('DPEDDDDD', props.response.compounded);
}, [props]); }, [props]);
const [loadingState, setLoadingState] = useState(false); const [loadingState, setLoadingState] = useState(false);
useEffect(() => { useEffect(() => {
console.log('STATE', examples, pronunciation, sound); // console.log('STATE', examples, pronunciation, sound);
if (examples && pronunciation && sound) { if (examples && pronunciation && sound) {
setLoadingState(true); setLoadingState(true);
} else { } else {
@ -64,15 +65,11 @@ const FieldList = props => {
<ScrollView keyboardShouldPersistTaps={'handled'} style={{height: '100%'}}> <ScrollView keyboardShouldPersistTaps={'handled'} style={{height: '100%'}}>
{loadingState && props.loadingState ? ( {loadingState && props.loadingState ? (
<View> <View>
<PickerList labelNum={1} id={0} role={DEF_LIST1} /> <PickerList labelNum={1} id={props.pos1id} role={DEF_LIST1} />
{/*<PickerList labelNum={2} id={1} role={DEF_LIST2} />*/} {/*<PickerList labelNum={2} id={1} role={DEF_LIST2} />*/}
<PickerList <PickerList labelNum={2} id={props.pos2id} role={DEF_LIST2} />
labelNum={2}
id={props.response.compounded.length >= 2 ? 1 : 0}
role={DEF_LIST2}
/>
<FieldEditor <FieldEditor
hasChanged={c => hasChanged={(c) =>
props.sendField({ props.sendField({
text: c, text: c,
role: EXAMPLES, role: EXAMPLES,
@ -85,7 +82,7 @@ const FieldList = props => {
}} }}
/> />
<FieldEditor <FieldEditor
hasChanged={c => hasChanged={(c) =>
props.sendField({ props.sendField({
text: c, text: c,
role: SOUND, role: SOUND,
@ -95,7 +92,7 @@ const FieldList = props => {
role={SOUND} role={SOUND}
/> />
<FieldEditor <FieldEditor
hasChanged={c => hasChanged={(c) =>
props.sendField({ props.sendField({
text: c, text: c,
role: PRONUNCIATION, role: PRONUNCIATION,
@ -119,11 +116,13 @@ const FieldList = props => {
); );
}; };
export default connect( export default connect(
state => ({ (state) => ({
response: state.api.parsedDictionary, response: state.api.parsedDictionary,
word: state.api.availableApi.word, word: state.api.availableApi.word,
loadingState: state.api.apiIsLoaded, loadingState: state.api.apiIsLoaded,
fields: state.anki.currentFields, fields: state.anki.currentFields,
pos1id: state.anki.pos1id,
pos2id: state.anki.pos2id,
}), }),
{ {
sendField, sendField,

View file

@ -5,30 +5,23 @@ import PosPicker from './pos-picker';
import FieldEditor from './field-editor'; import FieldEditor from './field-editor';
import {setDef} from '../../actions/anki-set-actions'; import {setDef} from '../../actions/anki-set-actions';
import {sendField} from '../../actions/form-actions'; import {sendField} from '../../actions/form-actions';
import {setPosId} from '../../actions/anki-ui-actions';
/* /*
****************** 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) => {
const [data, setData] = useState(props.data[props.id]);
const [tr, setTr] = useState(props.data[props.id].definitions[0]); const [tr, setTr] = useState(props.data[props.id].definitions[0]);
const [def, setDef] = 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); const [pos, setPos] = useState(props.data[props.id].pos);
const [globID, setId] = useState(props.id);
useEffect(() => { useEffect(() => {
setData(props.data[props.id]); // props.setPosId(props.id, props.id);
setTimeout(() => { setPos(props.data[props.id].pos);
selectDef(0); setDef(props.data[props.id].definitions[0]);
}, 0); setTr(props.data[props.id].translates[0]);
console.log('emmit', props.id);
}, [props]); }, [props]);
const selectDef = id => {
setId(id);
setPos(props.data[id].pos);
setDef(props.data[id].definitions[0]);
setTr(props.data[id].translates[0]);
};
useEffect(() => { useEffect(() => {
props.sendField({ props.sendField({
@ -39,17 +32,9 @@ const PickerList = props => {
}, },
role: props.role, role: props.role,
}); });
props.sendField('HDFSL:FJL:SKDJF: SLDKJF:LSDJF:LSDKFJ SDF', {
text: {
pos: pos,
tr: tr,
definition: def,
},
role: props.role,
});
}, [tr, def, pos]); }, [tr, def, pos]);
const updateData = c => { const updateData = (c) => {
console.log('HDFLSDKFJ SDF', { console.log('HDFLSDKFJ SDF', {
text: { text: {
pos: pos, pos: pos,
@ -65,40 +50,43 @@ const PickerList = props => {
<PosPicker <PosPicker
labelNum={props.labelNum} labelNum={props.labelNum}
defaultId={props.id} defaultId={props.id}
onSelect={id => selectDef(id | props.id)} onSelect={(id) => {
props.setPosId(props.labelNum - 1, id);
}}
/> />
<FieldEditor <FieldEditor
hasChanged={c => { hasChanged={(c) => {
setTr(c); setTr(c);
updateData(c); updateData(c);
}} }}
pos={pos} pos={pos}
data={{ data={{
label: `Translate ${props.labelNum}`, label: `Translate ${props.labelNum}`,
values: props.data[globID].translates, values: props.data[props.id].translates,
}} }}
/> />
<FieldEditor <FieldEditor
hasChanged={c => { hasChanged={(c) => {
setDef(c); setDef(c);
updateData(c); updateData(c);
}} }}
pos={pos} pos={pos}
data={{ data={{
label: `Definition ${props.labelNum}`, label: `Definition ${props.labelNum}`,
values: props.data[globID].definitions, values: props.data[props.id].definitions,
}} }}
/> />
</View> </View>
); );
}; };
export default connect( export default connect(
state => ({ (state) => ({
data: state.api.parsedDictionary.compounded, data: state.api.parsedDictionary.compounded,
word: state.api.availableApi.word, word: state.api.availableApi.word,
}), }),
{ {
setDef, setDef,
sendField, sendField,
setPosId,
}, },
)(PickerList); )(PickerList);

View file

@ -9,6 +9,7 @@ const PosPicker = props => {
const [poses, setPoses] = useState([]); const [poses, setPoses] = useState([]);
useEffect(() => { useEffect(() => {
if (props.parts) { if (props.parts) {
console.log('PARTASSDFSD', props.defaultId)
let posArray = props.parts.map((part, id) => part.pos); let posArray = props.parts.map((part, id) => part.pos);
setPoses(posArray); setPoses(posArray);
setReady(true); setReady(true);

View file

@ -32,6 +32,7 @@ export const ANKILAN_DATA = 'ANKILAN_DATA';
//form actions //form actions
export const SEND_FIELD = 'SEND_FIELD'; export const SEND_FIELD = 'SEND_FIELD';
export const SELECT_POS_ID = 'SELECT_POS_ID';
//field names //field names
export const SOUND = 'SOUND'; export const SOUND = 'SOUND';

View file

@ -6,6 +6,7 @@ import {
GET_MODEL_LIST, GET_MODEL_LIST,
PRONUNCIATION, PRONUNCIATION,
REQUEST_PERMISSIONS, REQUEST_PERMISSIONS,
SELECT_POS_ID,
SEND_FIELD, SEND_FIELD,
SET_ANKI_DATA, SET_ANKI_DATA,
SET_ANKI_NOTE_CREATOR, SET_ANKI_NOTE_CREATOR,
@ -31,6 +32,8 @@ const initialState = {
ankiLanModelName: 'develop_final_maybe_maybe_maybe', ankiLanModelName: 'develop_final_maybe_maybe_maybe',
noteCreator: {}, noteCreator: {},
noteTemplate: [], noteTemplate: [],
pos1id: 0,
pos2id: 0,
currentFields: { currentFields: {
word: '', word: '',
compounded: [ compounded: [
@ -68,6 +71,12 @@ const ankiReducer = (state = initialState, action) => {
...state, ...state,
savedData: action.payload, savedData: action.payload,
}; };
case SELECT_POS_ID: {
console.log('click', action.id);
return action.id == 1
? {...state, pos2id: action.payload}
: {...state, pos1id: action.payload};
}
case SEND_FIELD: { case SEND_FIELD: {
const fields = state.currentFields; const fields = state.currentFields;
switch (action.role) { switch (action.role) {
@ -120,6 +129,7 @@ const ankiReducer = (state = initialState, action) => {
} }
} }
} }
default: default:
return state; return state;
} }