-
Notifications
You must be signed in to change notification settings - Fork 0
/
gallery.js
90 lines (87 loc) · 2.49 KB
/
gallery.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const inquirer = require('inquirer');
const auth = require('./utils/auth-utils');
const {
galleryPrompt,
welcomePrompt,
deletePrompt,
loginPrompt,
userPrompt,
exitPrompt,
} = require('./prompts');
const {
deleteADrawing,
getAllImages,
getRandomImage,
getUserDrawings,
logUserIn,
} = require('./utils/gallery-utils');
module.exports = () => {
const stARTupSkeleton = (newPrompt) => {
return inquirer
.prompt({
type: newPrompt.type,
message: newPrompt.message,
name: newPrompt.name,
choices: newPrompt.choices,
})
.then((response) => {
switch (response.option) {
case 'Log in to edit my drawings':
logInSkeleton();
break;
case 'Show me the art!':
stARTupSkeleton(galleryPrompt);
break;
case 'Exit':
console.log('See you later!');
break;
case 'View your drawings':
getUserDrawings().then(() => stARTupSkeleton(galleryPrompt));
break;
case 'View all drawings':
getAllImages().then(() => stARTupSkeleton(galleryPrompt));
break;
case 'View image carousel':
getRandomImage().then(() => exitSkeleton());
break;
case 'View my drawings':
getUserDrawings(userToken).then(() => stARTupSkeleton(userPrompt));
break;
case 'Delete a drawing by its ID':
deleteSkeleton(userToken);
break;
case 'Go back to main menu':
stARTupSkeleton(welcomePrompt);
}
});
};
let userToken;
const logInSkeleton = () => {
inquirer.prompt(loginPrompt).then((response) => {
if (response.githubAuth === true) {
auth().then((token) => {
logUserIn(token), stARTupSkeleton(userPrompt), (userToken = token);
});
} else {
console.log('Please create a github account to log in to stARTup');
}
});
};
const deleteSkeleton = (userToken) => {
inquirer.prompt(deletePrompt).then((response) => {
deleteADrawing(response.deleteIt, userToken),
console.log('DELETED FOREVER'),
stARTupSkeleton(userPrompt);
});
};
const exitSkeleton = () => {
inquirer.prompt(exitPrompt).then((response) => {
if (response.exit === true) {
getRandomImage().then(() => exitSkeleton());
} else {
stARTupSkeleton(galleryPrompt);
}
});
};
stARTupSkeleton(welcomePrompt);
};