-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
50 lines (41 loc) · 1.02 KB
/
ui.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
"use strict";
const React = require("react");
const importJsx = require("import-jsx");
const { Text } = require("ink");
const axios = require("./src/axios");
const getHeaders = require("./src/utils/get-headers");
const App = importJsx("./src/app");
const Login = importJsx("./src/components/login");
const { useState, useEffect } = React;
const UI = () => {
const [loading, setLoading] = useState(true);
const [profile, setProfile] = useState();
const getProfile = async () => {
const headers = await getHeaders();
axios
.get("/profile", { headers })
.then((result) => {
setProfile(result.data);
setLoading(false);
})
.catch((e) => {
setLoading(false);
});
};
useEffect(() => {
getProfile();
}, []);
const handleLoginSuccessful = (tokens) => {
getProfile(tokens);
};
return (
<>
{loading && <Text>Loading...</Text>}
{profile && <App profile={profile} />}
{!loading && !profile && (
<Login loginSuccessful={handleLoginSuccessful} />
)}
</>
);
};
module.exports = UI;