Skip to content

Commit 6a429cc

Browse files
committed
Refactored getTitle and isUserOwner #1458
1 parent 26bdef9 commit 6a429cc

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

client/modules/IDE/pages/IDEView.jsx

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

37+
const getTitle = (props) => {
38+
const { id } = props.project;
39+
return id ? `p5.js Web Editor | ${props.project.name}` : 'p5.js Web Editor';
40+
};
41+
42+
const isUserOwner = props => props.project.owner && props.project.owner.id === props.user.id;
43+
3744
class IDEView extends React.Component {
3845
constructor(props) {
3946
super(props);
@@ -92,7 +99,7 @@ class IDEView extends React.Component {
9299
}
93100

94101
componentDidUpdate(prevProps) {
95-
if (this.isUserOwner(this.props) && this.props.project.id) {
102+
if (isUserOwner(this.props) && this.props.project.id) {
96103
if (this.props.preferences.autosave && this.props.ide.unsavedChanges && !this.props.ide.justOpenedProject) {
97104
if (
98105
this.props.selectedFile.name === prevProps.selectedFile.name &&
@@ -123,19 +130,12 @@ class IDEView extends React.Component {
123130
this.autosaveInterval = null;
124131
}
125132

126-
getTitle = (props) => {
127-
const { id } = props.project;
128-
return id ? `p5.js Web Editor | ${props.project.name}` : 'p5.js Web Editor';
129-
}
130-
131-
isUserOwner = props => props.project.owner && props.project.owner.id === props.user.id;
132-
133133
handleGlobalKeydown(e) {
134134
// 83 === s
135135
if (e.keyCode === 83 && ((e.metaKey && this.isMac) || (e.ctrlKey && !this.isMac))) {
136136
e.preventDefault();
137137
e.stopPropagation();
138-
if (this.isUserOwner(this.props) || (this.props.user.authenticated && !this.props.project.owner)) {
138+
if (isUserOwner(this.props) || (this.props.user.authenticated && !this.props.project.owner)) {
139139
this.props.saveProject(this.cmController.getContent());
140140
} else if (this.props.user.authenticated) {
141141
this.props.cloneProject();
@@ -206,7 +206,7 @@ class IDEView extends React.Component {
206206
return (
207207
<div className="ide">
208208
<Helmet>
209-
<title>{this.getTitle(this.props)}</title>
209+
<title>{getTitle(this.props)}</title>
210210
</Helmet>
211211
{this.props.toast.isVisible && <Toast />}
212212
<Nav
@@ -311,7 +311,7 @@ class IDEView extends React.Component {
311311
isExpanded={this.props.ide.sidebarIsExpanded}
312312
expandSidebar={this.props.expandSidebar}
313313
collapseSidebar={this.props.collapseSidebar}
314-
isUserOwner={this.isUserOwner(this.props)}
314+
isUserOwner={isUserOwner(this.props)}
315315
clearConsole={this.props.clearConsole}
316316
consoleEvents={this.props.console}
317317
showRuntimeErrorWarning={this.props.showRuntimeErrorWarning}

0 commit comments

Comments
 (0)