Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private Sketch feat. #3034

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions client/constants.js
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ export const DELETE_COLLECTION = 'DELETE_COLLECTION';
export const ADD_TO_COLLECTION = 'ADD_TO_COLLECTION';
export const REMOVE_FROM_COLLECTION = 'REMOVE_FROM_COLLECTION';
export const EDIT_COLLECTION = 'EDIT_COLLECTION';
export const CHANGE_VISIBILITY = 'CHANGE_VISIBILITY';

export const DELETE_PROJECT = 'DELETE_PROJECT';

39 changes: 39 additions & 0 deletions client/modules/IDE/actions/project.js
Original file line number Diff line number Diff line change
@@ -410,3 +410,42 @@ export function deleteProject(id) {
});
};
}
export function changeVisibility(projectId, projectName, visibility) {
return (dispatch, getState) => {
const state = getState();

apiClient
.patch('/project/visibility', { projectId, visibility })
.then((response) => {
if (response.status === 200) {
const { visibility: newVisibility } = response.data;

dispatch({
type: ActionTypes.CHANGE_VISIBILITY,
payload: {
id: response.data.id,
visibility: newVisibility
}
});

if (state.project.id === response.data.id) {
dispatch({
type: ActionTypes.SET_PROJECT_NAME,
name: response.data.name
});
}

dispatch(
setToastText(`${projectName} is now ${newVisibility.toLowerCase()}`)
);
dispatch(showToast(2000));
}
})
.catch((error) => {
dispatch({
type: ActionTypes.ERROR,
error: error?.response?.data
});
});
};
}
51 changes: 47 additions & 4 deletions client/modules/IDE/components/Header/MobileNav.jsx
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ import { setLanguage } from '../../actions/preferences';
import Overlay from '../../../App/components/Overlay';
import ProjectName from './ProjectName';
import CollectionCreate from '../../../User/components/CollectionCreate';
import { changeVisibility } from '../../actions/project';

const Nav = styled(NavBar)`
background: ${prop('MobilePanel.default.background')};
@@ -75,6 +76,13 @@ const Title = styled.div`
margin: 0;
}

> section {
display: flex;
align-items: center;
justify-content: center;
gap: 5px;
}

> h5 {
font-size: ${remSize(13)};
font-weight: normal;
@@ -203,6 +211,7 @@ const LanguageSelect = styled.div`
const MobileNav = () => {
const project = useSelector((state) => state.project);
const user = useSelector((state) => state.user);
const dispatch = useDispatch();

const { t } = useTranslation();

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

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

const Logo = AsteriskIcon;

const toggleVisibility = (e) => {
try {
const isChecked = e.target.checked;

dispatch(
changeVisibility(
project.id,
project.name,
isChecked ? 'Private' : 'Public'
)
);
} catch (error) {
console.log(error);
}
};
return (
<Nav>
<LogoContainer>
<Logo />
</LogoContainer>
<Title>
<h1>{title === project.name ? <ProjectName /> : title}</h1>
{project?.owner && title === project.name && (
<h5>by {project?.owner?.username}</h5>
)}
<h1>{title === project?.name ? <ProjectName /> : title}</h1>
{(() => {
if (project?.owner && title === project.name && userIsOwner) {
return (
<main className="toolbar__makeprivate">
<p>Private</p>
<input
className="toolbar__togglevisibility"
type="checkbox"
onChange={toggleVisibility}
defaultChecked={project.visibility === 'Private'}
/>
</main>
);
}
if (project?.owner && title === project.name) {
return <h5>by {project?.owner?.username}</h5>;
}
return null;
})()}
</Title>

{/* check if the user is in login page */}
{pageName === 'login' || pageName === 'signup' ? (
// showing the CrossIcon
36 changes: 33 additions & 3 deletions client/modules/IDE/components/Header/Toolbar.jsx
Original file line number Diff line number Diff line change
@@ -15,22 +15,39 @@ import {
setGridOutput,
setTextOutput
} from '../../actions/preferences';

import PlayIcon from '../../../../images/play.svg';
import StopIcon from '../../../../images/stop.svg';
import PreferencesIcon from '../../../../images/preferences.svg';
import ProjectName from './ProjectName';
import { changeVisibility } from '../../actions/project';

const Toolbar = (props) => {
const { isPlaying, infiniteLoop, preferencesIsVisible } = useSelector(
(state) => state.ide
);
const project = useSelector((state) => state.project);
const user = useSelector((state) => state.user);
const autorefresh = useSelector((state) => state.preferences.autorefresh);
const dispatch = useDispatch();

const { t } = useTranslation();

console.log(project.visibility);
const userIsOwner = user?.username === project.owner?.username;
const toggleVisibility = (e) => {
try {
const isChecked = e.target.checked;
dispatch(
changeVisibility(
project.id,
project.name,
isChecked ? 'Private' : 'Public'
)
);
} catch (error) {
console.log(error);
}
};

const playButtonClass = classNames({
'toolbar__play-button': true,
'toolbar__play-button--selected': isPlaying
@@ -99,7 +116,20 @@ const Toolbar = (props) => {
<div className="toolbar__project-name-container">
<ProjectName />
{(() => {
if (project.owner) {
if (project?.owner && userIsOwner) {
return (
<main className="toolbar__makeprivate">
<p>Private</p>
<input
type="checkbox"
className="toolbar__togglevisibility"
defaultChecked={project.visibility === 'Private'}
onChange={toggleVisibility}
/>
</main>
);
}
if (project?.owner && !userIsOwner) {
return (
<p className="toolbar__project-project.owner">
{t('Toolbar.By')}{' '}
Original file line number Diff line number Diff line change
@@ -150,6 +150,22 @@ exports[`Nav renders dashboard version for mobile 1`] = `
margin: 0;
}

.c2 > section {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
gap: 5px;
}

.c2 > h5 {
font-size: 1.0833333333333333rem;
font-weight: normal;
@@ -780,6 +796,22 @@ exports[`Nav renders editor version for mobile 1`] = `
margin: 0;
}

.c2 > section {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
gap: 5px;
}

.c2 > h5 {
font-size: 1.0833333333333333rem;
font-weight: normal;
Loading