Skip to content

Commit 992353f

Browse files
committed
with search
1 parent adf7d3a commit 992353f

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
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') {
2627
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');
@@ -56,7 +61,7 @@ export const App = (): JSX.Element => {
5661
}
5762
});
5863
}
59-
}, []);
64+
}, [toggleAttempt]);
6065
// useEffect(() => {
6166
// // provide config properties to legacy projects so new edits can be auto saved
6267
// // if (state.config === undefined) {

app/src/components/marketplace/MarketplaceCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
4040
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
4141
const open = Boolean(anchorEl);
4242
const state = useSelector((store:RootState) => store.appState);
43-
console.log('HEY', state)
4443
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
4544
setAnchorEl(event.currentTarget);
4645
};
4746
const handleClone = async () => { // creates a copy of the project
4847
const updatedProject: Project = JSON.parse(JSON.stringify(proj)); // creates a deep copy
4948
updatedProject.forked = `Forked from ${updatedProject.username}`;
49+
const username = window.localStorage.getItem('username');
5050
await axios.post('/cloneProject', {
51-
updatedProject
51+
updatedProject, username: username //passing in the username from localstorage for verification, just in case someone altered local storage
5252
});
5353
alert('Project cloned!');
5454
setAnchorEl(null);

app/src/components/right/LoginButton.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ 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-
13+
console.log('doc cookie 1', Cookies.get())
1314
const handleLogout = () => {
15+
console.log('doc cookie 2', Cookies.get('ssid'))
16+
// document.cookie = 'ssid' + '=; Max-Age=0';
17+
console.log('doc cookie 3', Cookies.get())
18+
1419
window.localStorage.clear();
15-
document.cookie = 'ssid' + '=; Max-Age=0';
1620

1721
if (state.isLoggedIn) {
1822
dispatch(toggleLoggedIn(false));

app/src/components/right/OpenProjects.tsx

Lines changed: 0 additions & 1 deletion
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

app/src/containers/MarketplaceContainer.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import MarketplaceCardContainer from '../components/marketplace/MarketplaceCardC
22
import SearchBar from '../components/marketplace/Searchbar';
33
import React, {useEffect, useState} from 'react';
44
import axios from 'axios';
5+
import { CircularProgress } from '@mui/material';
56

67
const MarketplaceContainer = () => {
78

@@ -28,13 +29,14 @@ const MarketplaceContainer = () => {
2829

2930
}, []);
3031

32+
3133
const updateDisplayProjects = (searchResults) => {
3234

3335
setDisplayProjects(searchResults);//have to pass this down as a prop so that the setting is done outside of Rendering otherwise callstack issues
3436

3537
};
3638

37-
39+
3840

3941

4042
return (
@@ -48,9 +50,17 @@ const MarketplaceContainer = () => {
4850
<SearchBar marketplaceProjects = {marketplaceProjects} updateDisplayProjects = {updateDisplayProjects}/>
4951
</div>
5052
{displayProjects.length ? <MarketplaceCardContainer displayProjects = {displayProjects} /> :
51-
<h2 style={{textAlign: 'center'}}>
52-
No Results Found!
53-
</h2>
53+
54+
(/*while marketplaceProjects is length 0 means it is not done fetching. Add loading...*/
55+
marketplaceProjects.length ?
56+
<h2 style={{textAlign: 'center'}}>
57+
No Results Found!
58+
</h2>
59+
:
60+
<h2 style={{textAlign: 'center'}}> {/*added a circular progress bar*/}
61+
Loading... <CircularProgress thickness={5.0}/>
62+
</h2>
63+
)
5464
}
5565
</div>
5666
);

server/controllers/marketplaceController.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ const marketplaceController: MarketplaceController = {
109109
*
110110
*/
111111
cloneProject: (req, res, next) => {
112-
const { updatedProject } = req.body;
113-
112+
const { updatedProject, username } = req.body;
113+
console.log('username in cloneProject end', username);
114114
// pulls cookies from request
115115
const currentuserID = req.cookies.ssid
116116
//getting the username based on the cookies ssid
@@ -122,6 +122,13 @@ const marketplaceController: MarketplaceController = {
122122
err: 'Error in marketplaceController.cloneProjects findUser, check server logs for details'
123123
}
124124
});
125+
}else if (user.username !== username){ //prevents users from editing their username to assign a different username to a cloned project
126+
return next({
127+
log: `Error in marketplaceController.cloneProjects. Window username did not match the corresponding db username: ${err}`,
128+
message: {
129+
err: 'Error in marketplaceController.cloneProjects. Window username did not match the corresponding db username, check server logs for details'
130+
}
131+
});
125132
}
126133
//adding the current user's username and userID since the project is now cloned
127134
updatedProject.username = user.username;

0 commit comments

Comments
 (0)