-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5c8b4a
commit eef97dd
Showing
8 changed files
with
154 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useContext } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import ExploreIcon from '@material-ui/icons/Explore'; | ||
import { useTranslation } from 'react-i18next'; | ||
import CloseIcon from '@material-ui/icons/Close'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
import { | ||
buildPublishButtonId, | ||
PUBLISH_ITEM_BUTTON_CLASS, | ||
} from '../../config/selectors'; | ||
import { LayoutContext } from '../context/LayoutContext'; | ||
|
||
const PublishButton = ({ itemId }) => { | ||
const { t } = useTranslation(); | ||
const { setIsItemPublishOpen, isItemPublishOpen } = useContext(LayoutContext); | ||
|
||
const onClick = () => { | ||
setIsItemPublishOpen(!isItemPublishOpen); | ||
}; | ||
|
||
return ( | ||
<Tooltip title={t('Share')}> | ||
<IconButton | ||
aria-label="share" | ||
className={PUBLISH_ITEM_BUTTON_CLASS} | ||
onClick={onClick} | ||
id={buildPublishButtonId(itemId)} | ||
> | ||
{isItemPublishOpen ? <CloseIcon /> : <ExploreIcon fontSize="small" />} | ||
</IconButton> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
PublishButton.propTypes = { | ||
itemId: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default PublishButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useContext, useEffect } from 'react'; | ||
import Container from '@material-ui/core/Container'; | ||
import PropTypes from 'prop-types'; | ||
import { Map } from 'immutable'; | ||
import { Loader } from '@graasp/ui'; | ||
import { makeStyles } from '@material-ui/core'; | ||
import { isItemUpdateAllowedForUser } from '../../../utils/membership'; | ||
import { LayoutContext } from '../../context/LayoutContext'; | ||
import { CurrentUserContext } from '../../context/CurrentUserContext'; | ||
import ItemPublishConfiguration from '../sharing/ItemPublishConfiguration'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
wrapper: { | ||
marginTop: theme.spacing(2), | ||
}, | ||
})); | ||
|
||
const ItemPublishTab = ({ item, memberships }) => { | ||
const classes = useStyles(); | ||
const { data: currentMember, isLoadingCurrentMember } = | ||
useContext(CurrentUserContext); | ||
const { setIsItemPublishOpen } = useContext(LayoutContext); | ||
|
||
const canEdit = isItemUpdateAllowedForUser({ | ||
memberships, | ||
memberId: currentMember?.get('id'), | ||
}); | ||
|
||
useEffect( | ||
() => () => { | ||
setIsItemPublishOpen(false); | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[], | ||
); | ||
|
||
if (isLoadingCurrentMember) { | ||
return <Loader />; | ||
} | ||
|
||
return ( | ||
<Container disableGutters className={classes.wrapper}> | ||
<ItemPublishConfiguration item={item} edit={canEdit} /> | ||
</Container> | ||
); | ||
}; | ||
ItemPublishTab.propTypes = { | ||
item: PropTypes.instanceOf(Map).isRequired, | ||
memberships: PropTypes.arrayOf(PropTypes.shape({})).isRequired, | ||
}; | ||
export default ItemPublishTab; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters