-
- {{Sound}}`;
- const modelProperties = {
- name: model.name,
- reference: 'com.ankilan.models',
- fields: modelFields,
- tags: [],
- cardNames: ['Rus->En', 'En->Rus'],
- questionFormat,
- answerFormat,
- css,
- };
- const settings = {
- modelId: model.id,
- modelProperties,
- deckId: model.deck.id,
- };
- new AnkiDroid(settings).addNote(
- [
- 'Word or sentence',
- 'Part of speech 1',
- 'Translate 1',
- 'Definition 1',
- 'Part of speech 2',
- 'Translate 2',
- 'Definition 2',
- 'Example',
- 'Transcription',
- 'Sound',
- ],
- modelFields,
- );
- } catch (err) {
- console.log(err);
- }*/
-
- ///////////////////////////////////
- // SETTING UP THE DECK AND MODEL //
- ///////////////////////////////////
-
- // Name of deck which will be created in AnkiDroid
const deckName = model.deck.name;
- // Name of model which will be created in AnkiDroid (can be any string)
- const modelName = model.name + '_test';
- // Used to save a reference to this deck in the SharedPreferences (can be any string)
+ const modelName = model.name;
const dbDeckReference = 'com.anki.decks';
- // Used to save a reference to this model in the SharedPreferences (can be any string)
const dbModelReference = 'com.anki.models';
- // Optional space separated list of tags to add to every note
const tags = ['AnkiLan'];
- // List of field names that will be used in AnkiDroid model
const modelFields = [
'Word or sentence',
'Part of speech 1',
@@ -132,9 +21,7 @@ export const createAnkiLanModel = model => async dispatch => {
'Transcription',
'Sound',
];
- // List of card names that will be used in AnkiDroid (one for each direction of learning)
const cardNames = ['Russian>English', 'English>Russian'];
- // CSS to share between all the cards (optional).
const css = `.card {
font-family: 'Roboto', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-size: 24px;
@@ -167,33 +54,33 @@ export const createAnkiLanModel = model => async dispatch => {
color: #1e7efc;
font-weight: bold;
}
-.list{
-list-style: none;
-display: flex;
-flex-direction:column;
-align-items:center;
-padding: 0;
-}
-.definition{
-font-size: 20px;
-font-famyli: sans-serif;
-font-style: italic;
-display: block;
-margin: 7px ;
-padding: 0 20px ;
-white-space: normal;
-width: 70vw;
-}
-.usage{
-background-color: rgba(100,100,100,0.1);
-padding: 10px;
-font-size: 20px;
-white-space: normal;
-width: 70vw;
-margin: 0 auto;
-border-radius: 5px;
-}`;
- // Template for the question of each card
+ .list{
+ list-style: none;
+ display: flex;
+ flex-direction:column;
+ align-items:center;
+ padding: 0;
+ }
+ .definition{
+ font-size: 20px;
+ font-famyli: sans-serif;
+ font-style: italic;
+ display: block;
+ margin: 7px ;
+ padding: 0 20px ;
+ white-space: normal;
+ width: 70vw;
+ }
+ .usage{
+ background-color: rgba(100,100,100,0.1);
+ padding: 10px;
+ font-size: 20px;
+ white-space: normal;
+ width: 70vw;
+ margin: 0 auto;
+ border-radius: 5px;
+ }`;
+
const questionFmt1 = `
{{Word or sentence}}
@@ -208,21 +95,19 @@ border-radius: 5px;
{{Transcription}}
{{Sound}}
`;
+
const questionFmt2 = '
{{Translation 1}}
';
+
const questionFormat = [questionFmt1, questionFmt2];
- // Template for the answer (this example is identical for both sides)
+
const answerFmt1 = `
{{Word or sentence}}
{{Transcription}}
{{Sound}}
-
-
-
{{Usage example}}
-
@@ -243,9 +128,7 @@ border-radius: 5px;
`;
const answerFormat = [answerFmt1, answerFmt1];
- //////////////////
// ADDING NOTES //
- //////////////////
const deckProperties = {
name: deckName,
@@ -263,16 +146,16 @@ border-radius: 5px;
};
const valueFields = [
- 'Word or sentence',
- 'Part of speech 1',
- 'Translation 1',
- 'Definition 1',
- 'Part of speech 2',
- 'Translation 2',
- 'Definition 2',
- 'Usage example',
- 'Transcription',
- 'Sound',
+ 'AnkiLan',
+ 'Translate by typing the word',
+ '',
+ 'You can type the word in input field and get translate, sound and definition of this word',
+ 'Translate via sharing',
+ '',
+ 'You can mark the word in you phone and share it with AnkiLan',
+ 'IMAGE WILL BE HERE',
+ 'guide',
+ '',
];
const settings = {
@@ -281,12 +164,17 @@ border-radius: 5px;
deckId: model.deck.id,
deckProperties: deckProperties,
};
-
const selectedDeck = new AnkiDroid(settings);
-
- selectedDeck.addNote(valueFields, modelFields);
- // returns a promise that returns the added note ID
+ await dispatch(setAnkiNoteCreator(selectedDeck));
+ await dispatch(setCreatorTemplate(modelFields));
+ addNote(selectedDeck, valueFields, modelFields);
+ checkAnkiLanModelForExisting(model.name, model.list);
+ await dispatch(getModelList());
} catch (err) {
console.log(err);
}
};
+
+export const addNote = (creator, words, template) => {
+ creator.addNote(words, template);
+};
diff --git a/src/components/add-anklan-model.jsx b/src/components/add-anklan-model.jsx
index 364b224..e041a04 100644
--- a/src/components/add-anklan-model.jsx
+++ b/src/components/add-anklan-model.jsx
@@ -4,7 +4,7 @@ import {ScrollView} from 'react-native'
import Permissions from './permissions';
import {connect, Provider} from 'react-redux';
import DeckPicker from './view/deck-picker';
-import AddWordForm from './add-word-form';
+import AddWordForm from './anki-form';
import AnkiTemplate from './view/add-main-template';
import {Grid, Row} from 'native-base';
diff --git a/src/components/add-word-form.jsx b/src/components/anki-form.jsx
similarity index 52%
rename from src/components/add-word-form.jsx
rename to src/components/anki-form.jsx
index 96f9bc0..a89a1cb 100644
--- a/src/components/add-word-form.jsx
+++ b/src/components/anki-form.jsx
@@ -1,11 +1,15 @@
-import React from 'react'
+import React , {useEffect}from 'react'
import {connect} from 'react-redux'
import DeckPicker from './view/deck-picker';
import{Form, Container} from 'native-base';
import AnkiTemplate from './view/add-main-template';
import {ScrollView} from 'react-native';
+import {checkAnkiLanModelForExisting} from '../actions/anki-get-actions';
-const AddWordForm = props => {
+const AnkiForm = props => {
+ useEffect(() => {
+ props.checkAnkiLanModelForExisting(props.modelName, props.modelList)
+ })
return (
@@ -20,5 +24,10 @@ const AddWordForm = props => {
}
export default connect(state => ({
- ankiLanModelExists: state.anki.ankiLanModelIsAlreadyExists
-}))(AddWordForm)
+ ankiLanModelExists: state.anki.ankiLanModelIsAlreadyExists,
+ modelName: state.anki.ankiLanModelName,
+ modelList: state.anki.modelList,
+ creator: state.anki.noteCreator
+}), {
+ checkAnkiLanModelForExisting
+})(AnkiForm)
diff --git a/src/components/view/add-main-template.jsx b/src/components/view/add-main-template.jsx
index 7f843d3..716b928 100644
--- a/src/components/view/add-main-template.jsx
+++ b/src/components/view/add-main-template.jsx
@@ -1,18 +1,15 @@
-import React, {useEffect} from 'react'
+import React from 'react'
import {Text, Button,Grid, Container} from 'native-base';
-import {checkAnkiLanModelForExisting} from '../../actions/anki-get-actions';
import {connect} from 'react-redux'
import {createAnkiLanModel} from '../../actions/createAnkiLanModel';
const AnkiTemplate = props => {
- useEffect(() => {
- props.checkAnkiLanModelForExisting(props.modelName)
- }, [])
return(
You have no AnkiLan card template
@@ -23,8 +20,8 @@ const AnkiTemplate = props => {
export default connect(state => ({
modelName: state.anki.ankiLanModelName,
- currentDeck: state.anki.selectedDeck
+ currentDeck: state.anki.selectedDeck,
+ modelList: state.anki.modelList,
}), {
createAnkiLanModel,
- checkAnkiLanModelForExisting
})(AnkiTemplate)
diff --git a/src/components/view/deck-picker.jsx b/src/components/view/deck-picker.jsx
index 9c06b58..fd2dca2 100644
--- a/src/components/view/deck-picker.jsx
+++ b/src/components/view/deck-picker.jsx
@@ -24,7 +24,7 @@ const DeckPicker = props => {
export default connect(state => ({
decks: state.anki.deckList,
- selectedDeck: state.anki.selectedDeck
+ selectedDeck: state.anki.selectedDeck,
}),{
getDeckList,
selectDeck,
diff --git a/src/constants/anki-constants.js b/src/constants/anki-constants.js
index 046d3e6..9e75ccd 100644
--- a/src/constants/anki-constants.js
+++ b/src/constants/anki-constants.js
@@ -14,6 +14,8 @@ export const SET_DECK = 'SET_DECK';
export const SET_WORD_DEFINITION = 'SET_DEFINITION';
export const SET_WORD_SOUND = 'SET_WORD_SOUND';
export const SET_WORD_TRANSLATE = 'SET_WORD_TRANSLATE';
+export const SET_ANKI_NOTE_CREATOR = 'SET_ANKI_NOTE_CREATOR';
+export const SET_CREATOR_TEMPLATE = 'SET_CREATOR_TEMPLATE';
//Anki ui actions
export const SHOW_FIELDS = 'SHOW_FIELDS';
// Anki check actions
diff --git a/src/reducers/anki-reducer.js b/src/reducers/anki-reducer.js
index 9a9969d..dbc815b 100644
--- a/src/reducers/anki-reducer.js
+++ b/src/reducers/anki-reducer.js
@@ -2,6 +2,8 @@ import {
GET_DECK_LIST,
GET_MODEL_LIST,
REQUEST_PERMISSIONS,
+ SET_ANKI_NOTE_CREATOR,
+ SET_CREATOR_TEMPLATE,
SET_DECK,
SET_EXISTING_OF_ANKI_LAN_MODEL,
} from '../constants/anki-constants';
@@ -18,7 +20,9 @@ const initialState = {
mainFieldIsAvailable: false,
fieldList: [],
ankiLanModelIsAlreadyExists: false,
- ankiLanModelName: 'AnkiLan_test',
+ ankiLanModelName: 'AnkiLan2',
+ noteCreator: {},
+ noteTemplate: [],
};
const ankiReducer = (state = initialState, action) => {
@@ -37,6 +41,10 @@ const ankiReducer = (state = initialState, action) => {
};
case SET_EXISTING_OF_ANKI_LAN_MODEL:
return {...state, ankiLanModelIsAlreadyExists: action.payload};
+ case SET_CREATOR_TEMPLATE:
+ return {...state, noteTemplate: action.payload};
+ case SET_ANKI_NOTE_CREATOR:
+ return {...state, noteCreator: action.payload};
default:
return state;
}