11import Tooltip from '@codesandbox/common/lib/components/Tooltip' ;
22import { Sandbox } from '@codesandbox/common/lib/types' ;
33import noop from 'lodash/noop' ;
4- import { inject , hooksObserver } from 'app/componentConnectors ' ;
4+ import { useOvermind } from 'app/overmind ' ;
55import React from 'react' ;
66// @ts -ignore
77import HeartIcon from '-!svg-react-loader!@codesandbox/common/lib/icons/heart-open.svg' ; // eslint-disable-line import/no-webpack-loader-syntax
@@ -19,58 +19,54 @@ const MaybeTooltip = ({ loggedIn, disableTooltip, title, children }) =>
1919 children
2020 ) ;
2121
22- interface Props {
22+ interface ILikeHeartProps {
2323 sandbox : Sandbox ;
2424 className ?: string ;
2525 colorless ?: boolean ;
2626 text ?: string ;
2727 style ?: React . CSSProperties ;
2828 disableTooltip ?: boolean ;
2929 highlightHover ?: boolean ;
30- store : any ;
31- signals : any ;
3230}
3331
34- export const LikeHeart = inject ( 'store' , 'signals' ) (
35- hooksObserver (
36- ( {
37- sandbox,
38- className,
39- colorless,
40- text,
41- style,
42- disableTooltip,
43- highlightHover,
44- store : { isLoggedIn } ,
45- signals : { editor } ,
46- } : Props ) => (
47- < Container
48- style = { style }
49- hasText = { text !== undefined }
32+ export const LikeHeart : React . FC < ILikeHeartProps > = ( {
33+ sandbox,
34+ className,
35+ colorless,
36+ text,
37+ style,
38+ disableTooltip,
39+ highlightHover,
40+ } ) => {
41+ const {
42+ state : { isLoggedIn } ,
43+ actions : { editor } ,
44+ } = useOvermind ( ) ;
45+ return (
46+ < Container
47+ style = { style }
48+ hasText = { text !== undefined }
49+ loggedIn = { isLoggedIn }
50+ liked = { sandbox . userLiked }
51+ className = { className }
52+ highlightHover = { highlightHover }
53+ onClick = {
54+ isLoggedIn ? ( ) => editor . likeSandboxToggled ( { id : sandbox . id } ) : noop
55+ }
56+ >
57+ < MaybeTooltip
5058 loggedIn = { isLoggedIn }
51- liked = { sandbox . userLiked }
52- className = { className }
53- highlightHover = { highlightHover }
54- onClick = {
55- isLoggedIn
56- ? ( ) => editor . likeSandboxToggled ( { id : sandbox . id } )
57- : noop
58- }
59+ disableTooltip = { disableTooltip }
60+ title = { sandbox . userLiked ? 'Undo like' : 'Like' }
5961 >
60- < MaybeTooltip
61- loggedIn = { isLoggedIn }
62- disableTooltip = { disableTooltip }
63- title = { sandbox . userLiked ? 'Undo like' : 'Like' }
64- >
65- { sandbox . userLiked ? (
66- < FullHeartIcon style = { colorless ? null : { color : '#E01F4E' } } />
67- ) : (
68- < HeartIcon />
69- ) }
62+ { sandbox . userLiked ? (
63+ < FullHeartIcon style = { colorless ? null : { color : '#E01F4E' } } />
64+ ) : (
65+ < HeartIcon />
66+ ) }
7067
71- { text && < span > { text } </ span > }
72- </ MaybeTooltip >
73- </ Container >
74- )
75- )
76- ) ;
68+ { text && < span > { text } </ span > }
69+ </ MaybeTooltip >
70+ </ Container >
71+ ) ;
72+ } ;
0 commit comments