2020-03-08 11:17:42 +00:00
|
|
|
import {
|
|
|
|
SET_ANKI_NOTE_CREATOR,
|
|
|
|
SET_CREATOR_TEMPLATE,
|
|
|
|
SET_DECK,
|
2020-03-24 13:37:25 +00:00
|
|
|
SET_FIELDS,
|
2020-03-08 11:17:42 +00:00
|
|
|
} from '../constants/anki-constants';
|
2020-03-05 22:16:34 +00:00
|
|
|
|
|
|
|
export const selectDeck = id => ({
|
|
|
|
type: SET_DECK,
|
|
|
|
payload: id,
|
|
|
|
});
|
2020-03-08 11:17:42 +00:00
|
|
|
|
|
|
|
export const setAnkiNoteCreator = creator => ({
|
|
|
|
type: SET_ANKI_NOTE_CREATOR,
|
|
|
|
payload: creator,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const setCreatorTemplate = template => ({
|
|
|
|
type: SET_CREATOR_TEMPLATE,
|
|
|
|
payload: template,
|
|
|
|
});
|
2020-03-24 13:37:25 +00:00
|
|
|
|
|
|
|
const parseToAnkiFormat = dict => {
|
|
|
|
/*
|
|
|
|
*** TEMPLATE ***
|
|
|
|
const modelFields = [
|
|
|
|
'Word or sentence',
|
|
|
|
'Part of speech 1',
|
|
|
|
'Translation 1',
|
|
|
|
'Definition 1',
|
|
|
|
'Part of speech 2',
|
|
|
|
'Translation 2',
|
|
|
|
'Definition 2',
|
|
|
|
'Usage example',
|
|
|
|
'Transcription',
|
|
|
|
'Sound',
|
|
|
|
]
|
|
|
|
*/
|
|
|
|
|
|
|
|
const tr1 = dict.compounded[0];
|
|
|
|
const tr2 = dict.compounded[1] || {};
|
|
|
|
return [
|
|
|
|
dict.word,
|
|
|
|
tr1.pos,
|
|
|
|
tr1.tr,
|
|
|
|
tr1.definition,
|
|
|
|
tr2.pos || '',
|
|
|
|
tr2.tr || '',
|
|
|
|
tr2.definition || '',
|
|
|
|
`${tr1.example || ''} \n ${tr2.example || ''}`,
|
|
|
|
dict.pronunciation,
|
|
|
|
`[sound:${dict.sound}]`,
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const setFields = dict => ({
|
|
|
|
type: SET_FIELDS,
|
|
|
|
payload: parseToAnkiFormat(dict),
|
|
|
|
});
|