@@ -34,17 +34,14 @@ import About from '../components/About';
3434import AddToCollectionList from '../components/AddToCollectionList' ;
3535import Feedback from '../components/Feedback' ;
3636import { CollectionSearchbar } from '../components/Searchbar' ;
37+ import { getIsUserOwner } from '../selectors/users' ;
3738
3839
3940function getTitle ( props ) {
4041 const { id } = props . project ;
4142 return id ? `p5.js Web Editor | ${ props . project . name } ` : 'p5.js Web Editor' ;
4243}
4344
44- function isUserOwner ( props ) {
45- return props . project . owner && props . project . owner . id === props . user . id ;
46- }
47-
4845function warnIfUnsavedChanges ( props ) {
4946 // eslint-disable-line
5047 const { route } = props . route ;
@@ -138,7 +135,7 @@ class IDEView extends React.Component {
138135 }
139136
140137 componentDidUpdate ( prevProps ) {
141- if ( isUserOwner ( this . props ) && this . props . project . id ) {
138+ if ( this . props . isUserOwner && this . props . project . id ) {
142139 if (
143140 this . props . preferences . autosave &&
144141 this . props . ide . unsavedChanges &&
@@ -151,7 +148,6 @@ class IDEView extends React.Component {
151148 if ( this . autosaveInterval ) {
152149 clearTimeout ( this . autosaveInterval ) ;
153150 }
154- console . log ( 'will save project in 20 seconds' ) ;
155151 this . autosaveInterval = setTimeout ( this . props . autosaveProject , 20000 ) ;
156152 }
157153 } else if ( this . autosaveInterval && ! this . props . preferences . autosave ) {
@@ -182,7 +178,7 @@ class IDEView extends React.Component {
182178 e . preventDefault ( ) ;
183179 e . stopPropagation ( ) ;
184180 if (
185- isUserOwner ( this . props ) ||
181+ this . props . isUserOwner ||
186182 ( this . props . user . authenticated && ! this . props . project . owner )
187183 ) {
188184 this . props . saveProject ( this . cmController . getContent ( ) ) ;
@@ -603,6 +599,7 @@ IDEView.propTypes = {
603599 openUploadFileModal : PropTypes . func . isRequired ,
604600 closeUploadFileModal : PropTypes . func . isRequired ,
605601 t : PropTypes . func . isRequired ,
602+ isUserOwner : PropTypes . bool . isRequired
606603} ;
607604
608605function mapStateToProps ( state ) {
@@ -620,6 +617,7 @@ function mapStateToProps(state) {
620617 project : state . project ,
621618 toast : state . toast ,
622619 console : state . console ,
620+ isUserOwner : getIsUserOwner ( state )
623621 } ;
624622}
625623
0 commit comments