-
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.
feat: add button to show/hide item in perform
- Loading branch information
1 parent
6af5632
commit 340b04d
Showing
5 changed files
with
244 additions
and
232 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,63 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import Visibility from '@material-ui/icons/Visibility'; | ||
import VisibilityOff from '@material-ui/icons/VisibilityOff'; | ||
import { useTranslation } from 'react-i18next'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
import { MUTATION_KEYS } from '@graasp/query-client'; | ||
import { useMutation } from 'react-query'; | ||
import { hooks } from '../../config/queryClient'; | ||
import { PIN_ITEM_BUTTON_CLASS } from '../../config/selectors'; | ||
import { HIDDEN_ITEM_TAG_ID } from '../../config/constants'; | ||
|
||
const HideButton = ({ item }) => { | ||
const { t } = useTranslation(); | ||
|
||
const { data: tags } = hooks.useItemTags(item.id); | ||
const addTag = useMutation(MUTATION_KEYS.POST_ITEM_TAG); | ||
const removeTag = useMutation(MUTATION_KEYS.DELETE_ITEM_TAG); | ||
|
||
const isHidden = | ||
tags?.filter(({ tagId }) => tagId === HIDDEN_ITEM_TAG_ID).size > 0; | ||
|
||
const handlePin = () => { | ||
if (isHidden) { | ||
removeTag.mutate({ | ||
id: item.id, | ||
tagId: tags?.filter(({ tagId }) => tagId === HIDDEN_ITEM_TAG_ID).first() | ||
.id, | ||
}); | ||
} else { | ||
addTag.mutate({ | ||
id: item.id, | ||
tagId: HIDDEN_ITEM_TAG_ID, | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<Tooltip title={isHidden ? t('Unpin') : t('Pin')}> | ||
<IconButton | ||
aria-label={isHidden ? t('Unpin') : t('Pin')} | ||
className={PIN_ITEM_BUTTON_CLASS} | ||
onClick={handlePin} | ||
> | ||
{isHidden ? ( | ||
<VisibilityOff fontSize="small" /> | ||
) : ( | ||
<Visibility fontSize="small" /> | ||
)} | ||
</IconButton> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
HideButton.propTypes = { | ||
item: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
itemPath: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default HideButton; |
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
Oops, something went wrong.