Skip to content

Commit ae08e56

Browse files
committed
UI changes
1 parent c9da6cc commit ae08e56

File tree

14 files changed

+234
-144
lines changed

14 files changed

+234
-144
lines changed

client/common/icons.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ 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';
3028

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

client/images/lock.svg

Lines changed: 0 additions & 2 deletions
This file was deleted.

client/images/lockgif.gif

-5.32 KB
Binary file not shown.

client/images/unlock.svg

Lines changed: 0 additions & 5 deletions
This file was deleted.

client/modules/IDE/actions/project.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export function deleteProject(id) {
411411
};
412412
}
413413

414-
export function changeVisibility(projectId, visibility) {
414+
export function changeVisibility(projectId, projectName, visibility) {
415415
return (dispatch) =>
416416
apiClient
417417
.patch('/project/visibility', { projectId, visibility })
@@ -423,7 +423,7 @@ export function changeVisibility(projectId, visibility) {
423423
payload: { visibility: response.data.visibility }
424424
});
425425

426-
dispatch(setToastText(`Sketch is ${newVisibility}`));
426+
dispatch(setToastText(`The ${projectName} is now ${newVisibility}!`));
427427
dispatch(showToast(2000));
428428
})
429429
.catch((error) => {

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

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { setLanguage } from '../../actions/preferences';
3535
import Overlay from '../../../App/components/Overlay';
3636
import ProjectName from './ProjectName';
3737
import CollectionCreate from '../../../User/components/CollectionCreate';
38+
import { changeVisibility } from '../../actions/project';
3839

3940
const Nav = styled(NavBar)`
4041
background: ${prop('MobilePanel.default.background')};
@@ -75,6 +76,13 @@ const Title = styled.div`
7576
margin: 0;
7677
}
7778
79+
> section {
80+
display: flex;
81+
align-items: center;
82+
justify-content: center;
83+
gap: 5px;
84+
}
85+
7886
> h5 {
7987
font-size: ${remSize(13)};
8088
font-weight: normal;
@@ -203,6 +211,7 @@ const LanguageSelect = styled.div`
203211
const MobileNav = () => {
204212
const project = useSelector((state) => state.project);
205213
const user = useSelector((state) => state.user);
214+
const dispatch = useDispatch();
206215

207216
const { t } = useTranslation();
208217

@@ -228,19 +237,53 @@ const MobileNav = () => {
228237
}
229238

230239
const title = useMemo(resolveTitle, [pageName, project.name]);
240+
const userIsOwner = user?.username === project.owner?.username;
231241

232242
const Logo = AsteriskIcon;
243+
244+
const toggleVisibility = (e) => {
245+
try {
246+
const isChecked = e.target.checked;
247+
248+
dispatch(
249+
changeVisibility(
250+
project.id,
251+
project.name,
252+
isChecked ? 'Private' : 'Public'
253+
)
254+
);
255+
} catch (error) {
256+
console.log(error);
257+
}
258+
};
233259
return (
234260
<Nav>
235261
<LogoContainer>
236262
<Logo />
237263
</LogoContainer>
238264
<Title>
239-
<h1>{title === project.name ? <ProjectName /> : title}</h1>
240-
{project?.owner && title === project.name && (
241-
<h5>by {project?.owner?.username}</h5>
242-
)}
265+
<h1>{title === project?.name ? <ProjectName /> : title}</h1>
266+
{(() => {
267+
if (project?.owner && title === project.name && userIsOwner) {
268+
return (
269+
<main className="toolbar__makeprivate">
270+
<p>Private</p>
271+
<input
272+
className="toolbar__togglevisibility"
273+
type="checkbox"
274+
onChange={toggleVisibility}
275+
defaultChecked={project.visibility === 'Private'}
276+
/>
277+
</main>
278+
);
279+
}
280+
if (project?.owner && title === project.name) {
281+
return <h5>by {project?.owner?.username}</h5>;
282+
}
283+
return null;
284+
})()}
243285
</Title>
286+
244287
{/* check if the user is in login page */}
245288
{pageName === 'login' || pageName === 'signup' ? (
246289
// showing the CrossIcon

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +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 IconButton from '../../../../common/IconButton';
25-
import { LockIcon, UnlockIcon } from '../../../../common/icons';
24+
// import IconButton from '../../../../common/IconButton';
25+
// import { LockIcon, UnlockIcon } from '../../../../common/icons';
2626

2727
const Toolbar = (props) => {
2828
const { isPlaying, infiniteLoop, preferencesIsVisible } = useSelector(
@@ -33,17 +33,17 @@ const Toolbar = (props) => {
3333
const autorefresh = useSelector((state) => state.preferences.autorefresh);
3434
const dispatch = useDispatch();
3535
const { t } = useTranslation();
36-
const [visibility, setVisibility] = React.useState(
37-
project.visibility || 'Public'
38-
);
36+
3937
const userIsOwner = user?.username === project.owner?.username;
40-
const toggleVisibility = () => {
38+
const toggleVisibility = (e) => {
4139
try {
42-
setVisibility((prev) => (prev === 'Public' ? 'Private' : 'Public'));
40+
const isChecked = e.target.checked;
41+
4342
dispatch(
4443
changeVisibility(
4544
project.id,
46-
visibility === 'Public' ? 'Private' : 'Public'
45+
project.name,
46+
isChecked ? 'Private' : 'Public'
4747
)
4848
);
4949
} catch (error) {
@@ -119,7 +119,20 @@ const Toolbar = (props) => {
119119
<div className="toolbar__project-name-container">
120120
<ProjectName />
121121
{(() => {
122-
if (project.owner) {
122+
if (project?.owner && userIsOwner) {
123+
return (
124+
<main className="toolbar__makeprivate">
125+
<p>Private</p>
126+
<input
127+
type="checkbox"
128+
className="toolbar__togglevisibility"
129+
defaultChecked={project.visibility === 'Private'}
130+
onChange={toggleVisibility}
131+
/>
132+
</main>
133+
);
134+
}
135+
if (project?.owner && !userIsOwner) {
123136
return (
124137
<p className="toolbar__project-project.owner">
125138
{t('Toolbar.By')}{' '}
@@ -131,15 +144,6 @@ const Toolbar = (props) => {
131144
}
132145
return null;
133146
})()}
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-
)}
143147
</div>
144148
<button
145149
className={preferencesButtonClass}

0 commit comments

Comments
 (0)