Skip to content

Commit 7f6471d

Browse files
committed
More code cleaning. Down to 2855 problems.
1 parent a538c27 commit 7f6471d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1966
-1979
lines changed

__tests__/spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// import 'regenerator-runtime/runtime'; // if there is an error with moduleNameMapper, npm -S install regenerator-runtime
2+
3+
//const { Application } = require('spectron');
4+
// const electronPath = require('electron');
5+
// const path = require('path');
6+
7+
// let app;
8+
9+
// // beforeAll(() => {
10+
// // // create a new app to test with setTimeout to be 15000 because the app takes a few seconds to spin up
11+
// // app = new Application({
12+
// // path: electronPath,
13+
// // chromeDriverArgs: ['--disable-extensions'],
14+
// // args: [path.join(__dirname, '../app/electron/main.js')] // this is the path from this test file to main.js inside electron folder
15+
// // });
16+
// // return app.start();
17+
// // }, 15000);
18+
19+
// // getWindowsCount() will return 2 instead of 1 in dev mode (one for the actual app, one in the browser at localhost:8080 in dev mode)
20+
// xtest('Displays App window', async () => {
21+
// const windowCount = await app.client.getWindowCount();
22+
// // expect(windowCount).toBe(1); // this returns true/passed if in production mode, change mode in script "test" to 'production' instead of 'test'
23+
// expect(windowCount).toBe(2); // 'dev' or 'test' mode results in 2 windows (one for the app and one for the browser)
24+
// });
25+
26+
// /* we want to test other functionalities of app.client such as text, title, etc. but even the examples from the official spectron website
27+
// or github repo did not yield the same outcomes as demonstrated. So we stopped testing Electron app here */
28+
// // afterAll(() => {
29+
// // if (app && app.isRunning()) {
30+
// // return app.stop();
31+
// // }
32+
// // });

app/src/Dashboard/NavbarDash.tsx

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-len */
12
import React, { useState, useContext } from 'react';
23
import { Theme } from '@mui/material/styles';
34
import withStyles from '@mui/styles/withStyles';
@@ -23,44 +24,42 @@ import { setStyle } from '../redux/reducers/slice/styleSlice';
2324
import { useSelector, useDispatch } from 'react-redux';
2425

2526
// NavBar text and button styling
26-
const useStyles = makeStyles((theme: Theme) =>
27-
createStyles({
28-
root: {
29-
flexGrow: 1,
30-
width: '100%'
31-
},
32-
menuButton: {
33-
marginRight: theme.spacing(2),
34-
color: 'white'
35-
},
36-
title: {
37-
flexGrow: 1,
38-
color: 'white'
39-
},
40-
manageProject: {
41-
display: 'flex',
42-
justifyContent: 'center'
43-
}
44-
})
45-
);
27+
const useStyles = makeStyles((theme: Theme) => createStyles({
28+
root: {
29+
flexGrow: 1,
30+
width: '100%',
31+
},
32+
menuButton: {
33+
marginRight: theme.spacing(2),
34+
color: 'white',
35+
},
36+
title: {
37+
flexGrow: 1,
38+
color: 'white',
39+
},
40+
manageProject: {
41+
display: 'flex',
42+
justifyContent: 'center',
43+
},
44+
}));
4645
// sorting options
4746
const sortMethods = ['RATING', 'DATE', 'USER'];
4847
// Drop down menu button for SORT PROJECTS
4948
const StyledMenu = withStyles({
5049
paper: {
51-
border: '1px solid #d3d4d5'
52-
}
50+
border: '1px solid #d3d4d5',
51+
},
5352
})((props) => (
5453
<Menu
5554
elevation={0}
5655
// getContentAnchorEl={null}
5756
anchorOrigin={{
5857
vertical: 'bottom',
59-
horizontal: 'center'
58+
horizontal: 'center',
6059
}}
6160
transformOrigin={{
6261
vertical: 'top',
63-
horizontal: 'center'
62+
horizontal: 'center',
6463
}}
6564
{...props}
6665
/>
@@ -69,10 +68,10 @@ const StyledMenuItem = withStyles((theme) => ({
6968
root: {
7069
'&:focus': {
7170
'& .MuiListItemIcon-root, & .MuiListItemText-primary': {
72-
color: theme.palette.common.white
73-
}
74-
}
75-
}
71+
color: theme.palette.common.white,
72+
},
73+
},
74+
},
7675
}))(MenuItem);
7776

