This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
[WIP] Export to Codesandbox #324
Open
AWolf81
wants to merge
11
commits into
master
Choose a base branch
from
export-to-codesandbox
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
85226db
WIP: Basic export working. Refactoring required.
AWolf81 8aff62d
WIP: Rendering issue with TokenInput
AWolf81 f8c459e
WIP: Scrollbars not working yet.
AWolf81 a6218fe
improved scrolling
AWolf81 c37b420
WIP: Added logout
AWolf81 7a547b6
Merge branch 'master' into export-to-codesandbox
AWolf81 f6253ba
Improved export logic
AWolf81 e91861b
WIP: Add codesandbox export saga
AWolf81 0be8dbd
improved saga & added tests. Improved styling.
AWolf81 0f4411f
updated snapshot for new app-setting
AWolf81 529a370
WIP: Updated codesandbox cli
AWolf81 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @flow | ||
import styled from 'styled-components'; | ||
import { COLORS } from '../../constants'; | ||
|
||
export default styled.div` | ||
padding-top: 16px; | ||
color: ${COLORS.gray[500]}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// @flow | ||
export { default } from './DisabledText'; |
183 changes: 183 additions & 0 deletions
183
src/components/ExportToCodesandbox/ExportToCodesandbox.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
// @flow | ||
import React, { Fragment, PureComponent } from 'react'; | ||
import styled from 'styled-components'; | ||
import { connect } from 'react-redux'; | ||
|
||
import * as actions from '../../actions'; | ||
import { COLORS } from '../../constants'; | ||
|
||
import { getSelectedProject } from '../../reducers/projects.reducer'; | ||
import { getCodesandboxToken } from '../../reducers/app-settings.reducer'; | ||
import { getExportingActiveStatus } from '../../reducers/project-status.reducer'; | ||
|
||
import ExternalLink from '../ExternalLink'; | ||
import FormField from '../FormField'; | ||
import TokenInput from '../TokenInput'; | ||
import StrokeButton from '../Button/StrokeButton'; | ||
import DisabledText from '../DisabledText'; | ||
import Spacer from '../Spacer'; | ||
import Spinner from '../Spinner'; | ||
|
||
import type { Project } from '../../types'; | ||
import type { Dispatch } from '../../actions/types'; | ||
|
||
type Props = { | ||
exportingActive: boolean, | ||
codesandboxToken: string, | ||
isFocused: boolean, | ||
project: Project, | ||
exportToCodesandbox: Dispatch<typeof actions.exportToCodesandboxStart>, | ||
updateToken: Dispatch<typeof actions.updateCodesandboxToken>, | ||
setCodesandboxUrl: Dispatch<typeof actions.setCodesandboxUrl>, | ||
logout: Dispatch<typeof actions.logoutCodesandbox>, | ||
onFocus: () => void, | ||
onBlur: () => void, | ||
}; | ||
|
||
class ExportToCodesandbox extends PureComponent<Props> { | ||
logout = (evt: any) => { | ||
evt.preventDefault(); | ||
const { logout, project } = this.props; | ||
|
||
logout(project.path); | ||
}; | ||
handleExport = (evt: any) => { | ||
const { project, exportToCodesandbox } = this.props; | ||
evt.preventDefault(); | ||
|
||
exportToCodesandbox(project.id); | ||
}; | ||
// todo: Change flow: | ||
// 1. Token always available before running the code - so no need to opne codesandbox page | ||
// 2. After export click display External link to created sandbox & store link in project | ||
render() { | ||
const { | ||
codesandboxToken, | ||
project, | ||
isFocused, | ||
onFocus, | ||
onBlur, | ||
exportingActive, | ||
} = this.props; | ||
const { codesandboxUrl } = project; | ||
|
||
return ( | ||
<ExportToCodesandboxWrapper> | ||
<FormField size="small" label="Export to Codesandbox.io" spacing={5}> | ||
<InfoText> | ||
Go to the Codesandbox website by clicking the link and copy the | ||
token. Then paste the token in the token field.{' '} | ||
</InfoText> | ||
<ExternalLink href="https://codesandbox.io/cli/login"> | ||
Get new token | ||
</ExternalLink> | ||
</FormField> | ||
<Wrapper> | ||
<FormField label="Codesandbox token" spacing={0}> | ||
<TokenRow> | ||
<TokenInput | ||
token={codesandboxToken} | ||
onChange={this.props.updateToken} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
focused={isFocused} | ||
disabled={codesandboxToken !== ''} | ||
/> | ||
{codesandboxToken && | ||
!isFocused && ( | ||
<Fragment> | ||
<Spacer size={10} /> | ||
<StrokeButton size="small" onClick={this.logout}> | ||
Logout | ||
</StrokeButton> | ||
</Fragment> | ||
)} | ||
</TokenRow> | ||
</FormField> | ||
<Action> | ||
<StrokeButton | ||
onClick={this.handleExport} | ||
size="small" | ||
strokeColors={[COLORS.green[700], COLORS.lightGreen[500]]} | ||
disabled={!codesandboxToken || exportingActive} | ||
> | ||
<ButtonCaption> | ||
{exportingActive && ( | ||
<Fragment> | ||
<Spinner size={24} /> | ||
<Spacer size={6} /> | ||
</Fragment> | ||
)} | ||
Export to Codesandbox | ||
</ButtonCaption> | ||
</StrokeButton> | ||
{!codesandboxToken && ( | ||
<DisabledText> | ||
Export disabled because token is missing. | ||
</DisabledText> | ||
)} | ||
|
||
{codesandboxUrl && ( | ||
<Fragment> | ||
<Spacer size={5} /> | ||
<InfoText> | ||
Codesandbox created <strong>{codesandboxUrl}</strong> | ||
<ExternalLink href={codesandboxUrl}> | ||
Open sandbox | ||
</ExternalLink> | ||
</InfoText> | ||
</Fragment> | ||
)} | ||
</Action> | ||
</Wrapper> | ||
</ExportToCodesandboxWrapper> | ||
); | ||
} | ||
} | ||
|
||
const Wrapper = styled.div` | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
`; | ||
|
||
const ButtonCaption = styled.div` | ||
display: flex; | ||
justify-content: flex-end; | ||
align-items: center; | ||
`; | ||
const ExportToCodesandboxWrapper = styled.div` | ||
margin-top: 16px; | ||
`; | ||
|
||
const Action = styled.div` | ||
margin: auto 0; | ||
padding-top: 5px; | ||
`; | ||
|
||
const InfoText = styled.div``; | ||
|
||
const TokenRow = styled.div` | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
const mapStateToProps = state => { | ||
const project = getSelectedProject(state); | ||
|
||
return { | ||
project, | ||
exportingActive: getExportingActiveStatus(state, project && project.id), | ||
codesandboxToken: getCodesandboxToken(state), | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = { | ||
exportToCodesandbox: actions.exportToCodesandboxStart, | ||
logout: actions.logoutCodesandbox, | ||
updateToken: actions.updateCodesandboxToken, | ||
}; | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(ExportToCodesandbox); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// @flow | ||
export { default } from './ExportToCodesandbox'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I've missed to pin the version. I'll change that in my next commit.