Skip to content

Commit d598080

Browse files
committed
Merge branch 'master' into prototype-common-sync
2 parents a2ec6d9 + 3fd001f commit d598080

File tree

43 files changed

+340
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+340
-347
lines changed

packages/app/src/app/components/CreateNewSandbox/CreateSandbox/Create/Create.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const Create = () => {
4444
<LinkButton onClick={actions.signInGithubClicked}>
4545
Sign in
4646
</LinkButton>{' '}
47-
to create templates or bookmark templates for later use.
47+
to create and bookmark templates for later use.
4848
</div>
4949
</CenteredMessage>
5050
)}

packages/app/src/app/components/CreateNewSandbox/CreateSandbox/Create/PersonalTemplates/PersonalTemplates.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,25 @@ export const PersonalTemplates = ({
9797
data.me.templates.length === 0 &&
9898
data.me.bookmarkedTemplates.length === 0;
9999

100-
if (hasNoTemplates) {
101-
return (
102-
<CenteredMessage>
103-
You don{"'"}t have any templates yet, go on and create or bookmark some!
104-
</CenteredMessage>
105-
);
106-
}
107-
108100
return filter ? (
109101
<FilteredTemplates
110102
forkOnOpen
111103
query={filter}
112104
templateInfos={allTemplateInfos}
113105
/>
114106
) : (
115-
<DynamicWidthTemplateList
116-
showSecondaryShortcuts
117-
forkOnOpen
118-
templateInfos={allTemplateInfos}
119-
/>
107+
<>
108+
{hasNoTemplates && (
109+
<CenteredMessage>
110+
You don{"'"}t have any templates yet, go on and create or bookmark
111+
some!
112+
</CenteredMessage>
113+
)}
114+
<DynamicWidthTemplateList
115+
showSecondaryShortcuts
116+
forkOnOpen
117+
templateInfos={allTemplateInfos}
118+
/>
119+
</>
120120
);
121121
};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import styled from 'styled-components';
21
import delayEffect from '@codesandbox/common/lib/utils/animation/delay-effect';
2+
import styled from 'styled-components';
33

4-
export const DelayedAnimation = styled.div<{ delay: number }>`
5-
${({ delay }) => delayEffect(delay || 0)};
4+
export const DelayedAnimation = styled.div<{ delay?: number }>`
5+
${({ delay = 0 }) => delayEffect(delay)};
66
`;

packages/app/src/app/overmind/effects/vscode/extensionHostWorker/common/fs.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ export async function initializeBrowserFS({
117117
}
118118

119119
if (syncSandbox) {
120+
// Resolve after 3s, if it doesn't resolve, vscode won't be able to resolve the ext host
121+
// and it won't try to reconnect.
122+
const timeout = setTimeout(() => {
123+
resolve();
124+
}, 3000);
125+
126+
const callResolve = () => {
127+
clearTimeout(timeout);
128+
resolve();
129+
};
130+
120131
self.addEventListener('message', evt => {
121132
// Some messages are specific to this worker
122133
if (!evt.data.$fs_ids || !evt.data.$fs_ids.includes(fsId)) {
@@ -142,7 +153,7 @@ export async function initializeBrowserFS({
142153
touchFileSystem();
143154
if (isInitialSync) {
144155
isInitialSync = false;
145-
resolve();
156+
callResolve();
146157
}
147158
break;
148159
}
@@ -170,7 +181,7 @@ export async function initializeBrowserFS({
170181
$data: {},
171182
});
172183
} else {
173-
resolve();
184+
callResolve();
174185
}
175186
break;
176187
}

packages/app/src/app/overmind/internalActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export const onApiError: Action<ApiError> = (
371371
error.message = result;
372372
} else if ('errors' in result) {
373373
const errors = values(result.errors)[0];
374-
const fields = Object.keys(result.errors)[0];
374+
const fields = Object.keys(result.errors);
375375
if (Array.isArray(errors)) {
376376
if (errors[0]) {
377377
error.message = `${fields[0]}: ${errors[0]}`; // eslint-disable-line no-param-reassign,prefer-destructuring

packages/app/src/app/overmind/namespaces/deployment/actions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ export const deleteDeployment: AsyncAction = async ({
163163
);
164164
};
165165

166-
export const aliasDeployment: AsyncAction<{
167-
id: string;
168-
}> = async ({ state, effects, actions }, { id }) => {
166+
export const aliasDeployment: AsyncAction<string> = async (
167+
{ state, effects, actions },
168+
id
169+
) => {
169170
const zeitConfig = effects.zeit.getConfig(state.editor.currentSandbox);
170171

171172
try {

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,10 @@ export const forkSandboxClicked: AsyncAction = async ({
301301
});
302302
};
303303

304-
export const likeSandboxToggled: AsyncAction<{
305-
id: string;
306-
}> = async ({ state, effects }, { id }) => {
304+
export const likeSandboxToggled: AsyncAction<string> = async (
305+
{ state, effects },
306+
id
307+
) => {
307308
if (state.editor.sandboxes[id].userLiked) {
308309
state.editor.sandboxes[id].likeCount--;
309310
await effects.api.unlikeSandbox(id);

packages/app/src/app/overmind/namespaces/explore/actions.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import { PickedSandboxDetails } from '@codesandbox/common/lib/types';
12
import { AsyncAction, Action } from 'app/overmind';
23
import { withLoadApp } from 'app/overmind/factories';
34

4-
export const popularSandboxesMounted: AsyncAction<{
5-
date: string;
6-
}> = withLoadApp(async ({ state, effects }, { date }) => {
7-
try {
8-
state.explore.popularSandboxes = await effects.api.getPopularSandboxes(
9-
date
10-
);
11-
} catch (error) {
12-
effects.notificationToast.error(
13-
'There has been a problem getting the sandboxes'
14-
);
5+
export const popularSandboxesMounted: AsyncAction<string> = withLoadApp(
6+
async ({ state, effects }, date) => {
7+
try {
8+
state.explore.popularSandboxes = await effects.api.getPopularSandboxes(
9+
date
10+
);
11+
} catch (error) {
12+
effects.notificationToast.error(
13+
'There has been a problem getting the sandboxes'
14+
);
15+
}
1516
}
16-
});
17+
);
1718

1819
export const pickSandbox: AsyncAction<{
1920
id: string;
@@ -43,13 +44,10 @@ export const pickSandbox: AsyncAction<{
4344
}
4445
};
4546

46-
export const pickSandboxModal: Action<{
47-
details: {
48-
id: string;
49-
title: string;
50-
description: string;
51-
};
52-
}> = ({ state }, { details }) => {
47+
export const pickSandboxModal: Action<PickedSandboxDetails> = (
48+
{ state },
49+
details
50+
) => {
5351
state.explore.pickedSandboxDetails = details;
5452
state.currentModal = 'pickSandbox';
5553
};

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
};

0 commit comments

Comments
 (0)