7877
/**
@@ -117,7 +116,7 @@ export default function NavBar(props): JSX.Element {
117116
style={{
118117
display: 'inline-flex',
119118
justifyContent: 'center',
120-
textDecoration: 'none'
119+
textDecoration: 'none',
121120
}}
122121
>
123122
<Avatar src={greenLogo}></Avatar>
@@ -126,7 +125,7 @@ export default function NavBar(props): JSX.Element {
126125
style={{
127126
marginTop: '0.3rem',
128127
marginLeft: '0.5rem',
129-
color: 'silver'
128+
color: 'silver',
130129
}}
131130
className={classes.title}
132131
>

app/src/Dashboard/Project.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
/* eslint-disable max-len */
12
import React, { useState } from 'react';
23
import { useMutation } from '@apollo/client';
34
import {
45
ADD_LIKE,
56
MAKE_COPY,
67
DELETE_PROJECT,
78
PUBLISH_PROJECT,
8-
ADD_COMMENT
9+
ADD_COMMENT,
910
} from './gqlStrings';
1011
import CloseIcon from '@mui/icons-material/Close';
1112
import AddCommentIcon from '@mui/icons-material/AddComment';
@@ -58,7 +59,7 @@ const Project = ({
5859
id,
5960
username,
6061
published,
61-
comments
62+
comments,
6263
}: props): JSX.Element => {
6364
// IMPORTANT:
6465
// 1) schema change projId => id to allows Apollo Client cache auto-update. Only works with 'id'
@@ -72,53 +73,53 @@ const Project = ({
7273
const [addComment] = useMutation(ADD_COMMENT);
7374

7475
const noPointer = { cursor: 'default' };
75-
//Likes the project when the star icon is clicked
76+
// Likes the project when the star icon is clicked
7677
function handleLike(e) {
7778
e.preventDefault();
7879
const myVar = {
7980
variables: {
8081
projId: id,
81-
likes: likes + 1
82-
}
82+
likes: likes + 1,
83+
},
8384
};
8485
addLike(myVar);
8586
}
86-
//Makes a copy of the public project and saves as a user project
87+
// Makes a copy of the public project and saves as a user project
8788
function handleDownload(e) {
8889
e.preventDefault();
8990
const myVar = {
9091
variables: {
9192
projId: id,
9293
userId: currUserSSID,
93-
username: currUsername
94-
}
94+
username: currUsername,
95+
},
9596
};
9697
makeCopy(myVar);
9798
}
98-
//Publishes project from user dashboard to public dashboard
99+
// Publishes project from user dashboard to public dashboard
99100
function handlePublish(e) {
100101
e.preventDefault();
101102
const myVar = {
102103
variables: {
103104
projId: id,
104-
published: !published
105-
}
105+
published: !published,
106+
},
106107
};
107108
publishProject(myVar);
108109
}
109-
//Adds the comment to the project
110+
// Adds the comment to the project
110111
function handleComment(e) {
111112
e.preventDefault();
112113
const myVar = {
113114
variables: {
114115
projId: id,
115116
comment: commentVal,
116-
username: currUsername
117-
}
117+
username: currUsername,
118+
},
118119
};
119120
addComment(myVar);
120121
}
121-
//sets state of commentVal to what the user types in to comment
122+
// sets state of commentVal to what the user types in to comment
122123
function handleChange(e) {
123124
e.preventDefault();
124125
let commentValue = e.target.value;
@@ -133,21 +134,21 @@ const Project = ({
133134
<p className="comment">
134135
<b>{reversedCommentArray[i].username}</b>:
135136
{reversedCommentArray[i].text}
136-
</p>
137+
</p>,
137138
);
138139
}
139140
}
140141
// Closes out the open modal
141142
const closeModal = () => setModal('');
142143
// Creates modal that asks if user wants to delete project
143144
const deleteProjectModal = () => {
144-
//Deletes project from the database
145+
// Deletes project from the database
145146
const handleDelete = (e) => {
146147
e.preventDefault();
147148
const myVar = {
148149
variables: {
149-
projId: id
150-
}
150+
projId: id,
151+
},
151152
};
152153
deleteProject(myVar);
153154
};
@@ -161,7 +162,7 @@ const Project = ({
161162
style={{
162163
border: '1px solid #3c59ba',
163164
marginBottom: '2%',
164-
marginTop: '5%'
165+
marginTop: '5%',
165166
}}
166167
>
167168
<ListItemText
@@ -183,8 +184,8 @@ const Project = ({
183184
primBtnAction: null,
184185
secBtnAction: null,
185186
secBtnLabel: null,
186-
open: true
187-
})
187+
open: true,
188+
}),
188189
);
189190
};
190191

