Skip to content

Commit 7cff97f

Browse files
authored
Add an import from GitHub page (codesandbox#33)
* Add an import from GitHub page * Update Button snapshots
1 parent 3d186f3 commit 7cff97f

File tree

6 files changed

+139
-10
lines changed

6 files changed

+139
-10
lines changed

src/app/components/Input.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ export default styled.input`
55
border: none;
66
outline: none;
77
border-radius: 4px;
8-
border: 1px solid rgba(0,0,0,.1);
8+
border: 1px solid rgba(0, 0, 0, .1);
99
color: white;
10-
padding: 2px 0;
10+
padding: 0.25em;
1111
width: inherit;
12+
box-sizing: border-box;
1213
`;

src/app/components/buttons/Button.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const styles = css`
3939
4040
border-radius: 4px;
4141
42+
box-sizing: border-box;
4243
font-size: 1.125rem;
4344
text-align: center;
4445
color: ${props => getColor(props)};
@@ -80,8 +81,8 @@ const styles = css`
8081
}`}
8182
`;
8283
const LinkButton = styled(Link)`${styles}`;
83-
const AButton = styled.a`${styles}`;
84-
const Button = styled.button`${styles}`;
84+
const AButton = styled.a`${styles};`;
85+
const Button = styled.button`${styles};`;
8586

