/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { Button } from '@wordpress/components'; import { NAVIGATION_STORE_NAME } from '@woocommerce/data'; import { recordEvent } from '@woocommerce/tracks'; import { useDispatch, useSelect } from '@wordpress/data'; import { Icon, starEmpty, starFilled } from '@wordpress/icons'; /** * Internal dependencies */ import './style.scss'; export const FavoriteButton = ( { id } ) => { const { favorites, isResolving } = useSelect( ( select ) => { return { favorites: select( NAVIGATION_STORE_NAME ).getFavorites(), isResolving: select( NAVIGATION_STORE_NAME ).isResolving( 'getFavorites' ), }; } ); const { addFavorite, removeFavorite } = useDispatch( NAVIGATION_STORE_NAME ); const isFavorited = favorites.includes( id ); const toggleFavorite = () => { const toggle = isFavorited ? removeFavorite : addFavorite; toggle( id ); recordEvent( 'navigation_favorite', { id, action: isFavorited ? 'unfavorite' : 'favorite', } ); }; if ( isResolving ) { return null; } return ( ); }; export default FavoriteButton;