2020-08-08 22:17:31 +12:00
|
|
|
import React from 'react';
|
2020-08-09 21:04:07 +12:00
|
|
|
import { useSelector, useDispatch } from 'react-redux'
|
2020-08-08 22:17:31 +12:00
|
|
|
import * as coreActions from '../../services/core/actions';
|
|
|
|
|
import Icon from '../Icon';
|
2020-08-15 21:05:00 +12:00
|
|
|
import Button from '../Button';
|
2020-08-08 22:17:31 +12:00
|
|
|
|
2020-08-15 21:05:00 +12:00
|
|
|
const PinButton = ({ item }) => {
|
|
|
|
|
if (!item || !item.name) return null;
|
2020-08-08 22:17:31 +12:00
|
|
|
|
2020-08-09 21:04:07 +12:00
|
|
|
const {
|
|
|
|
|
removePinned,
|
|
|
|
|
addPinned,
|
|
|
|
|
} = coreActions;
|
2020-08-08 22:17:31 +12:00
|
|
|
|
2020-08-09 21:04:07 +12:00
|
|
|
const dispatch = useDispatch();
|
2020-08-15 21:05:00 +12:00
|
|
|
const remove = () => dispatch(removePinned(item.uri));
|
|
|
|
|
const add = () => dispatch(addPinned(item));
|
|
|
|
|
const isPinned = useSelector((state) => (
|
|
|
|
|
state.core.pinned ? state.core.pinned.find((pinnedItem) => pinnedItem.uri === item.uri) : false
|
|
|
|
|
));
|
2020-08-08 22:17:31 +12:00
|
|
|
|
2020-08-09 21:04:07 +12:00
|
|
|
if (isPinned) {
|
2020-08-08 22:17:31 +12:00
|
|
|
return (
|
2020-08-15 21:05:00 +12:00
|
|
|
<Button
|
|
|
|
|
icon
|
|
|
|
|
destructiveHover
|
2020-08-09 21:04:07 +12:00
|
|
|
onClick={remove}
|
2020-08-16 20:00:10 +12:00
|
|
|
tracking={{ category: 'PinButton', action: 'Pin' }}
|
2020-08-08 22:17:31 +12:00
|
|
|
>
|
2020-08-09 21:04:07 +12:00
|
|
|
<Icon name="star" />
|
2020-08-15 21:05:00 +12:00
|
|
|
</Button>
|
2020-08-08 22:17:31 +12:00
|
|
|
);
|
|
|
|
|
}
|
2020-08-09 21:04:07 +12:00
|
|
|
return (
|
2020-08-15 21:05:00 +12:00
|
|
|
<Button
|
|
|
|
|
icon
|
2020-08-09 21:04:07 +12:00
|
|
|
onClick={add}
|
2020-08-16 20:00:10 +12:00
|
|
|
tracking={{ category: 'PinButton', action: 'Unpin' }}
|
2020-08-09 21:04:07 +12:00
|
|
|
>
|
|
|
|
|
<Icon name="star_border" />
|
2020-08-15 21:05:00 +12:00
|
|
|
</Button>
|
2020-08-09 21:04:07 +12:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PinButton;
|