File tree Expand file tree Collapse file tree 4 files changed +38
-9
lines changed Expand file tree Collapse file tree 4 files changed +38
-9
lines changed Original file line number Diff line number Diff line change
1
+ // @flow
2
+ import React from 'react' ;
3
+ import { Link } from 'react-router-dom' ;
4
+
5
+ type Props = {
6
+ enabled : boolean ,
7
+ message : string ,
8
+ } ;
9
+
10
+ export default class ConfirmLink extends React . PureComponent {
11
+ props : Props ;
12
+ confirm = ( e : Event ) => {
13
+ const { enabled, message } = this . props ;
14
+
15
+ if ( enabled ) {
16
+ const yes = confirm ( message ) ;
17
+
18
+ if ( ! yes ) {
19
+ e . preventDefault ( ) ;
20
+ e . stopPropagation ( ) ;
21
+ }
22
+ }
23
+ } ;
24
+
25
+ render ( ) {
26
+ const { enabled, message, ...props } = this . props ;
27
+ return < Link onClick = { this . confirm } { ...props } /> ;
28
+ }
29
+ }
Original file line number Diff line number Diff line change @@ -161,11 +161,6 @@ class EditorPreview extends React.PureComponent {
161
161
162
162
return (
163
163
< FullSize >
164
- < Prompt
165
- when = { notSynced }
166
- message = { ( ) =>
167
- 'You have not saved this sandbox, are you sure you want to navigate away?' }
168
- />
169
164
< Header
170
165
sandbox = { sandbox }
171
166
sandboxActions = { sandboxActions }
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import styled from 'styled-components' ;
3
- import { Link } from 'react-router-dom ' ;
3
+ import ConfirmLink from 'app/components/ConfirmLink ' ;
4
4
import WorkspaceSubtitle from '../WorkspaceSubtitle' ;
5
5
import WorkspaceInputContainer from '../WorkspaceInputContainer' ;
6
6
import { sandboxUrl } from '../../../../../utils/url-generator' ;
@@ -58,7 +58,7 @@ export default class Project extends React.PureComponent {
58
58
} ;
59
59
60
60
render ( ) {
61
- const { forkedSandbox } = this . props ;
61
+ const { forkedSandbox, preventTransition } = this . props ;
62
62
const { title, description } = this . state ;
63
63
return (
64
64
< div >
@@ -88,9 +88,13 @@ export default class Project extends React.PureComponent {
88
88
< WorkspaceSubtitle > Forked from</ WorkspaceSubtitle >
89
89
90
90
< Item >
91
- < Link to = { sandboxUrl ( forkedSandbox ) } >
91
+ < ConfirmLink
92
+ enabled = { preventTransition }
93
+ message = "You have unsaved changes. Are you sure you want to navigate away?"
94
+ to = { sandboxUrl ( forkedSandbox ) }
95
+ >
92
96
{ forkedSandbox . title || forkedSandbox . id }
93
- </ Link >
97
+ </ ConfirmLink >
94
98
</ Item >
95
99
</ div > }
96
100
</ div >
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ const Workspace = ({ sandbox, sandboxActions }: Props) => (
45
45
title = { sandbox . title }
46
46
description = { sandbox . description }
47
47
forkedSandbox = { sandbox . forkedFromSandbox }
48
+ preventTransition = { sandbox . modules . some ( m => m . isNotSynced ) }
48
49
/>
49
50
</ WorkspaceItem >
50
51
You can’t perform that action at this time.
0 commit comments