8687
type Props = {
8788
[key: any]: any,

src/app/components/buttons/__snapshots__/Button.test.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
exports[`Button renders 1`] = `
44
<button
5-
className="sc-htpNat hUeRGA"
5+
className="sc-htpNat iGlKTD"
66
>
77
Test
88
</button>
99
`;
1010

1111
exports[`Button renders disabled 1`] = `
1212
<button
13-
className="sc-htpNat izIXMc"
13+
className="sc-htpNat fTFVBb"
1414
disabled={true}
1515
>
1616
Test
@@ -19,7 +19,7 @@ exports[`Button renders disabled 1`] = `
1919

2020
exports[`Button renders href 1`] = `
2121
<a
22-
className="sc-bwzfXH cMAwix"
22+
className="sc-bwzfXH eBmlcd"
2323
href="https://ivesvh.com"
2424
>
2525
Test
@@ -28,7 +28,7 @@ exports[`Button renders href 1`] = `
2828

2929
exports[`Button renders onClick 1`] = `
3030
<button
31-
className="sc-htpNat hUeRGA"
31+
className="sc-htpNat iGlKTD"
3232
onClick={[Function]}
3333
>
3434
Test
@@ -37,15 +37,15 @@ exports[`Button renders onClick 1`] = `
3737

3838
exports[`Button renders properties 1`] = `
3939
<button
40-
className="sc-htpNat kgEmQI"
40+
className="sc-htpNat dpXcLN"
4141
>
4242
Test
4343
</button>
4444
`;
4545

4646
exports[`Button renders to 1`] = `
4747
<a
48-
className="sc-bdVaJa kfQsdG"
48+
className="sc-bdVaJa gUBIAT"
4949
href="https://ivesvh.com"
5050
onClick={[Function]}
5151
>

src/app/pages/GitHub/index.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// @flow
2+
import React from 'react';
3+
import styled from 'styled-components';
4+
5+
import Navigation from 'app/containers/Navigation';
6+
import Centered from 'app/components/flex/Centered';
7+
import Title from 'app/components/text/Title';
8+
import SubTitle from 'app/components/text/SubTitle';
9+
import Input from 'app/components/Input';
10+
import Button from 'app/components/buttons/Button';
11+
import { gitHubToSandboxUrl, protocolAndHost } from 'app/utils/url-generator';
12+
13+
const Container = styled.div`
14+
height: 100%;
15+
width: 100%;
16+
margin: 1rem;
17+
`;
18+
19+
const Content = styled(Centered)`
20+
max-width: 50em;
21+
margin: auto;
22+
margin-top: 10%;
23+
`;
24+
25+
const Label = styled.label`
26+
text-align: left;
27+
width: 100%;
28+
margin-bottom: 0.25rem;
29+
color: rgba(255, 255, 255, 0.3);
30+
`;
31+
32+
const Description = styled.div`margin-bottom: 1rem;`;
33+
34+
const StyledInput = styled(Input)`
35+
font-size: 1.25rem;
36+
margin-bottom: 2rem;
37+
`;
38+
39+
const ErrorMessage = styled.div`
40+
color: ${props => props.theme.red};
41+
margin-bottom: 2rem;
42+
`;
43+
44+
type State = {
45+
url: string,
46+
error: ?string,
47+
transformedUrl: string,
48+
};
49+
50+
const getFullGitHubUrl = url =>
51+
`${protocolAndHost()}${gitHubToSandboxUrl(url)}`;
52+
53+
export default class GitHub extends React.PureComponent {
54+
state: State = {
55+
url: 'https://github.com/reactjs/redux/tree/master/examples/counter',
56+
error: null,
57+
transformedUrl: getFullGitHubUrl(
58+
'https://github.com/reactjs/redux/tree/master/examples/counter',
59+
),
60+
};
61+
62+
updateUrl = e => {
63+
const url = e.target.value;
64+
65+
if (!url.includes('github.com')) {
66+
this.setState({
67+
url,
68+
error: "The URL should contain from 'github.com'.",
69+
});
70+
} else {
71+
this.setState({
72+
url: e.target.value,
73+
transformedUrl: getFullGitHubUrl(url),
74+
error: null,
75+
});
76+
}
77+
};
78+
79+
render() {
80+
const { url, transformedUrl, error } = this.state;
81+
return (
82+
<Container>
83+
<Navigation title="GitHub Import" />
84+
85+
<Content vertical horizontal>
86+
<Description>
87+
<Title>Import from GitHub</Title>
88+
<SubTitle>
89+
Enter the URL to your GitHub repository to generate a URL to your
90+
sandbox. The sandbox will stay in sync with your repository.
91+
</SubTitle>
92+
</Description>
93+
94+
<Label htmlFor="githuburl">GitHub URL</Label>
95+
96+
<StyledInput
97+
name="githuburl"
98+
value={url}
99+
onChange={this.updateUrl}
100+
placeholder="GitHub URL (can contain branch and path too)"
101+
/>
102+
{error !== null &&
103+
<ErrorMessage>
104+
{error}
105+
</ErrorMessage>}
106+
107+
<Label htmlFor="sandboxurl">Converted Sandbox URL</Label>
108+
<StyledInput
109+
name="sandboxurl"
110+
value={transformedUrl}
111+
placeholder="The Sandbox URL"
112+
/>
113+
114+
<Button to={gitHubToSandboxUrl(url)}>Open Sandbox</Button>
115+
</Content>
116+
</Container>
117+
);
118+
}
119+
}

src/app/pages/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const CLI = Loadable({
5050
loader: () => import('./CLI'),
5151
LoadingComponent: Loading,
5252
});
53+
const GitHub = Loadable({
54+
loader: () => import('./GitHub'),
55+
LoadingComponent: Loading,
56+
});
5357

5458
type Props = {
5559
hasLogin: boolean,
@@ -93,6 +97,7 @@ class Routes extends React.PureComponent {
9397
<Content>
9498
<Switch>
9599
<Route exact path="/" render={() => <Redirect to="/s/new" />} />
100+
<Route exact path="/s/github" component={GitHub} />
96101
<Route path="/s/:id*" component={Sandbox} />
97102
<Route path="/signin/:jwt?" component={SignIn} />
98103
<Route path="/u/:username" component={Profile} />

src/app/utils/url-generator.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ export const optionsToParameterizedUrl = (options: Object) => {
8686

8787
return keyValues ? `?${keyValues}` : '';
8888
};
89+
90+
export const gitHubToSandboxUrl = (githubUrl: string) =>
91+
githubUrl.replace('https://github.com', '/s/github');

0 commit comments

Comments
 (0)