1
- import React , { useState , useContext , useEffect , createContext } from 'react' ;
2
- import { createMuiTheme , MuiThemeProvider } from '@material-ui/core/styles' ;
1
+ import React , {
2
+ useState , useContext , useEffect , createContext ,
3
+ } from 'react' ;
4
+ import {
5
+ createMuiTheme , MuiThemeProvider , makeStyles , Theme , useTheme ,
6
+ } from '@material-ui/core/styles' ;
3
7
import { useQuery } from '@apollo/client' ;
8
+
9
+ import AppBar from '@material-ui/core/AppBar' ;
10
+ import Tabs from '@material-ui/core/Tabs' ;
11
+ import Tab from '@material-ui/core/Tab' ;
12
+
13
+ // import {Tab, Tabs} from '@material-ui/core'
14
+
15
+ import Box from '@material-ui/core/Box' ;
4
16
import { GET_PROJECTS } from './gqlStrings' ;
5
17
import Project from './Project' ;
6
18
import NavBarDash from './NavbarDash' ;
19
+
20
+
7
21
import AppContainer from '../containers/AppContainer' ;
8
22
import { theme1 , theme2 } from '../public/styles/theme' ;
9
23
// Implement Apollo Client useQuery hook to retrieve data from the server through graphQL. This includes 2 steps:
@@ -12,16 +26,15 @@ import { theme1, theme2 } from '../public/styles/theme';
12
26
13
27
export const styleContext = createContext ( {
14
28
style : null ,
15
- setStyle : null
29
+ setStyle : null ,
16
30
} ) ;
17
31
18
32
// setting light and dark themes (navbar and background); linked to theme.ts
19
33
const lightTheme = theme1 ;
20
34
const darkTheme = theme2 ; // dark mode color in theme.ts not reached
21
35
22
36
23
- const arrToComponent = ( arr ) => {
24
- return arr . map ( ( proj , index ) => < Project
37
+ const arrToComponent = arr => arr . map ( ( proj , index ) => < Project
25
38
key = { index }
26
39
name = { proj . name }
27
40
likes = { proj . likes }
@@ -32,22 +45,147 @@ const arrToComponent = (arr) => {
32
45
id = { proj . id }
33
46
comments = { proj . comments }
34
47
/> ) ;
48
+
49
+
50
+ // const ProjectContainerDetails = () => {
51
+ // const myVar = {};
52
+ // // Need this for the individual user dasboard, for now, dashboard shows all projects from all users
53
+ // const userSSID = window.localStorage.getItem('ssid') || 'unavailable';
54
+ // const username = window.localStorage.getItem('username') || 'unavailable';
55
+
56
+ // const [isThemeLight, setTheme] = useState(true);
57
+
58
+ // const initialStyle = useContext(styleContext);
59
+ // const [style, setStyle] = useState(initialStyle);
60
+
61
+ // // --------------------------Sorting Buttons------------------------------------//
62
+
63
+ // // hook for sorting menu
64
+ // const [selectedOption, setSelectedOption] = useState('RATING');
65
+
66
+ // const sortByRating = (projects) => {
67
+ // // generate a sorted array of public projects based on likes
68
+ // const sortedRatings = projects.sort((a, b) => b.likes - a.likes);
69
+ // return sortedRatings;
70
+ // };
71
+
72
+ // const sortByDate = (projects) => {
73
+ // // generate a sorted array of public projects based on date
74
+ // const sortedRatings = projects.sort((a, b) => b.createdAt - a.createdAt);
75
+ // return sortedRatings;
76
+ // };
77
+
78
+ // const sortByUser = (projects) => {
79
+ // // generate a sorted array of public projects based on username
80
+ // const sortedRatings = projects.sort((a, b) => b.username - a.username);
81
+ // return sortedRatings;
82
+ // };
83
+ // // ===================================================================================== //
84
+
85
+ // // function for selecting drop down sorting menu
86
+ // const optionClicked = (value) => {
87
+ // setSelectedOption(value);
88
+ // };
89
+ // // ===================================================================================== //
90
+
91
+
92
+ // // useQuery hook abstracts fetch request
93
+ // const { loading, error, data } = useQuery(GET_PROJECTS, { pollInterval: 2000, variables: myVar });
94
+ // if (loading) return <p>Loading...</p>;
95
+ // if (error) return <p>Error :{error}</p>;
96
+
97
+ // // based on resolver(getAllProject) for this query, the data is stored in the data object with the key 'getAllProjects'
98
+ // const projects = data.getAllProjects;
99
+
100
+ // // create array to hold the data recieved in the public dashboard the will be conditionally rendered
101
+ // let sortedProjects = projects.filter(proj => proj.published);
102
+ // const userProjects = projects.filter(proj => proj.username === username);
103
+
104
+ // // checking which sorting method was selected from drop down menu and invoking correct sorting function
105
+ // if (selectedOption === 'DATE') sortedProjects = sortByDate(sortedProjects);
106
+ // else if (selectedOption === 'USER') sortedProjects = sortByUser(sortedProjects);
107
+ // else if (selectedOption === 'RATING') sortedProjects = sortByRating(sortedProjects);
108
+
109
+
110
+ // // create array to hold the components Project of loggin-in users
111
+ // // generate an array of Project components based on queried data
112
+ // const userDisplay = arrToComponent(userProjects);
113
+
114
+ // // create an array of components Project that will be conditionally rendered
115
+ // const sortedDisplay = arrToComponent(sortedProjects);
116
+ // }
117
+ const a11yProps = ( index : any ) => ( {
118
+ id : `vertical-tab-${ index } ` ,
119
+ 'aria-controls' : `vertical-tabpanel-${ index } ` ,
120
+ } ) ;
121
+
122
+ interface LinkTabProps {
123
+ label ?: string ;
124
+ href ?: string ;
125
+ }
126
+
127
+ const LinkTab = ( props : LinkTabProps ) => (
128
+ < Tab
129
+ onClick = { ( event : React . MouseEvent < HTMLAnchorElement , MouseEvent > ) => {
130
+ event . preventDefault ( ) ;
131
+ } }
132
+ { ...props }
133
+ />
134
+ ) ;
135
+
136
+ const TabPanelItem = ( props : TabPanelProps ) : JSX . Element => {
137
+ const theme = useTheme ( ) ;
138
+ const {
139
+ children, index, value, ...other
140
+ } = props ;
141
+ return (
142
+ < div
143
+ role = "tabpanel"
144
+ hidden = { value !== index }
145
+ id = { `vertical-tabpanel-${ index } ` }
146
+ aria-labelledby = { `vertical-tab-${ index } ` }
147
+ { ...other }
148
+ >
149
+ { value === index && (
150
+ < Box p = { 3 } >
151
+ { children }
152
+ </ Box >
153
+ ) }
154
+ </ div >
155
+ ) ;
35
156
} ;
36
157
158
+ const useStyles = makeStyles ( ( theme ) => ( {
159
+ root : {
160
+ flexGrow : 1 ,
161
+ backgroundColor : theme . palette . background . paper ,
162
+ display : 'flex' ,
163
+ } ,
164
+ tabs : {
165
+ borderRight : `1px solid ${ theme . palette . divider } ` ,
166
+ } ,
167
+ } ) ) ;
168
+
169
+ const ProjectContainer = ( ) : JSX . Element => {
170
+ const classes = useStyles ( ) ;
171
+ const [ value , setValue ] = useState ( 0 ) ;
172
+
173
+ const handleChange = ( event : React . ChangeEvent < { } > , newValue : number ) => {
174
+ setValue ( newValue ) ;
175
+ } ;
37
176
38
- const ProjectContainer = ( ) => {
39
177
const myVar = { } ;
40
178
// Need this for the individual user dasboard, for now, dashboard shows all projects from all users
41
179
const userSSID = window . localStorage . getItem ( 'ssid' ) || 'unavailable' ;
42
180
const username = window . localStorage . getItem ( 'username' ) || 'unavailable' ;
43
-
181
+
44
182
const [ isThemeLight , setTheme ] = useState ( true ) ;
45
183
46
184
const initialStyle = useContext ( styleContext ) ;
47
185
const [ style , setStyle ] = useState ( initialStyle ) ;
48
186
49
187
// --------------------------Sorting Buttons------------------------------------//
50
-
188
+
51
189
// hook for sorting menu
52
190
const [ selectedOption , setSelectedOption ] = useState ( 'RATING' ) ;
53
191
@@ -84,39 +222,63 @@ const ProjectContainer = () => {
84
222
85
223
// based on resolver(getAllProject) for this query, the data is stored in the data object with the key 'getAllProjects'
86
224
const projects = data . getAllProjects ;
87
-
225
+ console . log ( 'projects data' , projects ) ;
88
226
// create array to hold the data recieved in the public dashboard the will be conditionally rendered
89
- let sortedProjects = projects . filter ( proj => proj . published ) ;
90
- const userProjects = projects . filter ( proj => proj . username === username ) ;
227
+ let sortedProjects = projects . filter ( proj => {
228
+ return proj . published
229
+ } ) ;
230
+ const userProjects = projects . filter ( ( proj ) => {
231
+ return proj . username === username ;
232
+ } ) ;
91
233
92
234
// checking which sorting method was selected from drop down menu and invoking correct sorting function
93
235
if ( selectedOption === 'DATE' ) sortedProjects = sortByDate ( sortedProjects ) ;
94
236
else if ( selectedOption === 'USER' ) sortedProjects = sortByUser ( sortedProjects ) ;
95
237
else if ( selectedOption === 'RATING' ) sortedProjects = sortByRating ( sortedProjects ) ;
96
-
238
+
97
239
98
240
// create array to hold the components Project of loggin-in users
99
241
// generate an array of Project components based on queried data
100
242
const userDisplay = arrToComponent ( userProjects ) ;
101
-
243
+ console . log ( 'This is the userDisplay' , userDisplay ) ;
102
244
// create an array of components Project that will be conditionally rendered
103
245
const sortedDisplay = arrToComponent ( sortedProjects ) ;
104
-
246
+ console . log ( 'This is the sortedDisplay' , sortedDisplay ) ;
105
247
return (
106
- < MuiThemeProvider theme = { isThemeLight ? lightTheme : darkTheme } >
107
- < div className = "dashboardContainer" >
108
- < NavBarDash setTheme = { setTheme } styles = { [ style , setStyle ] } isThemeLight = { isThemeLight } optionClicked = { optionClicked } />
109
- < h1 > Public Dashboard </ h1 >
110
- < div className = "projectContainer" >
111
- { sortedDisplay }
112
- </ div >
113
- < hr > </ hr >
114
- < h1 > User Dashboard </ h1 >
115
- < div className = "projectContainer" >
116
- { userDisplay }
248
+ < div className = { classes . root } >
249
+ < MuiThemeProvider theme = { isThemeLight ? lightTheme : darkTheme } >
250
+ < div >
251
+ < NavBarDash setTheme = { setTheme } styles = { [ style , setStyle ] } isThemeLight = { isThemeLight } optionClicked = { optionClicked } />
252
+ < div >
253
+ < AppBar position = "static" >
254
+ < Tabs
255
+ variant = "scrollable"
256
+ orientation = "vertical"
257
+ value = { value }
258
+ onChange = { handleChange }
259
+ aria-label = "Vertical tabs example"
260
+ className = { classes . tabs }
261
+ >
262
+ < LinkTab label = "Shared Dashboard" { ...a11yProps ( 0 ) } />
263
+ < LinkTab label = "Private Dashboard" { ...a11yProps ( 1 ) } />
264
+ </ Tabs >
265
+ </ AppBar >
266
+ < TabPanelItem value = { value } index = { 0 } >
267
+ < h1 > Shared Dashboard </ h1 >
268
+ < div >
269
+ { sortedDisplay }
270
+ </ div >
271
+ </ TabPanelItem >
272
+ < TabPanelItem value = { value } index = { 1 } >
273
+ < h1 > Private Dashboard </ h1 >
274
+ < div className = "projectContainer" >
275
+ { userDisplay }
276
+ </ div >
277
+ </ TabPanelItem >
117
278
</ div >
279
+ </ div >
280
+ </ MuiThemeProvider >
118
281
</ div >
119
- </ MuiThemeProvider >
120
282
) ;
121
283
} ;
122
284
0 commit comments