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 Box from '@material-ui/core/Box' ;
4
14
import { GET_PROJECTS } from './gqlStrings' ;
5
15
import Project from './Project' ;
6
16
import NavBarDash from './NavbarDash' ;
7
- import AppContainer from '../containers/AppContainer' ;
17
+
8
18
import { theme1 , theme2 } from '../public/styles/theme' ;
9
19
// Implement Apollo Client useQuery hook to retrieve data from the server through graphQL. This includes 2 steps:
10
20
// 1) Impliment Apollo Provider in the top component in ./src/index.js, this allows children components access to the queried data
11
21
// 2) useQuery hook will update the data stored in Apollo Client's cache and automatically trigger child components rendering
12
22
13
23
export const styleContext = createContext ( {
14
24
style : null ,
15
- setStyle : null
25
+ setStyle : null ,
16
26
} ) ;
17
27
18
28
// setting light and dark themes (navbar and background); linked to theme.ts
19
29
const lightTheme = theme1 ;
20
30
const darkTheme = theme2 ; // dark mode color in theme.ts not reached
21
31
22
32
23
- const arrToComponent = ( arr ) => {
24
- return arr . map ( ( proj , index ) => < Project
33
+ const arrToComponent = arr => arr . map ( ( proj , index ) => < Project
25
34
key = { index }
26
35
name = { proj . name }
27
36
likes = { proj . likes }
@@ -32,22 +41,81 @@ const arrToComponent = (arr) => {
32
41
id = { proj . id }
33
42
comments = { proj . comments }
34
43
/> ) ;
44
+
45
+ // Caret Start Pulled from materialUI to create a tab panel
46
+ const a11yProps = ( index : any ) => ( {
47
+ id : `vertical-tab-${ index } ` ,
48
+ 'aria-controls' : `vertical-tabpanel-${ index } ` ,
49
+ } ) ;
50
+
51
+ interface LinkTabProps {
52
+ label ?: string ;
53
+ href ?: string ;
54
+ }
55
+
56
+ const LinkTab = ( props : LinkTabProps ) => (
57
+ < Tab
58
+ onClick = { ( event : React . MouseEvent < HTMLAnchorElement , MouseEvent > ) => {
59
+ event . preventDefault ( ) ;
60
+ } }
61
+ { ...props }
62
+ />
63
+ ) ;
64
+
65
+ const TabPanelItem = ( props : TabPanelProps ) : JSX . Element => {
66
+ const theme = useTheme ( ) ;
67
+ const {
68
+ children, index, value, ...other
69
+ } = props ;
70
+ return (
71
+ < div
72
+ role = "tabpanel"
73
+ hidden = { value !== index }
74
+ id = { `vertical-tabpanel-${ index } ` }
75
+ aria-labelledby = { `vertical-tab-${ index } ` }
76
+ { ...other }
77
+ >
78
+ { value === index && (
79
+ < Box p = { 3 } >
80
+ { children }
81
+ </ Box >
82
+ ) }
83
+ </ div >
84
+ ) ;
35
85
} ;
36
86
87
+ const useStyles = makeStyles ( ( theme ) => ( {
88
+ root : {
89
+ flexGrow : 1 ,
90
+ backgroundColor : theme . palette . background . paper ,
91
+ display : 'flex' ,
92
+ // height: 224,
93
+ } ,
94
+ tabs : {
95
+ borderRight : `1px solid ${ theme . palette . divider } ` ,
96
+ } ,
97
+ } ) ) ;
98
+ // Caret End of prefab code to generate a tab panel
99
+
100
+ const ProjectContainer = ( ) : JSX . Element => {
101
+ const classes = useStyles ( ) ;
102
+ const [ value , setValue ] = useState ( 0 ) ;
103
+
104
+ const handleChange = ( event : React . ChangeEvent < { } > , newValue : number ) => {
105
+ setValue ( newValue ) ;
106
+ } ;
37
107
38
- const ProjectContainer = ( ) => {
108
+ // Start Caret of old code from project container
39
109
const myVar = { } ;
40
110
// Need this for the individual user dasboard, for now, dashboard shows all projects from all users
41
111
const userSSID = window . localStorage . getItem ( 'ssid' ) || 'unavailable' ;
42
112
const username = window . localStorage . getItem ( 'username' ) || 'unavailable' ;
43
-
113
+
44
114
const [ isThemeLight , setTheme ] = useState ( true ) ;
45
115
46
116
const initialStyle = useContext ( styleContext ) ;
47
117
const [ style , setStyle ] = useState ( initialStyle ) ;
48
118
49
- // --------------------------Sorting Buttons------------------------------------//
50
-
51
119
// hook for sorting menu
52
120
const [ selectedOption , setSelectedOption ] = useState ( 'RATING' ) ;
53
121
@@ -68,55 +136,72 @@ const ProjectContainer = () => {
68
136
const sortedRatings = projects . sort ( ( a , b ) => b . username - a . username ) ;
69
137
return sortedRatings ;
70
138
} ;
71
- // ===================================================================================== //
72
-
73
139
// function for selecting drop down sorting menu
74
140
const optionClicked = ( value ) => {
75
141
setSelectedOption ( value ) ;
76
142
} ;
77
- // ===================================================================================== //
78
-
79
-
80
143
// useQuery hook abstracts fetch request
81
144
const { loading, error, data } = useQuery ( GET_PROJECTS , { pollInterval : 2000 , variables : myVar } ) ;
82
145
if ( loading ) return < p > Loading...</ p > ;
83
146
if ( error ) return < p > Error :{ error } </ p > ;
84
-
85
147
// based on resolver(getAllProject) for this query, the data is stored in the data object with the key 'getAllProjects'
86
148
const projects = data . getAllProjects ;
87
-
88
149
// 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 ) ;
150
+ let sortedProjects = projects . filter ( proj => {
151
+ return proj . published ;
152
+ } ) ;
153
+ const userProjects = projects . filter ( ( proj ) => {
154
+ return proj . username === username ;
155
+ } ) ;
91
156
92
157
// checking which sorting method was selected from drop down menu and invoking correct sorting function
93
158
if ( selectedOption === 'DATE' ) sortedProjects = sortByDate ( sortedProjects ) ;
94
159
else if ( selectedOption === 'USER' ) sortedProjects = sortByUser ( sortedProjects ) ;
95
160
else if ( selectedOption === 'RATING' ) sortedProjects = sortByRating ( sortedProjects ) ;
96
-
161
+
97
162
98
163
// create array to hold the components Project of loggin-in users
99
164
// generate an array of Project components based on queried data
100
165
const userDisplay = arrToComponent ( userProjects ) ;
101
-
102
166
// create an array of components Project that will be conditionally rendered
103
167
const sortedDisplay = arrToComponent ( sortedProjects ) ;
168
+ // Caret End of old code from Project Container
104
169
105
170
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 }
171
+ < div className = { classes . root } >
172
+ < MuiThemeProvider theme = { isThemeLight ? lightTheme : darkTheme } >
173
+ < div className = { 'dashboardContainer' } >
174
+ < NavBarDash setTheme = { setTheme } styles = { [ style , setStyle ] } isThemeLight = { isThemeLight } optionClicked = { optionClicked } />
175
+ < div className = { 'userDashboard' } >
176
+ { /* <AppBar position="static"> */ }
177
+ < Tabs
178
+ variant = "scrollable"
179
+ orientation = "vertical"
180
+ value = { value }
181
+ onChange = { handleChange }
182
+ aria-label = "Vertical tabs example"
183
+ className = { classes . tabs }
184
+ >
185
+ < LinkTab label = "Shared Dashboard" { ...a11yProps ( 0 ) } />
186
+ < LinkTab label = "Private Dashboard" { ...a11yProps ( 1 ) } />
187
+ </ Tabs >
188
+ { /* </AppBar> */ }
189
+ < TabPanelItem className = { 'projectPanel' } value = { value } index = { 0 } >
190
+ < h1 > Shared Dashboard </ h1 >
191
+ < div className = "projectContainer" >
192
+ { sortedDisplay }
193
+ </ div >
194
+ </ TabPanelItem >
195
+ < TabPanelItem className = { 'projectPanel' } value = { value } index = { 1 } >
196
+ < h1 > Private Dashboard </ h1 >
197
+ < div className = "projectContainer" >
198
+ { userDisplay }
199
+ </ div >
200
+ </ TabPanelItem >
117
201
</ div >
202
+ </ div >
203
+ </ MuiThemeProvider >
118
204
</ div >
119
- </ MuiThemeProvider >
120
205
) ;
121
206
} ;
122
207
0 commit comments