ability of sending anki data to local storage
This commit is contained in:
parent
189dcb9e4a
commit
0962aa31b5
|
@ -105,8 +105,10 @@ export const checkAnkiLanModelForExisting = (
|
||||||
modelList,
|
modelList,
|
||||||
) => async dispatch => {
|
) => async dispatch => {
|
||||||
try {
|
try {
|
||||||
|
let id = 0;
|
||||||
for (let model of modelList) {
|
for (let model of modelList) {
|
||||||
if (model.name === name) {
|
if (model.name === name) {
|
||||||
|
id = model.id;
|
||||||
await dispatch(setExistingOfAnkiLanModel(true));
|
await dispatch(setExistingOfAnkiLanModel(true));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -118,3 +120,16 @@ export const checkAnkiLanModelForExisting = (
|
||||||
await dispatch(setExistingOfAnkiLanModel(false));
|
await dispatch(setExistingOfAnkiLanModel(false));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getModelId = (models, name) => {
|
||||||
|
console.log(models, name);
|
||||||
|
let id = '';
|
||||||
|
models.forEach(model => {
|
||||||
|
if (model.name === name) {
|
||||||
|
console.log('id', model.id);
|
||||||
|
id = model.id;
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return id;
|
||||||
|
};
|
||||||
|
|
|
@ -14,6 +14,9 @@ import {
|
||||||
import {createDictionary} from '../dictionary/create-dictionary';
|
import {createDictionary} from '../dictionary/create-dictionary';
|
||||||
import {setFields} from '../anki-set-actions';
|
import {setFields} from '../anki-set-actions';
|
||||||
import {sendWord, submit} from '../form-actions';
|
import {sendWord, submit} from '../form-actions';
|
||||||
|
import store from '../../store';
|
||||||
|
import {getModelId} from '../anki-get-actions';
|
||||||
|
import {AnkiDroid} from 'react-native-ankidroid/dist/ankidroid';
|
||||||
|
|
||||||
const getAvailableApi = (apiArray = []) => {
|
const getAvailableApi = (apiArray = []) => {
|
||||||
for (const api of apiArray) {
|
for (const api of apiArray) {
|
||||||
|
@ -52,6 +55,7 @@ export const wordInfo = word => async dispatch => {
|
||||||
dispatch(setDictioanry(wordDictionary));
|
dispatch(setDictioanry(wordDictionary));
|
||||||
/* TODO: move sendWord to submit function */
|
/* TODO: move sendWord to submit function */
|
||||||
// sendWord(setFields(wordDictionary));
|
// sendWord(setFields(wordDictionary));
|
||||||
|
drawFields();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 sendDataToLocaleStorage from './filesystem';
|
import sendDataToLocaleStorage, {getAnkiData} from './filesystem';
|
||||||
import setSettings, {
|
import setSettings, {
|
||||||
modelFields,
|
modelFields,
|
||||||
valueFields,
|
valueFields,
|
||||||
|
@ -8,6 +8,7 @@ import setSettings, {
|
||||||
import {
|
import {
|
||||||
checkAnkiLanModelForExisting,
|
checkAnkiLanModelForExisting,
|
||||||
getFieldList,
|
getFieldList,
|
||||||
|
getModelId,
|
||||||
getModelList,
|
getModelList,
|
||||||
} from './anki-get-actions';
|
} from './anki-get-actions';
|
||||||
|
|
||||||
|
@ -16,15 +17,15 @@ import store from '../store';
|
||||||
export const createAnkiLanModel = model => async dispatch => {
|
export const createAnkiLanModel = model => async dispatch => {
|
||||||
try {
|
try {
|
||||||
const settings = setSettings(model);
|
const settings = setSettings(model);
|
||||||
|
|
||||||
const selectedDeck = new AnkiDroid(settings);
|
const selectedDeck = new AnkiDroid(settings);
|
||||||
await dispatch(setAnkiNoteCreator(selectedDeck));
|
await dispatch(setAnkiNoteCreator(selectedDeck));
|
||||||
await dispatch(setCreatorTemplate(modelFields));
|
await dispatch(setCreatorTemplate(modelFields));
|
||||||
// const sd = JSON.parse(JSON.stringify(selectedDeck));
|
// const sd = JSON.parse(JSON.stringify(selectedDeck));
|
||||||
// console.log(sd === selectedDeck);
|
// console.log(sd === selectedDeck);
|
||||||
// ****************
|
// ****************
|
||||||
alert('oh shit');
|
|
||||||
addNote(selectedDeck, valueFields, modelFields);
|
firstNote(selectedDeck, valueFields, modelFields);
|
||||||
|
|
||||||
// ****************
|
// ****************
|
||||||
// sendDataToLocaleStorage(
|
// sendDataToLocaleStorage(
|
||||||
// setAnkiNoteCreator(sd), //send creator to locale storage
|
// setAnkiNoteCreator(sd), //send creator to locale storage
|
||||||
|
@ -32,19 +33,31 @@ export const createAnkiLanModel = model => async dispatch => {
|
||||||
// );
|
// );
|
||||||
checkAnkiLanModelForExisting(model.name, model.list);
|
checkAnkiLanModelForExisting(model.name, model.list);
|
||||||
await dispatch(getModelList());
|
await dispatch(getModelList());
|
||||||
await dispatch(getFieldList(model.name));
|
const [err, modelList] = await AnkiDroid.getModelList();
|
||||||
|
const modelId = await getModelId(modelList, model.name);
|
||||||
|
await console.log(modelId);
|
||||||
|
const [, fieldList] = await AnkiDroid.getFieldList(model.name);
|
||||||
|
|
||||||
|
sendDataToLocaleStorage({
|
||||||
|
fieldList,
|
||||||
|
modelName: model.name,
|
||||||
|
modelId,
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log('irror is ghere', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const firstNote = (creator, fields, template) =>
|
||||||
|
creator.addNote(fields, template);
|
||||||
//creator is an object what have to store in locale storage.
|
//creator is an object what have to store in locale storage.
|
||||||
export const addNote = words => {
|
export const addNote = async words => {
|
||||||
const template = store.getState().anki.noteTemplate;
|
const template = store.getState().anki.noteTemplate;
|
||||||
const deckId = store.getState().anki.selectedDeck.id;
|
const deckId = store.getState().anki.selectedDeck.id;
|
||||||
|
const modelId = await getAnkiData().modelId;
|
||||||
const settings = {
|
const settings = {
|
||||||
deckId,
|
deckId,
|
||||||
modelId: '1585139654585',
|
modelId,
|
||||||
};
|
};
|
||||||
const creator = new AnkiDroid(settings);
|
const creator = new AnkiDroid(settings);
|
||||||
|
|
||||||
|
|
|
@ -1,48 +1,33 @@
|
||||||
import AsyncStorage from '@react-native-community/async-storage';
|
import AsyncStorage from '@react-native-community/async-storage';
|
||||||
import {
|
import {
|
||||||
|
ANKILAN_DATA,
|
||||||
ANKILAN_NOTE_CREATOR,
|
ANKILAN_NOTE_CREATOR,
|
||||||
ANKILAN_NOTE_TEMPLATE,
|
ANKILAN_NOTE_TEMPLATE,
|
||||||
} from '../constants/anki-constants';
|
} from '../constants/anki-constants';
|
||||||
import JSONfn from 'jsonfn';
|
import JSONfn from 'jsonfn';
|
||||||
|
|
||||||
const sendDataToLocaleStorage = async (creator, template) => {
|
const sendDataToLocaleStorage = async data => {
|
||||||
try {
|
try {
|
||||||
await AsyncStorage.clear();
|
await AsyncStorage.clear();
|
||||||
|
await AsyncStorage.setItem(ANKILAN_DATA, JSONfn.stringify(data));
|
||||||
await AsyncStorage.setItem(ANKILAN_NOTE_CREATOR, JSONfn.stringify(creator));
|
console.log(data);
|
||||||
await AsyncStorage.setItem(
|
|
||||||
ANKILAN_NOTE_TEMPLATE,
|
|
||||||
JSONfn.stringify(template),
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// saving error
|
// saving error
|
||||||
alert('Error while syncing with filesystem');
|
alert('Error while syncing with filesystem');
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAnkiData = async () => {
|
||||||
|
try {
|
||||||
|
const value = await AsyncStorage.getItem(ANKILAN_DATA);
|
||||||
|
if (value !== null) {
|
||||||
|
// value previously stored
|
||||||
|
return JSONfn.parse(value);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// error reading value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export default sendDataToLocaleStorage;
|
export default sendDataToLocaleStorage;
|
||||||
|
|
||||||
export const getTemplate = async () => {
|
|
||||||
try {
|
|
||||||
const value = await AsyncStorage.getItem(ANKILAN_NOTE_TEMPLATE);
|
|
||||||
console.log(value);
|
|
||||||
if (value !== null) {
|
|
||||||
// value previously stored
|
|
||||||
return JSONfn.parse(value);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// error reading value
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getCreator = async () => {
|
|
||||||
try {
|
|
||||||
const value = await AsyncStorage.getItem(ANKILAN_NOTE_CREATOR);
|
|
||||||
if (value !== null) {
|
|
||||||
// value previously stored
|
|
||||||
return JSONfn.parse(value);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// error reading value
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
2
src/actions/user-interface/draw-fields.js
Normal file
2
src/actions/user-interface/draw-fields.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
const drawFields = () => {};
|
||||||
|
export default drawFields;
|
|
@ -9,6 +9,7 @@ import {wordInfo} from "../actions/api/dictionary";
|
||||||
|
|
||||||
const AnkiForm = props => {
|
const AnkiForm = props => {
|
||||||
const [target, setTarget] = useState('')
|
const [target, setTarget] = useState('')
|
||||||
|
const [fields, setFields] = useState({})
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// props.wordInfo('Urge');
|
// props.wordInfo('Urge');
|
||||||
// props.wordInfo('Maze');
|
// props.wordInfo('Maze');
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {Button, Text} from 'native-base';
|
||||||
const SubmitButton = props => {
|
const SubmitButton = props => {
|
||||||
return (
|
return (
|
||||||
<Button onPress={props.onSubmit}>
|
<Button onPress={props.onSubmit}>
|
||||||
<Text>Submit</Text>
|
<Text>Send</Text>
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,3 +26,4 @@ export const SET_EXISTING_OF_ANKI_LAN_MODEL = 'SET_EXISTING_OF_ANKI_LAN_MODEL';
|
||||||
//rn-async-storage kesy
|
//rn-async-storage kesy
|
||||||
export const ANKILAN_NOTE_CREATOR = '@ANKILAN_NOTE_CREATOR';
|
export const ANKILAN_NOTE_CREATOR = '@ANKILAN_NOTE_CREATOR';
|
||||||
export const ANKILAN_NOTE_TEMPLATE = '@ANKILAN_NOTE_TEMPLATE';
|
export const ANKILAN_NOTE_TEMPLATE = '@ANKILAN_NOTE_TEMPLATE';
|
||||||
|
export const ANKILAN_DATA = 'ANKILAN_DATA';
|
||||||
|
|
|
@ -20,7 +20,7 @@ const initialState = {
|
||||||
mainFieldIsAvailable: false,
|
mainFieldIsAvailable: false,
|
||||||
fieldList: [],
|
fieldList: [],
|
||||||
ankiLanModelIsAlreadyExists: false,
|
ankiLanModelIsAlreadyExists: false,
|
||||||
ankiLanModelName: '1AnkiLan1111',
|
ankiLanModelName: 'develop_final',
|
||||||
noteCreator: {},
|
noteCreator: {},
|
||||||
noteTemplate: [],
|
noteTemplate: [],
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue