This commit is contained in:
horhik 2020-03-05 17:16:34 -05:00
parent 6113911f41
commit e3b736a60d
10 changed files with 123 additions and 0 deletions

View file

View file

@ -0,0 +1,46 @@
import {AnkiDroid} from 'react-native-ankidroid/dist/ankidroid';
import {
CHECK_ANKI_ACCESS,
ERROR,
GET_DECK_LIST,
GET_FIELD_LIST,
GET_MODEL_LIST,
REQUEST_PERMISSIONS,
} from '../constants/anki-constants';
export const requestAnkiPermissions = async (
ankiProvider = AnkiDroid.requestPermission,
) => {
const [err, res] = await ankiProvider();
const permission = res === 'granted';
return err ? {type: ERROR, err} : {type: REQUEST_PERMISSIONS, permission};
};
export const checkAnkiAccess = async (
ankiApiProvider = AnkiDroid.isApiAvailable,
) => {
const [err, res] = await ankiApiProvider();
return err ? {type: ERROR, err} : {type: CHECK_ANKI_ACCESS, payload: res};
};
export const getDeckList = async (
getDeckListFunction = AnkiDroid.getDeckList,
) => {
const [err, res] = await getDeckListFunction();
return err ? {type: ERROR, err} : {type: GET_DECK_LIST, payload: res};
};
export const getModelList = async (
getModelListFunction = AnkiDroid.getModelList,
) => {
const [err, res] = await getModelListFunction();
return err ? {type: ERROR, err} : {type: GET_MODEL_LIST, payload: res};
};
export const getFieldList = async (
id,
getFieldListFunction = AnkiDroid.getFieldList,
) => {
const [err, res] = await getFieldListFunction(id);
return err ? {type: ERROR, err} : {type: GET_FIELD_LIST, payload: res};
};

View file

@ -0,0 +1,7 @@
import {AnkiDroid} from 'react-native-ankidroid/dist/ankidroid';
import {SET_DECK} from '../constants/anki-constants';
export const selectDeck = id => ({
type: SET_DECK,
payload: id,
});

View file

View file

@ -0,0 +1,8 @@
import React from 'react';
import {Container, Text} from 'native-base';
const StartScreen = props => {
return <Text>world , УХТЫ БЛЯ</Text>;
};
export default StartScreen;

View file

@ -0,0 +1,18 @@
//export const ct = 'ct';
//Anki edit actions
export const ERROR = 'ERROR';
export const CREATE_MODEL = 'CREATE_MODEL';
export const EDIT_INPUT_WORD = 'EDIT_INPUT_WORD';
//Anki get actions
export const REQUEST_PERMISSIONS = 'REQUEST_PERMISSIONS';
export const CHECK_ANKI_ACCESS = 'CHECK_ANKI_ACCESS';
export const GET_DECK_LIST = 'GET_DECK_LIST';
export const GET_MODEL_LIST = 'GET_MODEL_LIST';
export const GET_FIELD_LIST = 'GET_FIELD_LIST';
//Anki set actions
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';
//Anki ui actions
export const SHOW_FIELDS = 'SHOW_FIELDS';

View file

@ -0,0 +1,15 @@
const initialState = {
isApiAvailable: false,
isAnkiConnected: false,
deckList: [],
mainFieldIsAvailable: false,
fieldList: [],
};
const ankiReducer = (state = initialState, action) => {
switch (action.type) {
default:
return state;
}
};
export default ankiReducer;

View file

@ -0,0 +1,9 @@
const initialState = {};
const apiReducer = (state = initialState, action) => {
switch (action.type) {
default:
return state;
}
};
export default apiReducer;

View file

@ -0,0 +1,10 @@
import {combineReducers} from 'redux';
import ankiReducer from './anki-reducer';
import apiReducer from './api-reducer';
const mainReducer = combineReducers({
ankiReducer,
apiReducer,
});
export default mainReducer;

10
src/store.js Normal file
View file

@ -0,0 +1,10 @@
import {createStore, applyMiddleware} from 'redux';
import {composeWithDevTools} from 'redux-devtools-extension';
import mainReducer from './reducers/main-reducer'; //your reducer
const composeEnhancers = composeWithDevTools({realtime: true, port: 8081}); //possible to run without arguments
const store = createStore(
mainReducer,
/* preloadedState, */ composeEnhancers(/*connect of middelwares*/),
);
export default store;