Skip to content

Commit da67f70

Browse files
committed
🔨 Switch CLI to use useOvermind
1 parent 3903655 commit da67f70

File tree

4 files changed

+35
-44
lines changed

4 files changed

+35
-44
lines changed

‎packages/app/src/app/pages/CLI/Prompt/elements.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const Buttons = styled.div`
1616
}
1717
`;
1818

19-
export const TokenContainer = styled.input`
19+
export const TokenInput = styled.input`
2020
color: white;
2121
2222
width: 100%;
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
import React from 'react';
21
import { Button } from '@codesandbox/common/lib/components/Button';
3-
import { Title } from 'app/components/Title';
2+
import React, { FunctionComponent, useRef } from 'react';
3+
44
import { SubTitle } from 'app/components/SubTitle';
5-
import { Container, Buttons, TokenContainer } from './elements';
5+
import { Title } from 'app/components/Title';
6+
import { useOvermind } from 'app/overmind';
67

7-
interface IPromptProps {
8-
error: string;
9-
token: string;
10-
loading: boolean;
11-
username: string;
12-
signIn: () => void;
13-
}
8+
import { Buttons, Container, TokenInput } from './elements';
149

15-
const select = ({ target }: { target: any }) => target.select();
10+
export const Prompt: FunctionComponent = () => {
11+
const {
12+
actions: { signInCliClicked },
13+
state: { authToken, error, isLoadingCLI, user },
14+
} = useOvermind();
15+
const tokenInputRef = useRef<HTMLInputElement>(null);
1616

17-
export const Prompt: React.FC<IPromptProps> = ({
18-
error,
19-
token,
20-
loading,
21-
username,
22-
signIn,
23-
}) => {
2417
if (error) {
2518
return (
2619
<Container>
@@ -35,7 +28,7 @@ export const Prompt: React.FC<IPromptProps> = ({
3528
);
3629
}
3730

38-
if (!username) {
31+
if (!user?.username) {
3932
return (
4033
<Container>
4134
<Title>Welcome to CodeSandbox!</Title>
@@ -45,13 +38,15 @@ export const Prompt: React.FC<IPromptProps> = ({
4538
</SubTitle>
4639

4740
<Buttons>
48-
<Button onClick={signIn}>Sign in with GitHub</Button>
41+
<Button onClick={() => signInCliClicked()}>
42+
Sign in with GitHub
43+
</Button>
4944
</Buttons>
5045
</Container>
5146
);
5247
}
5348

54-
if (loading) {
49+
if (isLoadingCLI) {
5550
return (
5651
<Container>
5752
<Title>Fetching authorization key...</Title>
@@ -61,15 +56,19 @@ export const Prompt: React.FC<IPromptProps> = ({
6156

6257
return (
6358
<Container>
64-
<Title>Hello {username}!</Title>
59+
<Title>Hello {user.username}!</Title>
6560

6661
<SubTitle>
6762
The CLI needs authorization to work.
6863
<br />
6964
Please paste the following code in the CLI:
7065
</SubTitle>
7166

72-
<TokenContainer onClick={select} value={token} />
67+
<TokenInput
68+
onClick={() => tokenInputRef.current.select()}
69+
ref={tokenInputRef}
70+
value={authToken}
71+
/>
7372
</Container>
7473
);
7574
};
Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import React, { useEffect } from 'react';
2-
import { Navigation } from 'app/pages/common/Navigation';
1+
import React, { FunctionComponent, useEffect } from 'react';
2+
33
import { useOvermind } from 'app/overmind';
4+
import { Navigation } from 'app/pages/common/Navigation';
5+
46
import { Container } from './elements';
57
import { Prompt } from './Prompt';
68

7-
interface CliProps {
8-
small: boolean;
9-
}
10-
11-
const CLI: React.FunctionComponent<CliProps> = ({ small }) => {
9+
export const CLI: FunctionComponent = () => {
1210
const {
13-
state: { user, authToken, isLoadingCLI, error },
14-
actions: { cliMounted, signInCliClicked },
11+
actions: { cliMounted },
1512
} = useOvermind();
1613

1714
useEffect(() => {
@@ -22,16 +19,7 @@ const CLI: React.FunctionComponent<CliProps> = ({ small }) => {
2219
<Container>
2320
<Navigation title="CLI Authorization" />
2421

25-
<Prompt
26-
error={error}
27-
loading={isLoadingCLI}
28-
signIn={signInCliClicked}
29-
token={authToken}
30-
username={user && user.username}
31-
/>
22+
<Prompt />
3223
</Container>
3324
);
3425
};
35-
36-
// eslint-disable-next-line import/no-default-export
37-
export default CLI;

‎packages/app/src/app/pages/index.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ const Search = Loadable(() =>
4747
default: module.Search,
4848
}))
4949
);
50-
const CLI = Loadable(() => import(/* webpackChunkName: 'page-cli' */ './CLI'));
50+
const CLI = Loadable(() =>
51+
import(/* webpackChunkName: 'page-cli' */ './CLI').then(module => ({
52+
default: module.CLI,
53+
}))
54+
);
5155

5256
const GitHub = Loadable(() =>
5357
import(/* webpackChunkName: 'page-github' */ './GitHub').then(module => ({

0 commit comments

Comments
 (0)