-
Notifications
You must be signed in to change notification settings - Fork 4
/
actions.js
53 lines (40 loc) · 1.43 KB
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { prompt } = require('./lib/utils');
const promptly = require('promptly');
const chalk = require('chalk');
exports.recall = async function({ spacedTime }) {
const qna = spacedTime.getSingleQuestion();
if (!qna)
return console.log(
chalk.yellow(
'No questions to be recalled at this time. Try again later.'
),
'\n'
);
console.log(chalk.bold(qna.question, '\n'));
await prompt(chalk.yellow('Press any key to reveal the answer', '\n'));
console.log(chalk.bold(qna.answer, '\n'));
const remembered = await promptly.choose(
chalk.yellow('Did you remember successfully? yes(y) or no(n)'),
['y', 'n']
);
spacedTime.recallAnswer(qna, remembered === 'y');
};
exports.add = async function({ spacedTime }, question, answer) {
const qna = spacedTime.createQNA(question, answer);
console.log(chalk.yellow('added'), chalk.yellow(qna.question));
};
exports.list = async function({ spacedTime }) {
const list = spacedTime.list();
console.table(list);
};
exports.remove = async function({ spacedTime }, index) {
const question = spacedTime.data[index];
spacedTime.remove(index);
console.log(chalk.yellow('removed', question.question));
};
exports.update = async function({ spacedTime }, index, { question, answer }) {
const q = spacedTime.data[index];
const updated = spacedTime.update(index, question, answer);
console.log(chalk.yellow('updated to'));
console.table(updated)
};