Skip to content

Commit 3321ac5

Browse files
vanya829Saeris
authored andcommitted
🔨 Switch LikeHeart to use useOvermind (#2635)
* Add @vanya829 as a contributor * refactor LikeHeart to functional component * convert likeCount to string to match typing * refactor LikeHeart to functional component convert likeCount to string to match typing
1 parent d074b2e commit 3321ac5

File tree

2 files changed

+41
-45
lines changed

2 files changed

+41
-45
lines changed

‎packages/app/src/app/pages/Sandbox/Editor/Header/Buttons/LikeButton/LikeButton.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const LikeButton: FunctionComponent = () => {
1414
return (
1515
<LikeHeart
1616
colorless
17-
text={currentSandbox.likeCount}
17+
text={String(currentSandbox.likeCount)}
1818
sandbox={currentSandbox}
1919
disableTooltip
2020
highlightHover
Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Tooltip from '@codesandbox/common/lib/components/Tooltip';
22
import { Sandbox } from '@codesandbox/common/lib/types';
33
import noop from 'lodash/noop';
4-
import { inject, hooksObserver } from 'app/componentConnectors';
4+
import { useOvermind } from 'app/overmind';
55
import React from 'react';
66
// @ts-ignore
77
import 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

Comments
 (0)