Skip to content

Commit 3ce4973

Browse files
authored
Merge pull request #1464 from saijatin28/refactor-IDEView.jsx
Refactored getTitle and isUserOwner #1458
2 parents 912a2bf + d99afcc commit 3ce4973

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

client/modules/IDE/pages/IDEView.jsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ import AddToCollectionList from '../components/AddToCollectionList';
3434
import Feedback from '../components/Feedback';
3535
import { CollectionSearchbar } from '../components/Searchbar';
3636

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+
3746
class IDEView extends React.Component {
3847
constructor(props) {
3948
super(props);
@@ -92,7 +101,7 @@ class IDEView extends React.Component {
92101
}
93102

94103
componentDidUpdate(prevProps) {
95-
if (this.isUserOwner() && this.props.project.id) {
104+
if (isUserOwner(this.props) && this.props.project.id) {
96105
if (this.props.preferences.autosave && this.props.ide.unsavedChanges && !this.props.ide.justOpenedProject) {
97106
if (
98107
this.props.selectedFile.name === prevProps.selectedFile.name &&
@@ -123,21 +132,12 @@ class IDEView extends React.Component {
123132
this.autosaveInterval = null;
124133
}
125134

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-
135135
handleGlobalKeydown(e) {
136136
// 83 === s
137137
if (e.keyCode === 83 && ((e.metaKey && this.isMac) || (e.ctrlKey && !this.isMac))) {
138138
e.preventDefault();
139139
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)) {
141141
this.props.saveProject(this.cmController.getContent());
142142
} else if (this.props.user.authenticated) {
143143
this.props.cloneProject();
@@ -208,7 +208,7 @@ class IDEView extends React.Component {
208208
return (
209209
<div className="ide">
210210
<Helmet>
211-
<title>{this.getTitle()}</title>
211+
<title>{getTitle(this.props)}</title>
212212
</Helmet>
213213
{this.props.toast.isVisible && <Toast />}
214214
<Nav
@@ -313,7 +313,7 @@ class IDEView extends React.Component {
313313
isExpanded={this.props.ide.sidebarIsExpanded}
314314
expandSidebar={this.props.expandSidebar}
315315
collapseSidebar={this.props.collapseSidebar}
316-
isUserOwner={this.isUserOwner()}
316+
isUserOwner={isUserOwner(this.props)}
317317
clearConsole={this.props.clearConsole}
318318
consoleEvents={this.props.console}
319319
showRuntimeErrorWarning={this.props.showRuntimeErrorWarning}

0 commit comments

Comments
 (0)