Skip to content

Commit b0940bb

Browse files
committed
Merge branch 'dev' into victor/sidebar
2 parents 8c3f691 + 1b478f7 commit b0940bb

28 files changed

+414
-172
lines changed

app/src/components/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import '../public/styles/style.css';
22

3-
import React, { useEffect } from 'react';
3+
import React, { useEffect, useState } from 'react';
44
import {
55
setInitialState,
66
toggleLoggedIn
@@ -19,16 +19,20 @@ import { saveProject } from '../helperFunctions/projectGetSaveDel';
1919
// Intermediary component to wrap main App component with higher order provider components
2020
export const App = (): JSX.Element => {
2121
const state = useSelector((store: RootState) => store.appState);
22+
const [toggleAttempt, setToggleAttempt] = useState(false);
2223
const dispatch = useDispatch();
2324
// checks if user is signed in as guest or actual user and changes loggedIn boolean accordingly
2425
useEffect(() => {
2526
if (window.localStorage.getItem('ssid') !== 'guest') {
26-
dispatch(toggleLoggedIn());
27+
dispatch(toggleLoggedIn(true));
2728
}
29+
//setToggleAttempt(!toggleAttempt);
2830
}, []);
2931

3032
// following useEffect runs on first mount
3133
useEffect(() => {
34+
console.log('state.isLoggedIn', state.isLoggedIn)
35+
// console.log('cookies.get in App', Cookies.get())
3236
// if user is a guest, see if a project exists in localforage and retrieve it
3337
if (!state.isLoggedIn) {
3438
localforage.getItem('guestProject').then((project) => {
@@ -39,6 +43,7 @@ export const App = (): JSX.Element => {
3943
});
4044
} else {
4145
// otherwise if a user is logged in, use a fetch request to load user's projects from DB
46+
4247
let userId;
4348
if (Cookies.get('ssid')) {
4449
userId = Cookies.get('ssid');

app/src/components/bottom/BottomTabs.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ const BottomTabs = (props): JSX.Element => {
8080
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
8181
label="CSS Editor"
8282
/>
83-
<Tab
83+
{/* <Tab (there was no more need for this tab since we created an outside button for the codePreview)
8484
disableRipple
8585
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
8686
label="Code Preview"
87-
/>
87+
/> */}
8888
<Tab
8989
disableRipple
9090
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
@@ -129,7 +129,7 @@ const BottomTabs = (props): JSX.Element => {
129129
{tab === 0 && <CreationPanel isThemeLight={props.isThemeLight} />}
130130
{tab === 1 && <CustomizationPanel isThemeLight={props.isThemeLight} />}
131131
{tab === 2 && <StylesEditor theme={theme} setTheme={setTheme} />}
132-
{tab === 3 && <CodePreview theme={theme} setTheme={setTheme} />}
132+
{/* {tab === 3 && <CodePreview theme={theme} setTheme={setTheme} />} */}
133133
{tab === 4 && <Tree data={components} />}
134134
{tab === 5 && <ContextManager theme={theme} setTheme={setTheme} />}
135135
{tab === 6 && (

app/src/components/main/Canvas.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
addChild,
66
changeFocus,
77
snapShotAction,
8-
toggleCodePreview
8+
// toggleCodePreview
99
} from '../../redux/reducers/slice/appStateSlice';
1010
import { useDispatch, useSelector } from 'react-redux';
1111

app/src/components/main/CanvasContainer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function CanvasContainer(props): JSX.Element {
1919
// onClickCodePreview swaps the rendered component from the canvas to the code preview editor
2020
const onClickCodePreview = () => {
2121
dispatch(toggleCodePreview());
22-
console.log(state.codePreview);
2322
}
2423

2524
const canvasContainerStyle = {

app/src/components/main/DemoRender.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const DemoRender = (): JSX.Element => {
8181
const elementType = element.name;
8282
const childId = element.childId;
8383
const elementStyle = element.style;
84-
const innerText = element.attributes.compText;
84+
const innerText = element.attributes.compText;
8585
const classRender = element.attributes.cssClasses;
8686
const activeLink = element.attributes.compLink;
8787
let renderedChildren;

app/src/components/marketplace/MarketplaceCard.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import React from 'react';
1818
import imageSrc from '../../../../resources/marketplace_images/marketplace_image.png';
1919
import { red } from '@mui/material/colors';
2020
import axios from 'axios';
21-
import {useDispatch, useSelector} from 'react-redux'
21+
import { useDispatch, useSelector } from 'react-redux'
2222
import { RootState } from '../../redux/store';
2323
import { saveProject } from '../../helperFunctions/projectGetSaveDel';
24+
import { useHistory } from 'react-router-dom';
25+
import { openProject } from '../../redux/reducers/slice/appStateSlice';
2426

2527
interface Project {
2628
forked: String,
@@ -37,21 +39,27 @@ interface Project {
3739

3840
const ITEM_HEIGHT = 48;
3941
const MarketplaceCard = ({proj} :{proj: Project}) => {
42+
const dispatch = useDispatch();
43+
const history = useHistory();
4044
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
4145
const open = Boolean(anchorEl);
4246
const state = useSelector((store:RootState) => store.appState);
43-
console.log('HEY', state)
4447
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
4548
setAnchorEl(event.currentTarget);
4649
};
4750
const handleClone = async () => { // creates a copy of the project
48-
const updatedProject: Project = JSON.parse(JSON.stringify(proj)); // creates a deep copy
49-
updatedProject.forked = `Forked from ${updatedProject.username}`;
50-
await axios.post('/cloneProject', {
51-
updatedProject
52-
});
51+
const docId = proj._id;
52+
const response = await axios.get(`/cloneProject/${docId}`, { params: { username: window.localStorage.getItem('username') } });//passing in username as a query param is query params
53+
const project = response.data.project;
5354
alert('Project cloned!');
5455
setAnchorEl(null);
56+
return project;
57+
};
58+
59+
const handleCloneOpen = async() => {
60+
const project = await handleClone();
61+
history.push('/');
62+
dispatch(openProject(project));
5563
};
5664
const handleClose = () => {
5765
setAnchorEl(null);
@@ -110,11 +118,19 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
110118
<MenuItem
111119
onClick={handleClone}
112120
sx={{
113-
color: '#C6C6C6'
121+
color: '#fff'
114122
}}
115123
>
116124
Clone
117125
</MenuItem>
126+
<MenuItem
127+
onClick={handleCloneOpen}
128+
sx={{
129+
color: '#fff'
130+
}}
131+
>
132+
Clone and open
133+
</MenuItem>
118134
</Menu>
119135
</Card>
120136
</>

app/src/components/marketplace/Searchbar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ const SearchBar = ({marketplaceProjects, updateDisplayProjects }):JSX.Element =>
2929
//a-zA-Z letters (lowercase and uppercase) and underscore symbol
3030
//All together: match either the start/end of a line/string or any character that is not a letter.
3131
//Looks for anything that has the searchText in between non-letter characters
32+
const patternString2 = '(?:^|.)' + searchText.toLowerCase() + '(?:$|.)';
33+
//Only difference is that (?:^|.) (?:$|.) look for anything that matches the string in between any other characters for the username search
34+
//test3 and 1test) would both match for string 'test'
35+
3236
const searchResults = marketplaceProjects.reduce((results, curr) => {
33-
if(curr.name.match(patternString) || curr.username.match(patternString))
37+
if(curr.name.match(patternString) || curr.username.match(patternString2))
3438
results.push(curr)
3539
return results;
3640
}, [])

app/src/components/right/DeleteProjects.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,27 @@ function ProjectsDialog(props: ProjectDialogProps) {
5353
aria-labelledby="project-dialog-title"
5454
open={open}
5555
>
56-
<DialogTitle style={{ color: "#000" }} id="project-dialog-title">Delete Project</DialogTitle>
56+
<DialogTitle style={{ color: "#297ac2" }} id="project-dialog-title">DELETE PROJECTS</DialogTitle>
57+
<DialogTitle style={{ color: "#000" }} id="project-dialog-title">User Projects</DialogTitle>
5758
<List style={{ color: "#000" }}>
58-
{projects.map((project: any, index: number) => (
59+
{projects.filter((project: any) => project.forked === undefined || project.forked === false).map((project: any, index: number) => (
60+
<ListItem
61+
button
62+
onClick={() => handleDelete(project.name)}
63+
key={index}
64+
>
65+
<ListItemAvatar>
66+
<Avatar className={classes.avatar}>
67+
<DeleteRoundedIcon />
68+
</Avatar>
69+
</ListItemAvatar>
70+
<ListItemText primary={project.name} />
71+
</ListItem>
72+
))}
73+
</List>
74+
<DialogTitle style={{ color: "#000" }} id="project-dialog-title"> MP Projects</DialogTitle>
75+
<List style={{ color: "#000" }}>
76+
{projects.filter((project: any) => project.forked === true).map((project: any, index: number) => (
5977
<ListItem
6078
button
6179
onClick={() => handleDelete(project.name)}

app/src/components/right/LoginButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { useSelector, useDispatch } from 'react-redux';
33
import { toggleLoggedIn } from '../../redux/reducers/slice/appStateSlice';
44
import config from '../../../../config.js';
55
import { RootState } from '../../redux/store';
6+
import Cookies from 'js-cookie';
67
// note that API_BASE_URL is assigned to different pages on dev mode vs prod mode
78
const { API_BASE_URL, API_BASE_URL2 } = config;
89

910
export default function LoginButton() {
1011
const state = useSelector((store:RootState) => store.appState);
1112
const dispatch = useDispatch();
12-
1313
const handleLogout = () => {
14+
1415
window.localStorage.clear();
15-
document.cookie = 'ssid' + '=; Max-Age=0';
1616

1717
if (state.isLoggedIn) {
18-
dispatch(toggleLoggedIn());
18+
dispatch(toggleLoggedIn(false));
1919
}
2020

2121
window.location.href = state.isLoggedIn

app/src/components/right/MarketplaceButton.tsx

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

app/src/components/right/OpenProjects.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export interface ProjectDialogProps {
2424
function ProjectsDialog(props: ProjectDialogProps) {
2525
const classes = useStyles();
2626
const { onClose, open, projects } = props;
27-
console.log(projects)
2827
const state = useSelector((store:RootState) => store.appState);
2928
const dispatch = useDispatch();
3029
// If no projects selected, keep the name of the current displayed
@@ -55,11 +54,10 @@ function ProjectsDialog(props: ProjectDialogProps) {
5554
aria-labelledby="project-dialog-title"
5655
open={open}
5756
>
58-
<DialogTitle style={{ color: "#000" }} id="project-dialog-title">Open Project</DialogTitle>
57+
<DialogTitle style={{ color: "#297ac2" }} id="project-dialog-title">SAVED PROJECTS</DialogTitle>
58+
<DialogTitle style={{ color: "#000" }} id="project-dialog-title">User Projects</DialogTitle>
5959
<List style={{ color: "#000" }}>
60-
{projects.filter((project: any) => project.forked === undefined).map((project: any, index: number) => {
61-
console.log("Logging something inside the map:", project.forked); // Add this line
62-
return (
60+
{projects.filter((project: any) => project.forked === undefined || project.forked === false).map((project: any, index: number) => (
6361
<ListItem
6462
button
6563
onClick={() => handleListItemClick(project.name)}
@@ -72,15 +70,13 @@ function ProjectsDialog(props: ProjectDialogProps) {
7270
</ListItemAvatar>
7371
<ListItemText primary={project.name} />
7472
</ListItem>
75-
);
76-
})}
73+
)
74+
)}
7775
</List>
7876
{/* this section handles the projects cloned from the marketplace */}
7977
<DialogTitle style={{ color: "#000" }} id="project-dialog-title">MP Projects</DialogTitle>
8078
<List style={{ color: "#000" }}>
81-
{projects.filter((project: any) => project.forked !== undefined).map((project: any, index: number) => {
82-
console.log("Logging something inside the second map:", project.forked); // Add this line
83-
return (
79+
{projects.filter((project: any) => project.forked === true).map((project: any, index: number) => (
8480
<ListItem
8581
button
8682
onClick={() => handleListItemClick(project.name)}
@@ -93,8 +89,8 @@ function ProjectsDialog(props: ProjectDialogProps) {
9389
</ListItemAvatar>
9490
<ListItemText primary={project.name} />
9591
</ListItem>
96-
);
97-
})}
92+
)
93+
)}
9894
</List>
9995
</Dialog>
10096
);

app/src/components/right/SaveProjectButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import DialogTitle from '@mui/material/DialogTitle';
88
import SaveOutlinedIcon from '@mui/icons-material/SaveOutlined';
99
import { saveProject } from '../../helperFunctions/projectGetSaveDel';
1010
import {useDispatch, useSelector} from 'react-redux'
11-
import {updateProjectName} from '../../redux/reducers/slice/appStateSlice';
11+
import {updateProjectName, updateProjectId} from '../../redux/reducers/slice/appStateSlice';
1212
import { RootState } from '../../redux/store';
13+
import { State } from '../../interfaces/Interfaces';
1314

1415
export default function FormDialog() {
1516
const [open, setOpen] = useState(false);
@@ -34,7 +35,7 @@ const dispatch = useDispatch();
3435
// If errors occur on the backend, the project name still gets updated
3536

3637
dispatch(updateProjectName(projectName))
37-
saveProject(projectName, state);
38+
saveProject(projectName, state).then((project: State) => dispatch(updateProjectId(project._id)))//updates the slice with new _id from mongo
3839
setOpen(false);
3940
} else {
4041
setInvalidProjectName(true);

0 commit comments

Comments
 (0)