Ankilan/src/actions/anki-set-actions.js

63 lines
1.2 KiB
JavaScript

import {
SET_ANKI_NOTE_CREATOR,
SET_CREATOR_TEMPLATE,
SET_DECK,
SET_FIELDS,
SET_GLOBAL_DEF,
} from '../constants/anki-constants';
export const selectDeck = id => ({
type: SET_DECK,
payload: id,
});
export const setAnkiNoteCreator = creator => ({
type: SET_ANKI_NOTE_CREATOR,
payload: creator,
});
export const setCreatorTemplate = template => ({
type: SET_CREATOR_TEMPLATE,
payload: template,
});
const parseToAnkiFormat = dict => {
console.log('SDFfasdfsadf', 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.example,
dict.pronunciation,
`[sound:${dict.sound}]`,
];
};
export const setFields = dict => ({
type: SET_FIELDS,
payload: parseToAnkiFormat(dict),
});