File tree Expand file tree Collapse file tree 3 files changed +37
-8
lines changed Expand file tree Collapse file tree 3 files changed +37
-8
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,9 @@ class Editor extends React.Component {
257
257
if ( ! prevProps . unsavedChanges ) {
258
258
setTimeout ( ( ) => this . props . setUnsavedChanges ( false ) , 400 ) ;
259
259
}
260
+ } else if ( this . getContent ( ) . content !== this . props . file . content ) {
261
+ // TODO: make this not break regular edits!
262
+ this . _cm . setValue ( this . props . file . content ) ;
260
263
}
261
264
if ( this . props . fontSize !== prevProps . fontSize ) {
262
265
this . _cm . getWrapperElement ( ) . style [
Original file line number Diff line number Diff line change 1
- import React from 'react' ;
2
- import { useP5Version } from '../hooks/useP5Version' ;
1
+ import React , { useCallback } from 'react' ;
2
+ import { useDispatch } from 'react-redux' ;
3
+
4
+ import { useP5Version , p5Versions } from '../hooks/useP5Version' ;
5
+ import MenuItem from '../../../components/Dropdown/MenuItem' ;
6
+ import DropdownMenu from '../../../components/Dropdown/DropdownMenu' ;
7
+ import { updateFileContent } from '../actions/files' ;
3
8
4
9
const VersionPicker = ( ) => {
5
- const versionInfo = useP5Version ( ) ;
10
+ const { indexID, versionInfo } = useP5Version ( ) ;
11
+ const dispatch = useDispatch ( ) ;
12
+ const dispatchReplaceVersion = useCallback (
13
+ ( version ) => {
14
+ if ( ! indexID || ! versionInfo ) return ;
15
+ dispatch ( updateFileContent ( indexID , versionInfo . replaceVersion ( version ) ) ) ;
16
+ } ,
17
+ [ indexID , versionInfo ]
18
+ ) ;
19
+
20
+ if ( ! versionInfo ) {
21
+ return < p > Custom</ p > ;
22
+ }
6
23
7
- return < p > { versionInfo ?. version || 'custom' } </ p > ;
24
+ return (
25
+ < DropdownMenu anchor = { < span > Version</ span > } align = "left" >
26
+ { p5Versions . map ( ( version ) => (
27
+ < MenuItem key = { version } onClick = { ( ) => dispatchReplaceVersion ( version ) } >
28
+ { version }
29
+ </ MenuItem >
30
+ ) ) }
31
+ </ DropdownMenu >
32
+ ) ;
8
33
} ;
9
34
10
35
VersionPicker . popTypes = { } ;
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import { useSelector } from 'react-redux';
8
8
export const p5Versions = [
9
9
'1.11.3' ,
10
10
'2.0.0-beta.2' ,
11
- '1.11.3' ,
12
11
'1.11.2' ,
13
12
'1.11.1' ,
14
13
'1.11.0' ,
@@ -135,12 +134,14 @@ export const p5Versions = [
135
134
136
135
export function useP5Version ( ) {
137
136
const files = useSelector ( ( state ) => state . files ) ;
138
- const indexSrc = files . find (
137
+ const indexFile = files . find (
139
138
( file ) =>
140
139
file . fileType === 'file' &&
141
140
file . name === 'index.html' &&
142
141
file . filePath === ''
143
- ) ?. content ;
142
+ ) ;
143
+ const indexSrc = indexFile ?. content ;
144
+ const indexID = indexFile ?. id ;
144
145
145
146
// { version: string, minified: boolean, replaceVersion: (version: string) => string } | null
146
147
const versionInfo = useMemo ( ( ) => {
@@ -180,5 +181,5 @@ export function useP5Version() {
180
181
return null ;
181
182
} , [ indexSrc ] ) ;
182
183
183
- return versionInfo ;
184
+ return { indexID , versionInfo } ;
184
185
}
You can’t perform that action at this time.
0 commit comments