app/src/Dashboard/ProjectContainer.tsx

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
/* eslint-disable max-len */
12
import React, { useState } from 'react';
23
import {
34
ThemeProvider,
45
Theme,
56
StyledEngineProvider,
6-
useTheme
7+
useTheme,
78
} from '@mui/material/styles';
89
import makeStyles from '@mui/styles/makeStyles';
910
import { useQuery } from '@apollo/client';
@@ -36,20 +37,19 @@ const darkTheme = theme2; // dark mode color in theme.ts not reached
3637
* @param {Array} arr - An array of project objects, where each object contains project data.
3738
* @returns {Array<JSX.Element>} An array of <Project> components populated with data from the input array.
3839
*/
39-
const arrToComponent = (arr): Array<JSX.Element> =>
40-
arr.map((proj, index) => (
41-
<Project
42-
key={index}
43-
name={proj.name}
44-
likes={proj.likes}
45-
published={proj.published}
46-
userId={proj.userId}
47-
username={proj.username}
48-
createdAt={proj.createdAt}
49-
id={proj.id}
50-
comments={proj.comments}
51-
/>
52-
));
40+
const arrToComponent = (arr): Array<JSX.Element> => arr.map((proj, index) => (
41+
<Project
42+
key={index}
43+
name={proj.name}
44+
likes={proj.likes}
45+
published={proj.published}
46+
userId={proj.userId}
47+
username={proj.username}
48+
createdAt={proj.createdAt}
49+
id={proj.id}
50+
comments={proj.comments}
51+
/>
52+
));
5353

5454
/**
5555
* Generates accessibility props for a tab component within a tab panel. These properties help in
@@ -58,9 +58,9 @@ const arrToComponent = (arr): Array<JSX.Element> =>
5858
* @param {any} index - The index of the tab and its corresponding panel.
5959
* @returns {Object} An object containing the `id` and `aria-controls` attributes for accessibility purposes.
6060
*/
61-
const a11yProps = (index: any): Object => ({
61+
const a11yProps = (index: any): object => ({
6262
id: `vertical-tab-${index}`,
63-
'aria-controls': `vertical-tabpanel-${index}`
63+
'aria-controls': `vertical-tabpanel-${index}`,
6464
});
6565

6666
interface LinkTabProps {
@@ -95,11 +95,11 @@ const useStyles = makeStyles((theme) => ({
9595
root: {
9696
flexGrow: 1,
9797
// backgroundColor: theme.palette.background.paper,
98-
display: 'flex'
98+
display: 'flex',
9999
},
100100
tabs: {
101101
// borderRight: `1px solid ${theme.palette.divider}`
102-
}
102+
},
103103
}));
104104

105105
/**
@@ -163,26 +163,20 @@ const ProjectContainer = (): JSX.Element => {
163163
// useQuery hook abstracts fetch request
164164
const { loading, error, data } = useQuery(GET_PROJECTS, {
165165
pollInterval: 2000,
166-
variables: myVar
166+
variables: myVar,
167167
});
168168
if (loading) return <p>Loading...</p>;
169169
if (error) return <p>Error :{error}</p>;
170170
// based on resolver(getAllProject) for this query, the data is stored in the data object with the key 'getAllProjects'
171171
const projects = data.getAllProjects;
172172

173-
//create array to hold the data recieved in the public dashboard the will be conditionally rendered
174-
let sortedProjects = projects.filter((proj) => {
175-
return proj.published;
176-
});
177-
const userProjects = projects.filter((proj) => {
178-
return proj.username === username;
179-
});
173+
// create array to hold the data recieved in the public dashboard the will be conditionally rendered
174+
let sortedProjects = projects.filter((proj) => proj.published);
175+
const userProjects = projects.filter((proj) => proj.username === username);
180176
// checking which sorting method was selected from drop down menu and invoking correct sorting function
181177
if (selectedOption === 'DATE') sortedProjects = sortByDate(sortedProjects);
182-
else if (selectedOption === 'USER')
183-
sortedProjects = sortByUser(sortedProjects);
184-
else if (selectedOption === 'RATING')
185-
sortedProjects = sortByRating(sortedProjects);
178+
else if (selectedOption === 'USER') sortedProjects = sortByUser(sortedProjects);
179+
else if (selectedOption === 'RATING') sortedProjects = sortByRating(sortedProjects);
186180
// create array to hold the components Project of loggin-in users
187181
// generate an array of Project components based on queried data
188182
const userDisplay = arrToComponent(userProjects);

app/src/Dashboard/gqlStrings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const PUBLISH_PROJECT = gql`
4949
}
5050
}`;
5151

52-
export const ADD_COMMENT = gql`
52+
export const ADD_COMMENT = gql`
5353
mutation AddComment($projId: ID!, $comment: String!, $username: String!) {
5454
addComment(projId: $projId, comment: $comment, username: $username)
5555
{

0 commit comments

Comments
 (0)