Skip to content

Commit f5864b1

Browse files
committed
refactoring code for private sketch feat
1 parent 2bb37c5 commit f5864b1

File tree

9 files changed

+74
-167
lines changed

9 files changed

+74
-167
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ MAILGUN_KEY=<your-mailgun-api-key>
1919
ML5_LIBRARY_USERNAME=ml5
2020
ML5_LIBRARY_EMAIL=[email protected]
2121
ML5_LIBRARY_PASS=helloml5
22-
MONGO_URL=mongodb://localhost:27017/local
22+
MONGO_URL=mongodb://localhost:27017/p5js-web-editor
2323
PORT=8000
2424
PREVIEW_PORT=8002
2525
EDITOR_URL=http://localhost:8000

client/images/earth.svg

Lines changed: 14 additions & 0 deletions
Loading

client/images/lock.svg

Lines changed: 13 additions & 0 deletions
Loading

client/modules/IDE/components/Header/MobileNav.jsx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,15 @@ const MobileNav = () => {
247247

248248
const title = useMemo(resolveTitle, [pageName, project.name]);
249249
const userIsOwner = user?.username === project.owner?.username;
250-
251250
const Logo = AsteriskIcon;
252251

252+
const showPrivacyToggle =
253+
project?.owner && title === project.name && userIsOwner;
254+
const showOwner = project?.owner && title === project.name && !userIsOwner;
255+
253256
const toggleVisibility = (e) => {
254257
try {
255258
const isChecked = e.target.checked;
256-
257259
dispatch(
258260
changeVisibility(
259261
project.id,
@@ -272,25 +274,18 @@ const MobileNav = () => {
272274
</LogoContainer>
273275
<Title>
274276
<h1>{title === project?.name ? <ProjectName /> : title}</h1>
275-
{(() => {
276-
if (project?.owner && title === project.name && userIsOwner) {
277-
return (
278-
<main className="toolbar__makeprivate">
279-
<p>Private</p>
280-
<input
281-
className="toolbar__togglevisibility"
282-
type="checkbox"
283-
onChange={toggleVisibility}
284-
defaultChecked={project.visibility === 'Private'}
285-
/>
286-
</main>
287-
);
288-
}
289-
if (project?.owner && title === project.name) {
290-
return <h5>by {project?.owner?.username}</h5>;
291-
}
292-
return null;
293-
})()}
277+
{showPrivacyToggle && (
278+
<main className="toolbar__makeprivate">
279+
<p>Private</p>
280+
<input
281+
className="toolbar__togglevisibility"
282+
type="checkbox"
283+
onChange={toggleVisibility}
284+
defaultChecked={project.visibility === 'Private'}
285+
/>
286+
</main>
287+
)}
288+
{showOwner && <h5>by {project?.owner?.username}</h5>}
294289
</Title>
295290

296291
{/* check if the user is in login page */}

client/modules/IDE/components/Header/Toolbar.jsx

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const Toolbar = (props) => {
3737
setIsPrivate(project.visibility === 'Private');
3838
}, [project]);
3939

40+
const showPrivacyToggle = project?.owner && userIsOwner;
41+
const showOwner = project?.owner && !userIsOwner;
42+
4043
const toggleVisibility = (e) => {
4144
try {
4245
const isChecked = e.target.checked;
@@ -117,32 +120,25 @@ const Toolbar = (props) => {
117120
</div>
118121
<div className="toolbar__project-name-container">
119122
<ProjectName />
120-
{(() => {
121-
if (project?.owner && userIsOwner) {
122-
return (
123-
<main className="toolbar__makeprivate">
124-
<p>Private</p>
125-
<input
126-
type="checkbox"
127-
className="toolbar__togglevisibility"
128-
checked={isPrivate}
129-
onChange={toggleVisibility}
130-
/>
131-
</main>
132-
);
133-
}
134-
if (project?.owner && !userIsOwner) {
135-
return (
136-
<p className="toolbar__project-owner">
137-
{t('Toolbar.By')}{' '}
138-
<Link to={`/${project.owner.username}/sketches`}>
139-
{project.owner.username}
140-
</Link>
141-
</p>
142-
);
143-
}
144-
return null;
145-
})()}
123+
{showPrivacyToggle && (
124+
<main className="toolbar__makeprivate">
125+
<p>Private</p>
126+
<input
127+
type="checkbox"
128+
className="toolbar__togglevisibility"
129+
checked={isPrivate}
130+
onChange={toggleVisibility}
131+
/>
132+
</main>
133+
)}
134+
{showOwner && (
135+
<p className="toolbar__project-owner">
136+
{t('Toolbar.By')}{' '}
137+
<Link to={`/${project.owner.username}/sketches`}>
138+
{project.owner.username}
139+
</Link>
140+
</p>
141+
)}
146142
<VersionIndicator />
147143
</div>
148144
<div style={{ flex: 1 }} />

client/modules/IDE/components/SketchList.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ const SketchList = ({
6060

6161
const renderEmptyTable = () => {
6262
if (!isLoading() && sketches.length === 0) {
63-
return (
64-
<p className="sketches-table curative__empty">
65-
{t('SketchList.NoSketches')}
66-
</p>
67-
);
63+
return <p className="sketches-table">{t('SketchList.NoSketches')}</p>;
6864
}
6965
return null;
7066
};

client/modules/IDE/components/SketchListRowBase.jsx

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import TableDropdown from '../../../components/Dropdown/TableDropdown';
1010
import MenuItem from '../../../components/Dropdown/MenuItem';
1111
import dates from '../../../utils/formatDate';
1212
import getConfig from '../../../utils/getConfig';
13+
import LockIcon from '../../../images/lock.svg';
14+
import EarthIcon from '../../../images/earth.svg';
1315

1416
const ROOT_URL = getConfig('API_URL');
1517

@@ -107,33 +109,8 @@ const SketchListRowBase = ({
107109
htmlFor={`toggle-${sketch.id}`}
108110
className="visibility__toggle-label"
109111
>
110-
<svg
111-
width="8"
112-
height="11"
113-
viewBox="0 0 8 11"
114-
fill="none"
115-
xmlns="http://www.w3.org/2000/svg"
116-
className="lock"
117-
>
118-
<path
119-
d="M8 5.68627V10.0784C8 10.5882 7.54067 11 7.00478 11H0.995215C0.440191 11 0 10.5686 0 10.0784V5.68627C0 5.17647 0.440191 4.7451 0.995215 4.7451C1.09035 4.7451 1.16746 4.66798 1.16746 4.57285V2.90196C1.16746 1.29412 2.43062 0 3.98086 0C5.55024 0 6.8134 1.29412 6.8134 2.90196V4.55371C6.8134 4.65941 6.89908 4.7451 7.00478 4.7451C7.54067 4.7451 8 5.15686 8 5.68627ZM2.33716 3.11732C2.34653 4.01904 3.08017 4.7451 3.98194 4.7451C4.89037 4.7451 5.62679 4.00867 5.62679 3.10024V2.90196C5.62679 1.96078 4.89952 1.21569 3.98086 1.21569C3.10048 1.21569 2.33493 1.96078 2.33493 2.90196L2.33716 3.11732Z"
120-
fill="white"
121-
fillOpacity="0.4"
122-
/>
123-
</svg>
124-
<svg
125-
width="10"
126-
height="10"
127-
viewBox="0 0 10 10"
128-
fill="none"
129-
xmlns="http://www.w3.org/2000/svg"
130-
className="earth"
131-
>
132-
<path
133-
d="M10 5C10 5.42308 9.96154 5.80769 9.86539 6.15385C9.32692 8.34615 7.34615 10 5 10C2.57692 10 0.538462 8.25 0.0961538 5.96154C0.0384615 5.65385 0 5.34615 0 5V4.98077C0 4.84615 7.26432e-08 4.73077 0.0192308 4.63461C0.125111 3.25818 0.781552 2.01128 1.78053 1.1614C1.91355 1.04823 2.15362 1.13705 2.32692 1.11538C2.67308 1.03846 2.90385 0.788462 3.07692 0.846154C3.26923 0.903846 3.42308 1.11538 3.19231 1.26923C2.94231 1.40385 2.88462 1.63462 3.01923 1.75C3.15385 1.86538 3.34615 1.63462 3.61538 1.63462C3.88462 1.63462 4.21154 1.96154 4.19231 2.21154C4.15385 2.55769 4.15385 3 4.30769 3.28846C4.46154 3.57692 4.80769 4.01923 5.23077 4.13462C5.61539 4.23077 6.26923 4.32692 6.34615 4.34615C6.63419 4.45588 6.57131 4.6983 6.33349 4.89437C6.21892 4.98883 6.11852 5.09107 6.09615 5.17308C5.86539 5.88462 6.84615 6.11538 6.67308 6.59615C6.55769 6.94231 6.17308 7.28846 6.03846 7.63462C5.95671 7.84484 5.9246 8.14727 5.98523 8.37391C6.02693 8.52981 6.28488 8.43597 6.40385 8.32692C6.63462 8.13462 7.11539 7.44231 7.44231 7.21154C7.78846 6.98077 8.57692 6.78846 8.82692 6.01923C8.96154 5.59615 8.94231 5.21154 8.36539 4.88462C7.78846 4.55769 8.17308 4.15385 7.67308 4.15385C7.17308 4.15385 7.15385 4.34615 6.78846 4.21154C5.53846 3.71154 5.90385 3.23077 6.21154 3.21154C6.34615 3.19231 6.48077 3.25 6.65385 3.32692C6.82692 3.42308 6.88462 3.32692 6.84615 3.05769C6.80769 2.78846 6.86539 2.42308 7 1.98077C7.21154 1.26923 6.80769 0.634615 6.19231 0.557692C5.61539 0.442308 5.57692 0.653846 5.19231 1.07692C4.90385 1.40385 4.34615 1.13462 3.88462 0.807692C3.61454 0.611276 3.90971 0.105968 4.2399 0.0560849C4.48198 0.019514 4.72894 0 4.98077 0C7.69649 0 9.91771 2.18723 9.97993 4.91613C9.9806 4.94511 10 4.97101 10 5Z"
134-
fill="#929292"
135-
/>
136-
</svg>
112+
<LockIcon className="lock" />
113+
<EarthIcon className="earth" />
137114
</label>
138115
</div>
139116
);
@@ -226,7 +203,7 @@ SketchListRowBase.defaultProps = {
226203

227204
function mapDispatchToPropsSketchListRow(dispatch) {
228205
return bindActionCreators(
229-
Object.assign({}, ProjectActions, IdeActions),
206+
Object.assign({}, ProjectActions, IdeActions), // Binding both ProjectActions and IdeActions
230207
dispatch
231208
);
232209
}

client/modules/IDE/pages/IDEView.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useRef, useState } from 'react';
2-
import { useLocation, Prompt, useParams, useHistory } from 'react-router-dom';
2+
import { useLocation, Prompt, useParams } from 'react-router-dom';
33
import { useDispatch, useSelector } from 'react-redux';
44
import { useTranslation } from 'react-i18next';
55
import { Helmet } from 'react-helmet';
@@ -105,7 +105,6 @@ const IDEView = () => {
105105
const [sidebarSize, setSidebarSize] = useState(160);
106106
const [isOverlayVisible, setIsOverlayVisible] = useState(false);
107107
const [MaxSize, setMaxSize] = useState(window.innerWidth);
108-
const history = useHistory();
109108
const cmRef = useRef({});
110109

111110
const autosaveIntervalRef = useRef(null);

client/modules/User/components/Collection.jsx

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import PropTypes from 'prop-types';
22
import React, { useEffect } from 'react';
33
import { useDispatch, useSelector } from 'react-redux';
4-
import { Link } from 'react-router-dom';
54
import { Helmet } from 'react-helmet';
65
import { useTranslation } from 'react-i18next';
76
import classNames from 'classnames';
@@ -12,88 +11,7 @@ import Loader from '../../App/components/loader';
1211
import ArrowUpIcon from '../../../images/sort-arrow-up.svg';
1312
import ArrowDownIcon from '../../../images/sort-arrow-down.svg';
1413
import CollectionMetadata from './CollectionMetadata';
15-
import dates from '../../../utils/formatDate';
16-
import RemoveIcon from '../../../images/close.svg';
17-
18-
const CollectionItemRow = ({ item, isOwner, collection, user }) => {
19-
const { t } = useTranslation();
20-
const dispatch = useDispatch();
21-
const formatDateCell = (date, mobile = false) =>
22-
dates.format(date, { showTime: !mobile });
23-
const handleSketchRemove = () => {
24-
dispatch(
25-
CollectionsActions.removeFromCollection(collection.id, item.projectId)
26-
);
27-
};
28-
29-
const projectIsDeleted = item.isDeleted;
30-
const projectIsPrivate =
31-
!item.isDeleted && !isOwner && item.project?.visibility === 'Private';
32-
33-
let name;
34-
if (projectIsDeleted) {
35-
name = <span>{t('Collection.SketchDeleted')}</span>;
36-
} else if (projectIsPrivate) {
37-
name = <span>Sketch is Private</span>;
38-
} else {
39-
name = (
40-
<Link to={`/${item.project.user.username}/sketches/${item.projectId}`}>
41-
{item.project.name}
42-
</Link>
43-
);
44-
}
45-
46-
const sketchOwnerUsername =
47-
projectIsDeleted || projectIsPrivate ? null : item.project.user.username;
48-
49-
return (
50-
<tr
51-
className={`sketches-table__row ${
52-
projectIsDeleted || projectIsPrivate ? 'is-deleted-or-private' : ''
53-
}`}
54-
>
55-
<th scope="row">{name}</th>
56-
<td>{formatDateCell(item.createdAt)}</td>
57-
<td>{sketchOwnerUsername}</td>
58-
<td className="collection-row__action-column">
59-
{isOwner && (
60-
<button
61-
className="collection-row__remove-button"
62-
onClick={handleSketchRemove}
63-
aria-label={t('Collection.SketchRemoveARIA')}
64-
>
65-
<RemoveIcon focusable="false" aria-hidden="true" />
66-
</button>
67-
)}
68-
</td>
69-
</tr>
70-
);
71-
};
72-
73-
CollectionItemRow.propTypes = {
74-
collection: PropTypes.shape({
75-
id: PropTypes.string.isRequired,
76-
name: PropTypes.string.isRequired
77-
}).isRequired,
78-
item: PropTypes.shape({
79-
createdAt: PropTypes.string.isRequired,
80-
projectId: PropTypes.string.isRequired,
81-
isDeleted: PropTypes.bool.isRequired,
82-
project: PropTypes.shape({
83-
id: PropTypes.string.isRequired,
84-
name: PropTypes.string.isRequired,
85-
visibility: PropTypes.string,
86-
user: PropTypes.shape({
87-
username: PropTypes.string.isRequired
88-
})
89-
}).isRequired
90-
}).isRequired,
91-
isOwner: PropTypes.bool.isRequired,
92-
user: PropTypes.shape({
93-
username: PropTypes.string,
94-
authenticated: PropTypes.bool.isRequired
95-
}).isRequired
96-
};
14+
import CollectionItemRow from './CollectionItemRow';
9715

9816
const Collection = ({ collectionId, username }) => {
9917
const { t } = useTranslation();
@@ -177,7 +95,6 @@ const Collection = ({ collectionId, username }) => {
17795
) : (
17896
<ArrowDownIcon
17997
role="img"
180-
IST
18198
aria-label={t('Collection.DirectionDescendingARIA')}
18299
/>
183100
))}

0 commit comments

Comments
 (0)