Skip to content

Commit c9da6cc

Browse files
committed
icons added
1 parent 3bf54c4 commit c9da6cc

File tree

13 files changed

+82
-61
lines changed

13 files changed

+82
-61
lines changed

client/common/icons.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import CircleInfo from '../images/circle-info.svg';
2525
import Add from '../images/add.svg';
2626
import Filter from '../images/filter.svg';
2727
import Cross from '../images/cross.svg';
28+
import Lock from '../images/lock.svg';
29+
import UnLock from '../images/unlock.svg';
2830

2931
// HOC that adds the right web accessibility props
3032
// https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html
@@ -102,3 +104,5 @@ export const CircleFolderIcon = withLabel(CircleFolder);
102104
export const CircleInfoIcon = withLabel(CircleInfo);
103105
export const AddIcon = withLabel(Add);
104106
export const FilterIcon = withLabel(Filter);
107+
export const LockIcon = withLabel(Lock);
108+
export const UnlockIcon = withLabel(UnLock);

client/images/lock.svg

Lines changed: 2 additions & 0 deletions
Loading

client/images/lockgif.gif

5.32 KB
Loading

client/images/unlock.svg

Lines changed: 5 additions & 0 deletions
Loading

client/modules/IDE/actions/project.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,14 @@ export function changeVisibility(projectId, visibility) {
416416
apiClient
417417
.patch('/project/visibility', { projectId, visibility })
418418
.then((response) => {
419-
console.log(response.data);
420419
const { visibility: newVisibility } = response.data;
421420

422421
dispatch({
423422
type: ActionTypes.CHANGE_VISIBILITY,
424423
payload: { visibility: response.data.visibility }
425424
});
426425

427-
dispatch(setToastText(`Sketch is switched to ${newVisibility}`));
426+
dispatch(setToastText(`Sketch is ${newVisibility}`));
428427
dispatch(showToast(2000));
429428
})
430429
.catch((error) => {

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import StopIcon from '../../../../images/stop.svg';
2121
import PreferencesIcon from '../../../../images/preferences.svg';
2222
import ProjectName from './ProjectName';
2323
import { changeVisibility } from '../../actions/project';
24-
import Button from '../../../../common/Button';
24+
import IconButton from '../../../../common/IconButton';
25+
import { LockIcon, UnlockIcon } from '../../../../common/icons';
2526

2627
const Toolbar = (props) => {
2728
const { isPlaying, infiniteLoop, preferencesIsVisible } = useSelector(
@@ -32,8 +33,9 @@ const Toolbar = (props) => {
3233
const autorefresh = useSelector((state) => state.preferences.autorefresh);
3334
const dispatch = useDispatch();
3435
const { t } = useTranslation();
35-
const [visibility, setVisibility] = React.useState(project.visibility);
36-
36+
const [visibility, setVisibility] = React.useState(
37+
project.visibility || 'Public'
38+
);
3739
const userIsOwner = user?.username === project.owner?.username;
3840
const toggleVisibility = () => {
3941
try {
@@ -129,16 +131,16 @@ const Toolbar = (props) => {
129131
}
130132
return null;
131133
})()}
134+
{userIsOwner && project.owner && (
135+
<section>
136+
{visibility !== 'Private' ? (
137+
<IconButton icon={UnlockIcon} onClick={toggleVisibility} />
138+
) : (
139+
<IconButton icon={LockIcon} onClick={toggleVisibility} />
140+
)}
141+
</section>
142+
)}
132143
</div>
133-
{userIsOwner && project.owner && (
134-
<section>
135-
{visibility === 'Private' ? (
136-
<Button onClick={toggleVisibility}>Private</Button>
137-
) : (
138-
<Button onClick={toggleVisibility}>Public</Button>
139-
)}
140-
</section>
141-
)}
142144
<button
143145
className={preferencesButtonClass}
144146
onClick={() => dispatch(openPreferences())}

client/modules/IDE/components/SketchList.jsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import getConfig from '../../../utils/getConfig';
2525
import ArrowUpIcon from '../../../images/sort-arrow-up.svg';
2626
import ArrowDownIcon from '../../../images/sort-arrow-down.svg';
2727
import Button from '../../../common/Button';
28+
import { LockIcon } from '../../../common/icons';
2829

2930
const ROOT_URL = getConfig('API_URL');
3031

@@ -213,6 +214,7 @@ class SketchListRowBase extends React.Component {
213214
title={title}
214215
closeOverlay={() => this.setState({ visibleDialogOpen: false })}
215216
>
217+
{/* TODO: these <li> should come from translate.json */}
216218
<div className="sketch-visibility">
217219
{this.state.newVisibility === 'Public' ? (
218220
<ul className="sketch-visibility_ul">
@@ -250,7 +252,6 @@ class SketchListRowBase extends React.Component {
250252
</ul>
251253
)}
252254

253-
<hr />
254255
<Button onClick={this.toggleVisibility}>
255256
I have read and understand these effects
256257
</Button>
@@ -267,10 +268,8 @@ class SketchListRowBase extends React.Component {
267268
key={sketch.id}
268269
onClick={this.handleRowClick}
269270
>
270-
<th scope="row" className="sketches-table__rowname">
271-
{this.state.newVisibility === 'Private' && <p>Lock</p>}
272-
{this.state.newVisibility}
273-
{name}
271+
<th scope="row" className="sketches-table_name">
272+
{this.state.newVisibility === 'Private' && <LockIcon />} {name}
274273
</th>
275274
<td>{formatDateCell(sketch.createdAt, mobile)}</td>
276275
<td>{formatDateCell(sketch.updatedAt, mobile)}</td>

client/modules/IDE/components/__snapshots__/SketchList.unit.test.jsx.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ exports[`<Sketchlist /> snapshot testing 1`] = `
8888
<tr
8989
class="sketches-table__row"
9090
>
91-
<th
91+
<th
9292
scope="row"
93+
class="sketches-table_name"
9394
>
9495
<a
9596
href="/happydog/sketches/testid1"
9697
>
98+
<LockIcon />
9799
testsketch1
98100
</a>
99101
</th>

client/modules/IDE/pages/IDEView.jsx

Lines changed: 9 additions & 3 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 } from 'react-router-dom';
2+
import { useLocation, Prompt, useParams, useHistory } from 'react-router-dom';
33
import { useDispatch, useSelector } from 'react-redux';
44
import { useTranslation } from 'react-i18next';
55
import { Helmet } from 'react-helmet';
@@ -11,7 +11,6 @@ import PreviewFrame from '../components/PreviewFrame';
1111
import Console from '../components/Console';
1212
import Toast from '../components/Toast';
1313
import { updateFileContent } from '../actions/files';
14-
1514
import {
1615
autosaveProject,
1716
clearPersistedState,
@@ -103,7 +102,7 @@ const IDEView = () => {
103102
const [sidebarSize, setSidebarSize] = useState(160);
104103
const [isOverlayVisible, setIsOverlayVisible] = useState(false);
105104
const [MaxSize, setMaxSize] = useState(window.innerWidth);
106-
105+
const history = useHistory();
107106
const cmRef = useRef({});
108107

109108
const autosaveIntervalRef = useRef(null);
@@ -124,6 +123,13 @@ const IDEView = () => {
124123
}
125124
}, [dispatch, params, project.id]);
126125

126+
useEffect(() => {
127+
if (!isUserOwner && project.visibility === 'Private') {
128+
// TODO: we might want to have a 'Sorry, this sketch is private' page for this
129+
history.push('/');
130+
}
131+
}, [isUserOwner, project.visibility, history]);
132+
127133
const autosaveAllowed = isUserOwner && project.id && preferences.autosave;
128134
const shouldAutosave = autosaveAllowed && ide.unsavedChanges;
129135

client/styles/components/_sketch-list.scss

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
}
77
}
88

9+
.sketch-visibility__icons {
10+
height: 30px;
11+
width: 30px;
12+
display: flex;
13+
gap: 5px;
14+
}
15+
916
.sketch-visibility {
1017
padding: 30px;
1118
display: flex;
@@ -45,6 +52,7 @@
4552

4653

4754

55+
4856
.sketches-table-container {
4957
overflow-y: auto;
5058
max-width: 100%;
@@ -71,6 +79,8 @@
7179
flex-direction: column;
7280
gap: #{math.div(12, $base-font-size)}rem;
7381

82+
83+
7484
.sketches-table__row {
7585
margin: 0;
7686
position: relative;
@@ -85,13 +95,14 @@
8595
background-color: getThemifyVariable("search-background-color") !important;
8696
}
8797

88-
>th {
89-
padding-left: 0;
90-
width: 100%;
98+
.sketches-table_name {
99+
display: flex;
100+
gap: 5px;
91101
font-weight: bold;
92-
margin-bottom: #{math.div(6, $base-font-size)}rem;
102+
align-items: center;
93103
}
94104

105+
95106
>td {
96107
padding-left: 0;
97108
width: 30%;

0 commit comments

Comments
 (0)