1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import clsx from 'clsx' ;
4
+ import { connect } from 'react-redux' ;
4
5
import { withStyles } from '@material-ui/core/styles' ;
5
6
import Card from '@material-ui/core/Card' ;
6
7
import CardActionArea from '@material-ui/core/CardActionArea' ;
@@ -16,7 +17,7 @@ import ClearButton from '../space/ClearButton';
16
17
import ExportButton from '../space/ExportButton' ;
17
18
import SyncButton from '../space/SyncButton' ;
18
19
import Text from './Text' ;
19
- import { MIN_CARD_WIDTH } from '../../config/constants' ;
20
+ import { MIN_CARD_WIDTH , DEFAULT_STUDENT_MODE } from '../../config/constants' ;
20
21
import {
21
22
buildSpaceCardId ,
22
23
SPACE_DESCRIPTION_EXPAND_BUTTON_CLASS ,
@@ -56,13 +57,33 @@ const styles = theme => ({
56
57
} ) ;
57
58
58
59
export const MediaCard = props => {
59
- const { classes, image, text, viewLink, space, showActions } = props ;
60
+ const {
61
+ classes,
62
+ image,
63
+ text,
64
+ viewLink,
65
+ space,
66
+ showActions,
67
+ studentMode,
68
+ } = props ;
60
69
const { id, name } = space ;
61
70
const [ expanded , setExpanded ] = React . useState ( false ) ;
62
71
const handleExpandClick = ( ) => {
63
72
setExpanded ( ! expanded ) ;
64
73
} ;
65
74
75
+ const renderTeacherActions = ( ) => {
76
+ if ( ! studentMode ) {
77
+ return (
78
+ < >
79
+ < DeleteButton spaceId = { id } />
80
+ < SyncButton spaceId = { id } />
81
+ </ >
82
+ ) ;
83
+ }
84
+ return null ;
85
+ } ;
86
+
66
87
return (
67
88
< Card id = { buildSpaceCardId ( id ) } className = { classes . card } >
68
89
< CardActionArea className = { SPACE_CARD_LINK_CLASS } onClick = { viewLink } >
@@ -88,9 +109,8 @@ export const MediaCard = props => {
88
109
{ showActions && (
89
110
< CardActions disableSpacing >
90
111
< ClearButton spaceId = { id } />
91
- < DeleteButton spaceId = { id } />
92
112
< ExportButton space = { space } />
93
- < SyncButton spaceId = { id } />
113
+ { renderTeacherActions ( ) }
94
114
95
115
{ text && (
96
116
< IconButton
@@ -131,11 +151,19 @@ MediaCard.propTypes = {
131
151
text : PropTypes . string ,
132
152
viewLink : PropTypes . func . isRequired ,
133
153
showActions : PropTypes . bool ,
154
+ studentMode : PropTypes . bool ,
134
155
} ;
135
156
136
157
MediaCard . defaultProps = {
137
158
text : '' ,
138
159
showActions : false ,
160
+ studentMode : DEFAULT_STUDENT_MODE ,
139
161
} ;
140
162
141
- export default withStyles ( styles ) ( MediaCard ) ;
163
+ const mapStateToProps = ( { authentication } ) => ( {
164
+ studentMode : authentication . getIn ( [ 'user' , 'settings' , 'studentMode' ] ) ,
165
+ } ) ;
166
+
167
+ const ConnectedComponent = connect ( mapStateToProps , null ) ( MediaCard ) ;
168
+
169
+ export default withStyles ( styles ) ( ConnectedComponent ) ;
0 commit comments