Skip to content

Commit 907c057

Browse files
committed
frontend done
1 parent cae1399 commit 907c057

File tree

6 files changed

+131
-100
lines changed

6 files changed

+131
-100
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ const Toolbar = (props) => {
2828
(state) => state.ide
2929
);
3030
const project = useSelector((state) => state.project);
31+
const user = useSelector((state) => state.user);
3132
const autorefresh = useSelector((state) => state.preferences.autorefresh);
3233
const dispatch = useDispatch();
3334
const { t } = useTranslation();
3435
const [visibility, setVisibility] = React.useState(project.visibility);
35-
console.log(project);
36+
37+
const userIsOwner = user?.username === project.owner?.username;
3638
const toggleVisibility = () => {
3739
try {
3840
setVisibility((prev) => (prev === 'Public' ? 'Private' : 'Public'));
@@ -128,7 +130,7 @@ const Toolbar = (props) => {
128130
return null;
129131
})()}
130132
</div>
131-
{project?.owner && (
133+
{userIsOwner && project.owner && (
132134
<section>
133135
{visibility === 'Private' ? (
134136
<Button onClick={toggleVisibility}>Private</Button>

client/modules/IDE/components/SketchList.jsx

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ class SketchListRowBase extends React.Component {
179179
};
180180

181181
render() {
182-
console.log(this.props.sketch.visibility);
183182
const { sketch, username, mobile } = this.props;
184183
const { renameOpen, renameValue } = this.state;
185184
let url = `/${username}/sketches/${sketch.id}`;
@@ -188,7 +187,7 @@ class SketchListRowBase extends React.Component {
188187
}
189188
const title = (
190189
<p>
191-
Make {this.props.sketch.name}
190+
Make {this.props.sketch.name}{' '}
192191
<span className="sketch-visibility__title">
193192
{this.state.newVisibility === 'Private' ? 'Public' : 'Private'}
194193
</span>
@@ -215,18 +214,41 @@ class SketchListRowBase extends React.Component {
215214
closeOverlay={() => this.setState({ visibleDialogOpen: false })}
216215
>
217216
<div className="sketch-visibility">
218-
<hr />
219-
220-
<ul>
221-
<li>The sketch will not be visible to others.</li>
222-
<li>
223-
Other users will not be able to fork, edit or look the sketch
224-
</li>
225-
<li>
226-
You can always comeback and change the sketchs visibility
227-
nonetheless
228-
</li>
229-
</ul>
217+
{this.state.newVisibility === 'Public' ? (
218+
<ul className="sketch-visibility_ul">
219+
<li>
220+
Your sketch will stay private and will not be seen by
221+
others.
222+
</li>
223+
<li>
224+
Others will not be able to copy, change, or even see your
225+
sketch.
226+
</li>
227+
<li>This keeps your work safe and private.</li>
228+
229+
<li>
230+
you can focus on being creative without worrying about
231+
others seeing your work.
232+
</li>
233+
<li>
234+
You can always come back and adjust who can see your sketch.
235+
</li>
236+
</ul>
237+
) : (
238+
<ul className="sketch-visibility_ul">
239+
<li>Your sketch will be visible to everyone.</li>
240+
<li>Others can copy, edit, or just check out your sketch.</li>
241+
242+
<li>
243+
This helps everyone share ideas and be more creative
244+
together.
245+
</li>
246+
<li>
247+
You can always change who can see your sketch whenever you
248+
want.
249+
</li>
250+
</ul>
251+
)}
230252

231253
<hr />
232254
<Button onClick={this.toggleVisibility}>
@@ -415,8 +437,7 @@ class SketchList extends React.Component {
415437
};
416438

417439
render() {
418-
const userIsOwner = this.props.user.username === this.props.username;
419-
440+
// const userIsOwner = this.props.user.username === this.props.username;
420441
const username =
421442
this.props.username !== undefined
422443
? this.props.username
@@ -456,23 +477,19 @@ class SketchList extends React.Component {
456477
</tr>
457478
</thead>
458479
<tbody>
459-
{this.props.sketches
460-
.filter(
461-
(sketch) => userIsOwner || sketch.visibility === 'Public'
462-
)
463-
.map((sketch) => (
464-
<SketchListRow
465-
mobile={mobile}
466-
key={sketch.id}
467-
sketch={sketch}
468-
user={this.props.user}
469-
username={username}
470-
onAddToCollection={() => {
471-
this.setState({ sketchToAddToCollection: sketch });
472-
}}
473-
t={this.props.t}
474-
/>
475-
))}
480+
{this.props.sketches.map((sketch) => (
481+
<SketchListRow
482+
mobile={mobile}
483+
key={sketch.id}
484+
sketch={sketch}
485+
user={this.props.user}
486+
username={username}
487+
onAddToCollection={() => {
488+
this.setState({ sketchToAddToCollection: sketch });
489+
}}
490+
t={this.props.t}
491+
/>
492+
))}
476493
</tbody>
477494
</table>
478495
)}

client/modules/User/components/Collection.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ const CollectionItemRowBase = ({
6565

6666
return (
6767
<tr
68-
className={`sketches-table__row ${projectIsDeleted ? 'is-deleted' : ''}`}
68+
className={`sketches-table__row ${
69+
projectIsDeleted || projectIsPrivate ? 'is-deleted-or-private' : ''
70+
}`}
6971
>
7072
<th scope="row">{name}</th>
7173
<td>{dates.format(item.createdAt)}</td>

client/styles/components/_sketch-list.scss

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,50 @@
11
@use "sass:math";
22

3-
.sketch-visibility {
4-
text-align: center;
5-
}
6-
7-
sketch-visibility__title {
8-
color: red;
9-
text-decoration: underline;
3+
.sketch-visibility__title {
4+
@include themify() {
5+
color: getThemifyVariable('hint-arrow-background-color');
6+
}
107
}
118

12-
.sketch-visibility h1 {
13-
font-size: 24px;
14-
font-weight: bold;
15-
color: #333;
16-
/* Adjust color as needed */
17-
margin-bottom: 20px;
9+
.sketch-visibility {
10+
padding: 30px;
11+
display: flex;
12+
flex-direction: column;
13+
align-items: center;
1814
}
1915

2016
.sketch-visibility hr {
2117
border: none;
22-
border-top: 1px solid rgba(255, 255, 255, 0.5);
23-
/* Adjust color as needed */
24-
width: 80%;
18+
height: 1px;
19+
background: linear-gradient(to right, transparent, white, transparent);
2520
}
2621

27-
.sketch-visibility ul {
22+
.sketch-visibility_ul {
2823
list-style-type: none;
2924
padding: 0;
30-
text-align: left;
31-
margin-bottom: 20px;
25+
margin: 0;
26+
margin-bottom: 7px;
3227
}
3328

34-
.sketch-visibility ul li {
35-
position: relative;
36-
padding-left: 20px;
37-
/* Add padding for the text */
29+
.sketch-visibility_ul li {
30+
margin-bottom: 7px;
31+
display: flex;
32+
align-items: center;
3833
}
3934

40-
.sketch-visibility ul li::before {
35+
.sketch-visibility_ul li::before {
4136
content: "\2022";
42-
/* Bullet character */
43-
color: #333;
44-
/* Adjust color as needed */
45-
display: inline-block;
46-
width: 15px;
47-
/* Increase the width to make the circle bigger */
48-
height: 15px;
49-
/* Increase the height to make the circle bigger */
50-
border-radius: 50%;
51-
/* Make it a circle */
52-
background-color: #333;
53-
/* Adjust color as needed */
54-
position: absolute;
55-
left: 0;
56-
top: 50%;
57-
transform: translateY(-50%);
58-
}
5937

60-
.sketch-visibility button {
61-
display: block;
62-
margin: 0 auto;
63-
padding: 10px 20px;
64-
font-size: 16px;
65-
background-color: #007bff;
66-
/* Adjust color as needed */
67-
color: #fff;
68-
/* Adjust color as needed */
69-
border: none;
70-
border-radius: 5px;
71-
cursor: pointer;
72-
transition: background-color 0.3s ease;
73-
}
38+
@include themify() {
39+
color: getThemifyVariable('hint-arrow-background-color');
40+
}
7441

75-
.sketch-visibility button:hover {
76-
background-color: #0056b3;
77-
/* Adjust color as needed */
42+
font-size: 34px;
43+
margin-right: 10px;
7844
}
7945

8046

47+
8148
.sketches-table-container {
8249
overflow-y: auto;
8350
max-width: 100%;
@@ -239,7 +206,7 @@ sketch-visibility__title {
239206
}
240207
}
241208

242-
.sketches-table__row.is-deleted>* {
209+
.sketches-table__row.is-deleted-or-private>* {
243210
font-style: italic;
244211
}
245212

server/controllers/project.controller.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import slugify from 'slugify';
88
import Project from '../models/project';
99
import User from '../models/user';
1010
import { resolvePathToFile } from '../utils/filePath';
11+
import { get404Sketch } from '../views/404Page';
1112
import generateFileSystemSafeName from '../utils/generateFileSystemSafeName';
1213

1314
export {
@@ -96,14 +97,21 @@ export function getProject(req, res) {
9697
$or: [{ _id: projectId }, { slug: projectId }]
9798
})
9899
.populate('user', 'username')
99-
.select('visibility')
100100
.exec((err, project) => { // eslint-disable-line
101101
if (err) {
102102
console.log(err);
103103
return res
104104
.status(404)
105105
.send({ message: 'Project with that id does not exist' });
106106
}
107+
// TODO: most probably, this will require its own 'SketchIsPrivate' page in future.
108+
if (
109+
project.visibility === 'Private' &&
110+
project.owner.username !== username
111+
) {
112+
res.status(401);
113+
return get404Sketch((html) => res.send(html));
114+
}
107115
return res.json(project);
108116
});
109117
});
@@ -123,6 +131,26 @@ export function getProjectsForUserId(userId) {
123131
});
124132
}
125133

134+
// eslint-disable-next-line consistent-return
135+
// export async function getProjectsForUserId(userId) {
136+
// try {
137+
// const projects = await Project.find({ user: userId })
138+
// // .select('name files id createdAt updatedAt visibility owner.username')
139+
// .sort('-createdAt');
140+
// // const user = await User.findById(userId);
141+
142+
// // const filteredProjects = projects.filter((project) => {
143+
// // const userIsOwner = project.owner.username === user.username;
144+
// // return userIsOwner || project.visibility === 'Public';
145+
// // });
146+
147+
// return projects;
148+
// } catch (error) {
149+
// console.log(error);
150+
// console.log(error);
151+
// }
152+
// }
153+
126154
export function getProjectAsset(req, res) {
127155
const projectId = req.params.project_id;
128156
Project.findOne({ $or: [{ _id: projectId }, { slug: projectId }] })

server/controllers/project.controller/getProjectsForUser.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,40 @@ import { toApi as toApiProjectObject } from '../../domain-objects/Project';
1010
const createCoreHandler = (mapProjectsToResponse) => async (req, res) => {
1111
try {
1212
const { username } = req.params;
13+
const currentUser = req.user?._id || '';
14+
console.log('current user', currentUser);
15+
1316
if (!username) {
1417
res.status(422).json({ message: 'Username not provided' });
1518
return;
1619
}
20+
1721
const user = await User.findByUsername(username);
1822
if (!user) {
1923
res
2024
.status(404)
2125
.json({ message: 'User with that username does not exist.' });
2226
return;
2327
}
28+
2429
const projects = await Project.find({ user: user._id })
2530
.sort('-createdAt')
26-
.select('name files id createdAt updatedAt visibility')
31+
.select('name files user id createdAt updatedAt visibility')
2732
.exec();
28-
const response = mapProjectsToResponse(projects);
33+
34+
const publicProjectsOnly = projects.filter(
35+
(project) => project.visibility === 'Public'
36+
);
37+
38+
const response = mapProjectsToResponse(
39+
currentUser !== user._id ? publicProjectsOnly : projects
40+
);
41+
2942
res.json(response);
30-
} catch (e) {
31-
res.status(500).json({ message: 'Error fetching projects' });
43+
} catch (error) {
44+
res
45+
.status(500)
46+
.json({ success: false, message: 'Error fetching projects' });
3247
}
3348
};
3449

0 commit comments

Comments
 (0)