diff --git a/src/actions/anki-edit-actions.js b/src/actions/anki-edit-actions.js new file mode 100644 index 0000000..e69de29 diff --git a/src/actions/anki-get-actions.js b/src/actions/anki-get-actions.js new file mode 100644 index 0000000..fca64a3 --- /dev/null +++ b/src/actions/anki-get-actions.js @@ -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}; +}; diff --git a/src/actions/anki-set-actions.js b/src/actions/anki-set-actions.js new file mode 100644 index 0000000..b65e170 --- /dev/null +++ b/src/actions/anki-set-actions.js @@ -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, +}); diff --git a/src/actions/anki-ui-actions.js b/src/actions/anki-ui-actions.js new file mode 100644 index 0000000..e69de29 diff --git a/src/components/start-screen.jsx b/src/components/start-screen.jsx new file mode 100644 index 0000000..3bae246 --- /dev/null +++ b/src/components/start-screen.jsx @@ -0,0 +1,8 @@ +import React from 'react'; +import {Container, Text} from 'native-base'; + +const StartScreen = props => { + return world , УХТЫ БЛЯ; +}; + +export default StartScreen; diff --git a/src/constants/anki-constants.js b/src/constants/anki-constants.js new file mode 100644 index 0000000..c89ead6 --- /dev/null +++ b/src/constants/anki-constants.js @@ -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'; diff --git a/src/reducers/anki-reducer.js b/src/reducers/anki-reducer.js new file mode 100644 index 0000000..9f9dc92 --- /dev/null +++ b/src/reducers/anki-reducer.js @@ -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; diff --git a/src/reducers/api-reducer.js b/src/reducers/api-reducer.js new file mode 100644 index 0000000..f57ae92 --- /dev/null +++ b/src/reducers/api-reducer.js @@ -0,0 +1,9 @@ +const initialState = {}; + +const apiReducer = (state = initialState, action) => { + switch (action.type) { + default: + return state; + } +}; +export default apiReducer; diff --git a/src/reducers/main-reducer.js b/src/reducers/main-reducer.js new file mode 100644 index 0000000..20d38e8 --- /dev/null +++ b/src/reducers/main-reducer.js @@ -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; diff --git a/src/store.js b/src/store.js new file mode 100644 index 0000000..12083eb --- /dev/null +++ b/src/store.js @@ -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;