Skip to content

Commit 54565c2

Browse files
committed
get user id and space new file
1 parent 19caaec commit 54565c2

File tree

6 files changed

+259
-89
lines changed

6 files changed

+259
-89
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const init = require('./utils/init');
1111
const cli = require('./utils/cli');
1212
const log = require('./utils/log');
1313
const findSpace = require('./utils/find-space');
14+
const findSpaceByHost = require('./utils/find-space-by-host');
1415

1516
const input = cli.input;
1617
const flags = cli.flags;
@@ -20,10 +21,14 @@ const { clear, debug } = flags;
2021
init({ clear });
2122
input.includes(`help`) && cli.showHelp(0);
2223

24+
if (flags.username) {
25+
await findSpaceByHost({ username: flags.username })
26+
}
27+
2328
if (flags.live) {
24-
await findSpace({scheduled: false, live: true, query: flags.query});
29+
await findSpace({ scheduled: false, live: true, query: flags.query });
2530
} else if (flags.scheduled) {
26-
await findSpace({scheduled: true, live: false, query: flags.query});
31+
await findSpace({ scheduled: true, live: false, query: flags.query });
2732
}
2833

2934
debug && log(flags);

package-lock.json

Lines changed: 2 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@
3939
"cli-meow-help": "^2.0.2",
4040
"cli-spinner": "^0.2.10",
4141
"cli-welcome": "^2.2.2",
42-
"dotenv": "^10.0.0",
4342
"lodash.merge": "^4.6.2",
4443
"meow": "^9.0.0",
4544
"node-emoji": "^1.11.0"
4645
},
4746
"devDependencies": {
4847
"prettier": "^2.3.2"
4948
}
50-
}
49+
}

utils/cli.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ const flags = {
3737
query: {
3838
type: `string`,
3939
desc: `Search query`
40+
},
41+
host: {
42+
type: `string`,
43+
desc: `The host of the space`
4044
}
4145
};
4246

4347
const commands = {
44-
help: { desc: `Print help info` },
48+
help: { desc: `Print help info` }
4549
};
4650

4751
const helpText = meowHelp({

utils/find-space-by-host.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
const { dim, italic, bold, red, green } = require('chalk');
2+
const Spinner = require('cli-spinner').Spinner;
3+
const merge = require('lodash.merge');
4+
const emoji = require('node-emoji');
5+
const axios = require('axios');
6+
7+
module.exports = async ({ username }) => {
8+
9+
const userResponse = await axios.post(
10+
`https://tweespaces-serverless-function.vercel.app/api/space-by-user`,
11+
{
12+
username
13+
},
14+
{
15+
headers: {
16+
'Content-Type': 'application/json'
17+
}
18+
}
19+
);
20+
21+
console.group({ userResponse })
22+
23+
const data = userResponse.data.spaces.data;
24+
const meta = userResponse.data.spaces.meta;
25+
const includes = userResponse.data.spaces.includes;
26+
27+
const spinner = new Spinner(dim('Searching for spaces.....'));
28+
29+
spinner.start();
30+
31+
const hasResult = meta.result_count !== 0 ? true : false;
32+
33+
spinner.stop(true);
34+
35+
if (!hasResult) {
36+
return console.log(emoji.get('scream'), ' ', bold('No results found!'));
37+
}
38+
39+
const spaceInfo = data.map(
40+
({ participant_count, scheduled_start, title, creator_id }) => {
41+
return {
42+
creator_id,
43+
participants: participant_count,
44+
start: scheduled_start,
45+
title
46+
};
47+
}
48+
);
49+
50+
const creatorInfo = includes.users.map(
51+
({ name, username, description, id }) => {
52+
return {
53+
id,
54+
creatorHandle: username,
55+
creator: name,
56+
description
57+
};
58+
}
59+
);
60+
61+
const space = merge(spaceInfo, creatorInfo);
62+
63+
function twitterHandleLink(handle) {
64+
return `https://twitter.com/${handle}`;
65+
}
66+
space.map(({ title, creator, creatorHandle, start, description }) => {
67+
const timingCheck = () => {
68+
if (start === undefined) {
69+
return console.log(
70+
emoji.get('timer_clock'),
71+
' ',
72+
bold('Live now!')
73+
);
74+
}
75+
return console.log(
76+
emoji.get('timer_clock'),
77+
' ',
78+
bold('Time: ', new Date(start).toLocaleTimeString('en-US')),
79+
dim(italic(' (All times localized)')),
80+
emoji.get('sunglasses')
81+
);
82+
};
83+
84+
const dateCheck = () => {
85+
if (start === undefined) {
86+
return null;
87+
}
88+
return console.log(
89+
emoji.get('calendar'),
90+
' ',
91+
bold('Date: ', new Date(start).toLocaleDateString('en-US'))
92+
);
93+
};
94+
95+
console.log(
96+
red(
97+
bold(
98+
'-----------------------------------------------------------------------------'
99+
)
100+
)
101+
);
102+
console.log(red(bold('Space details')));
103+
console.log();
104+
console.log(emoji.get('rocket'), ' ', bold('Title: ', title));
105+
console.log();
106+
dateCheck();
107+
console.log();
108+
timingCheck();
109+
console.log(
110+
green(
111+
bold(
112+
'-----------------------------------------------------------------------------'
113+
)
114+
)
115+
);
116+
console.log(green(bold('Host details')));
117+
console.log();
118+
console.log(emoji.get('writing_hand'), ' ', bold('Name: ', creator));
119+
console.log();
120+
console.log(emoji.get('question'), ' ', bold('Bio: ', description));
121+
console.log();
122+
console.log(
123+
emoji.get('baby_chick'),
124+
' ',
125+
bold('Handle: ', twitterHandleLink(creatorHandle))
126+
);
127+
console.log(
128+
green(
129+
bold(
130+
'-----------------------------------------------------------------------------'
131+
)
132+
)
133+
);
134+
});
135+
}

0 commit comments

Comments
 (0)