refactor Form component view
This commit is contained in:
parent
f979007154
commit
5db54dea84
12 changed files with 9541 additions and 48 deletions
|
@ -1,6 +1,6 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
bracketSpacing: false,
|
bracketSpacing: false,
|
||||||
jsxBracketSameLine: true,
|
jsxBracketSameLine: true,
|
||||||
singleQuote: true,
|
singleQuote: true,
|
||||||
trailingComma: 'all',
|
trailingComma: "all"
|
||||||
};
|
}
|
9463
package-lock.json
generated
Normal file
9463
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -27,7 +27,7 @@
|
||||||
"@babel/runtime": "^7.6.2",
|
"@babel/runtime": "^7.6.2",
|
||||||
"@react-native-community/eslint-config": "^0.0.5",
|
"@react-native-community/eslint-config": "^0.0.5",
|
||||||
"babel-jest": "^24.9.0",
|
"babel-jest": "^24.9.0",
|
||||||
"eslint": "^6.5.1",
|
"eslint": "^0.11.0-alpha.0",
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
"metro-react-native-babel-preset": "^0.56.0",
|
"metro-react-native-babel-preset": "^0.56.0",
|
||||||
"react-test-renderer": "16.9.0",
|
"react-test-renderer": "16.9.0",
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
REACT_DEBUGGER="rndebugger-open --open --port 8081" npm start
|
REACT_DEBUGGER="rndebugger-open --open --port 8081" yarn start
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
GET_MODEL_LIST,
|
GET_MODEL_LIST,
|
||||||
REQUEST_PERMISSIONS,
|
REQUEST_PERMISSIONS,
|
||||||
SET_EXISTING_OF_ANKI_LAN_MODEL,
|
SET_EXISTING_OF_ANKI_LAN_MODEL,
|
||||||
|
SET_FIELD_LIST,
|
||||||
} from '../constants/anki-constants';
|
} from '../constants/anki-constants';
|
||||||
import {createAnkiLanModel} from './createAnkiLanModel';
|
import {createAnkiLanModel} from './createAnkiLanModel';
|
||||||
|
|
||||||
|
@ -76,12 +77,22 @@ export const getModelList = () => async dispatch => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFieldList = async (
|
export const setFieldList = fieldList => ({
|
||||||
id,
|
type: SET_FIELD_LIST,
|
||||||
getFieldListFunction = AnkiDroid.getFieldList,
|
payload: fieldList,
|
||||||
) => {
|
});
|
||||||
const [err, res] = await getFieldListFunction(id);
|
|
||||||
return err ? {type: ERROR, err} : {type: GET_FIELD_LIST, payload: res};
|
export const getFieldList = name => async dispatch => {
|
||||||
|
try {
|
||||||
|
const [err, res] = await AnkiDroid.getFieldList(name);
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
await dispatch(setFieldList(res));
|
||||||
|
return res;
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*Checking*/
|
/*Checking*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {AnkiDroid} from 'react-native-ankidroid/dist/ankidroid';
|
import {AnkiDroid} from 'react-native-ankidroid/dist/ankidroid';
|
||||||
import {setAnkiNoteCreator, setCreatorTemplate} from './anki-set-actions';
|
import {setAnkiNoteCreator, setCreatorTemplate} from './anki-set-actions';
|
||||||
import {checkAnkiLanModelForExisting, getModelList} from './anki-get-actions';
|
import {checkAnkiLanModelForExisting, getFieldList, getModelList} from './anki-get-actions';
|
||||||
|
|
||||||
export const createAnkiLanModel = model => async dispatch => {
|
export const createAnkiLanModel = model => async dispatch => {
|
||||||
try {
|
try {
|
||||||
|
@ -170,6 +170,7 @@ export const createAnkiLanModel = model => async dispatch => {
|
||||||
addNote(selectedDeck, valueFields, modelFields);
|
addNote(selectedDeck, valueFields, modelFields);
|
||||||
checkAnkiLanModelForExisting(model.name, model.list);
|
checkAnkiLanModelForExisting(model.name, model.list);
|
||||||
await dispatch(getModelList());
|
await dispatch(getModelList());
|
||||||
|
await dispatch(getFieldList(model.name));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,42 @@
|
||||||
import React from 'react';
|
import React, {useEffect} from 'react';
|
||||||
import {Container, Text} from 'native-base';
|
import {Container, Text} from 'native-base';
|
||||||
import {ScrollView} from 'react-native'
|
import {ScrollView} from 'react-native';
|
||||||
import Permissions from './permissions';
|
import Permissions from './permissions';
|
||||||
import {connect, Provider} from 'react-redux';
|
import {connect, Provider} from 'react-redux';
|
||||||
import DeckPicker from './view/deck-picker';
|
import DeckPicker from './view/deck-picker';
|
||||||
import AddWordForm from './anki-form';
|
import AddWordForm from './anki-form';
|
||||||
import AnkiTemplate from './view/add-main-template';
|
import AnkiTemplate from './view/add-main-template';
|
||||||
import {Grid, Row} from 'native-base';
|
import {Grid, Row} from 'native-base';
|
||||||
|
import {checkAnkiLanModelForExisting} from '../actions/anki-get-actions';
|
||||||
|
|
||||||
const StartScreen = props => {
|
const StartScreen = props => {
|
||||||
return (
|
useEffect(() => {
|
||||||
<ScrollView>
|
props.checkAnkiLanModelForExisting(props.modelName, props.modelList);
|
||||||
{props.ankiAvailable? <AddWordForm/>: <Permissions /> }
|
});
|
||||||
</ScrollView>
|
return (
|
||||||
)
|
<ScrollView>
|
||||||
|
{props.ankiAvailable ? (
|
||||||
|
props.ankiLanModelExists ? (
|
||||||
|
<AddWordForm />
|
||||||
|
) : (
|
||||||
|
<AnkiTemplate />
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<Permissions />
|
||||||
|
)}
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(state => ({
|
export default connect(
|
||||||
|
state => ({
|
||||||
ankiAvailable: state.anki.appHasAccess,
|
ankiAvailable: state.anki.appHasAccess,
|
||||||
}))(StartScreen);
|
ankiLanModelExists: state.anki.ankiLanModelIsAlreadyExists,
|
||||||
|
modelName: state.anki.ankiLanModelName,
|
||||||
|
modelList: state.anki.modelList,
|
||||||
|
creator: state.anki.noteCreator,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
checkAnkiLanModelForExisting,
|
||||||
|
},
|
||||||
|
)(StartScreen);
|
||||||
|
|
|
@ -1,33 +1,29 @@
|
||||||
import React , {useEffect}from 'react'
|
import React, {useEffect} from 'react';
|
||||||
import {connect} from 'react-redux'
|
import {connect} from 'react-redux';
|
||||||
import DeckPicker from './view/deck-picker';
|
import DeckPicker from './view/deck-picker';
|
||||||
import{Form, Container} from 'native-base';
|
import {Form, Container} from 'native-base';
|
||||||
import AnkiTemplate from './view/add-main-template';
|
import AnkiTemplate from './view/add-main-template';
|
||||||
import {ScrollView} from 'react-native';
|
import {ScrollView} from 'react-native';
|
||||||
import {checkAnkiLanModelForExisting} from '../actions/anki-get-actions';
|
import {checkAnkiLanModelForExisting} from '../actions/anki-get-actions';
|
||||||
|
|
||||||
const AnkiForm = props => {
|
const AnkiForm = props => {
|
||||||
useEffect(() => {
|
return (
|
||||||
props.checkAnkiLanModelForExisting(props.modelName, props.modelList)
|
<Container style={{padding: 20}}>
|
||||||
})
|
<Form>
|
||||||
return (
|
<DeckPicker />
|
||||||
<Container style={{padding: 20}}>
|
</Form>
|
||||||
<DeckPicker/>
|
</Container>
|
||||||
{props.ankiLanModelExists ?
|
);
|
||||||
<Form>
|
};
|
||||||
</Form>
|
|
||||||
:
|
|
||||||
<AnkiTemplate/>
|
|
||||||
}
|
|
||||||
</Container>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default connect(state => ({
|
export default connect(
|
||||||
|
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,
|
||||||
}), {
|
}),
|
||||||
checkAnkiLanModelForExisting
|
{
|
||||||
})(AnkiForm)
|
checkAnkiLanModelForExisting,
|
||||||
|
},
|
||||||
|
)(AnkiForm);
|
||||||
|
|
|
@ -13,7 +13,7 @@ const Permissions = props => {
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
}}>
|
}}>
|
||||||
<Button onPress={() => requestAnkiPermission()}>
|
<Button onPress={() => props.requestAnkiPermission()}>
|
||||||
<Text>Request access</Text>
|
<Text>Request access</Text>
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -11,6 +11,7 @@ export const GET_MODEL_LIST = 'GET_MODEL_LIST';
|
||||||
export const GET_FIELD_LIST = 'GET_FIELD_LIST';
|
export const GET_FIELD_LIST = 'GET_FIELD_LIST';
|
||||||
//Anki set actions
|
//Anki set actions
|
||||||
export const SET_DECK = 'SET_DECK';
|
export const SET_DECK = 'SET_DECK';
|
||||||
|
export const SET_FIELD_LIST = 'SET_FIELD_LIST';
|
||||||
export const SET_WORD_DEFINITION = 'SET_DEFINITION';
|
export const SET_WORD_DEFINITION = 'SET_DEFINITION';
|
||||||
export const SET_WORD_SOUND = 'SET_WORD_SOUND';
|
export const SET_WORD_SOUND = 'SET_WORD_SOUND';
|
||||||
export const SET_WORD_TRANSLATE = 'SET_WORD_TRANSLATE';
|
export const SET_WORD_TRANSLATE = 'SET_WORD_TRANSLATE';
|
||||||
|
|
|
@ -20,7 +20,7 @@ const initialState = {
|
||||||
mainFieldIsAvailable: false,
|
mainFieldIsAvailable: false,
|
||||||
fieldList: [],
|
fieldList: [],
|
||||||
ankiLanModelIsAlreadyExists: false,
|
ankiLanModelIsAlreadyExists: false,
|
||||||
ankiLanModelName: 'AnkiLan2',
|
ankiLanModelName: 'AnkiLan3',
|
||||||
noteCreator: {},
|
noteCreator: {},
|
||||||
noteTemplate: [],
|
noteTemplate: [],
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue