Dev #3
|
@ -179,6 +179,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation project(':@react-native-community_async-storage')
|
||||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||||
implementation "com.facebook.react:react-native:+" // From node_modules
|
implementation "com.facebook.react:react-native:+" // From node_modules
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import com.facebook.react.PackageList;
|
import com.facebook.react.PackageList;
|
||||||
import com.facebook.react.ReactApplication;
|
import com.facebook.react.ReactApplication;
|
||||||
|
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
|
||||||
import com.facebook.react.ReactNativeHost;
|
import com.facebook.react.ReactNativeHost;
|
||||||
import com.facebook.react.ReactPackage;
|
import com.facebook.react.ReactPackage;
|
||||||
import com.facebook.soloader.SoLoader;
|
import com.facebook.soloader.SoLoader;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
rootProject.name = 'ankilan'
|
rootProject.name = 'ankilan'
|
||||||
|
include ':@react-native-community_async-storage'
|
||||||
|
project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android')
|
||||||
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
|
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
|
||||||
include ':app'
|
include ':app'
|
||||||
|
|
|
@ -34,6 +34,8 @@ target 'ankilan' do
|
||||||
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
|
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
|
||||||
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
|
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
|
||||||
|
|
||||||
|
pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
|
||||||
|
|
||||||
target 'ankilanTests' do
|
target 'ankilanTests' do
|
||||||
inherit! :search_paths
|
inherit! :search_paths
|
||||||
# Pods for testing
|
# Pods for testing
|
||||||
|
|
|
@ -1,5 +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 {
|
import {
|
||||||
checkAnkiLanModelForExisting,
|
checkAnkiLanModelForExisting,
|
||||||
getFieldList,
|
getFieldList,
|
||||||
|
@ -171,6 +172,10 @@ export const createAnkiLanModel = model => async dispatch => {
|
||||||
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));
|
||||||
|
sendDataToLocaleStorage(
|
||||||
|
setAnkiNoteCreator(selectedDeck), //send creator to locale storage
|
||||||
|
setCreatorTemplate(modelFields),
|
||||||
|
);
|
||||||
addNote(selectedDeck, valueFields, modelFields);
|
addNote(selectedDeck, valueFields, modelFields);
|
||||||
checkAnkiLanModelForExisting(model.name, model.list);
|
checkAnkiLanModelForExisting(model.name, model.list);
|
||||||
await dispatch(getModelList());
|
await dispatch(getModelList());
|
||||||
|
@ -180,6 +185,7 @@ export const createAnkiLanModel = model => async dispatch => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//creator is an object what have to store in locale storage.
|
||||||
export const addNote = (creator, words, template) => {
|
export const addNote = (creator, words, template) => {
|
||||||
creator.addNote(words, template);
|
creator.addNote(words, template);
|
||||||
};
|
};
|
||||||
|
|
40
src/actions/filesystem.js
Normal file
40
src/actions/filesystem.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import AsyncStorage from '@react-native-community/async-storage';
|
||||||
|
import {
|
||||||
|
ANKILAN_NOTE_CREATOR,
|
||||||
|
ANKILAN_NOTE_TEMPLATE,
|
||||||
|
} from '../constants/anki-constants';
|
||||||
|
const sendDataToLocaleStorage = async (creator, template) => {
|
||||||
|
try {
|
||||||
|
await AsyncStorage.setItem(ANKILAN_NOTE_CREATOR, JSON.stringify(creator));
|
||||||
|
await AsyncStorage.setItem(ANKILAN_NOTE_TEMPLATE, JSON.stringify(template));
|
||||||
|
} catch (e) {
|
||||||
|
// saving error
|
||||||
|
alert('Error while syncing with filesystem');
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export default sendDataToLocaleStorage;
|
||||||
|
|
||||||
|
export const getTemplate = async () => {
|
||||||
|
try {
|
||||||
|
const value = await AsyncStorage.getItem(ANKILAN_NOTE_TEMPLATE);
|
||||||
|
if (value !== null) {
|
||||||
|
// value previously stored
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// error reading value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCreator = async () => {
|
||||||
|
try {
|
||||||
|
const value = await AsyncStorage.getItem(ANKILAN_NOTE_TEMPLATE);
|
||||||
|
if (value !== null) {
|
||||||
|
// value previously stored
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// error reading value
|
||||||
|
}
|
||||||
|
};
|
|
@ -22,3 +22,7 @@ export const SET_FIELDS = 'SET_FIELDS';
|
||||||
export const SHOW_FIELDS = 'SHOW_FIELDS';
|
export const SHOW_FIELDS = 'SHOW_FIELDS';
|
||||||
// Anki check actions
|
// Anki check actions
|
||||||
export const SET_EXISTING_OF_ANKI_LAN_MODEL = 'SET_EXISTING_OF_ANKI_LAN_MODEL';
|
export const SET_EXISTING_OF_ANKI_LAN_MODEL = 'SET_EXISTING_OF_ANKI_LAN_MODEL';
|
||||||
|
|
||||||
|
//rn-async-storage kesy
|
||||||
|
export const ANKILAN_NOTE_CREATOR = '@ANKILAN_NOTE_CREATOR';
|
||||||
|
export const ANKILAN_NOTE_TEMPLATE = '@ANKILAN_NOTE_TEMPLATE';
|
||||||
|
|
|
@ -20,7 +20,7 @@ const initialState = {
|
||||||
mainFieldIsAvailable: false,
|
mainFieldIsAvailable: false,
|
||||||
fieldList: [],
|
fieldList: [],
|
||||||
ankiLanModelIsAlreadyExists: false,
|
ankiLanModelIsAlreadyExists: false,
|
||||||
ankiLanModelName: 'AnkiLan_final',
|
ankiLanModelName: 'AnkiLan_final1',
|
||||||
noteCreator: {},
|
noteCreator: {},
|
||||||
noteTemplate: [],
|
noteTemplate: [],
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue