@@ -34,6 +34,15 @@ import AddToCollectionList from '../components/AddToCollectionList';
34
34
import Feedback from '../components/Feedback' ;
35
35
import { CollectionSearchbar } from '../components/Searchbar' ;
36
36
37
+ function getTitle ( props ) {
38
+ const { id } = props . project ;
39
+ return id ? `p5.js Web Editor | ${ props . project . name } ` : 'p5.js Web Editor' ;
40
+ }
41
+
42
+ function isUserOwner ( props ) {
43
+ return props . project . owner && props . project . owner . id === props . user . id ;
44
+ }
45
+
37
46
class IDEView extends React . Component {
38
47
constructor ( props ) {
39
48
super ( props ) ;
@@ -92,7 +101,7 @@ class IDEView extends React.Component {
92
101
}
93
102
94
103
componentDidUpdate ( prevProps ) {
95
- if ( this . isUserOwner ( ) && this . props . project . id ) {
104
+ if ( isUserOwner ( this . props ) && this . props . project . id ) {
96
105
if ( this . props . preferences . autosave && this . props . ide . unsavedChanges && ! this . props . ide . justOpenedProject ) {
97
106
if (
98
107
this . props . selectedFile . name === prevProps . selectedFile . name &&
@@ -123,21 +132,12 @@ class IDEView extends React.Component {
123
132
this . autosaveInterval = null ;
124
133
}
125
134
126
- getTitle = ( ) => {
127
- const { id } = this . props . project ;
128
- return id ? `p5.js Web Editor | ${ this . props . project . name } ` : 'p5.js Web Editor' ;
129
- }
130
-
131
- isUserOwner ( ) {
132
- return this . props . project . owner && this . props . project . owner . id === this . props . user . id ;
133
- }
134
-
135
135
handleGlobalKeydown ( e ) {
136
136
// 83 === s
137
137
if ( e . keyCode === 83 && ( ( e . metaKey && this . isMac ) || ( e . ctrlKey && ! this . isMac ) ) ) {
138
138
e . preventDefault ( ) ;
139
139
e . stopPropagation ( ) ;
140
- if ( this . isUserOwner ( ) || ( this . props . user . authenticated && ! this . props . project . owner ) ) {
140
+ if ( isUserOwner ( this . props ) || ( this . props . user . authenticated && ! this . props . project . owner ) ) {
141
141
this . props . saveProject ( this . cmController . getContent ( ) ) ;
142
142
} else if ( this . props . user . authenticated ) {
143
143
this . props . cloneProject ( ) ;
@@ -208,7 +208,7 @@ class IDEView extends React.Component {
208
208
return (
209
209
< div className = "ide" >
210
210
< Helmet >
211
- < title > { this . getTitle ( ) } </ title >
211
+ < title > { getTitle ( this . props ) } </ title >
212
212
</ Helmet >
213
213
{ this . props . toast . isVisible && < Toast /> }
214
214
< Nav
@@ -313,7 +313,7 @@ class IDEView extends React.Component {
313
313
isExpanded = { this . props . ide . sidebarIsExpanded }
314
314
expandSidebar = { this . props . expandSidebar }
315
315
collapseSidebar = { this . props . collapseSidebar }
316
- isUserOwner = { this . isUserOwner ( ) }
316
+ isUserOwner = { isUserOwner ( this . props ) }
317
317
clearConsole = { this . props . clearConsole }
318
318
consoleEvents = { this . props . console }
319
319
showRuntimeErrorWarning = { this . props . showRuntimeErrorWarning }
0 commit comments