Skip to content

Commit 1a1fa85

Browse files
author
Gobinath Manokaran
committed
#2621 Refactored /app/pages/Sandbox/Editor/Header/index.tsx
1 parent 263774c commit 1a1fa85

File tree

1 file changed

+86
-81
lines changed
  • packages/app/src/app/pages/Sandbox/Editor/Header

1 file changed

+86
-81
lines changed

packages/app/src/app/pages/Sandbox/Editor/Header/index.tsx

Lines changed: 86 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
dashboardUrl,
88
patronUrl,
99
} from '@codesandbox/common/lib/utils/url-generator';
10-
import { hooksObserver, inject } from 'app/componentConnectors';
1110
import { LikeHeart } from 'app/pages/common/LikeHeart';
1211
import { SignInButton } from 'app/pages/common/SignInButton';
1312
import { UserMenu } from 'app/pages/common/UserMenu';
@@ -19,6 +18,7 @@ import Fork from 'react-icons/lib/go/repo-forked';
1918
import SaveIcon from 'react-icons/lib/md/save';
2019
import SettingsIcon from 'react-icons/lib/md/settings';
2120
import ShareIcon from 'react-icons/lib/md/share';
21+
import {useOvermind} from "app/overmind";
2222
import PatronBadge from '-!svg-react-loader!@codesandbox/common/lib/utils/badges/svg/patron-4.svg';
2323

2424
import { Action } from './Buttons/Action';
@@ -35,42 +35,42 @@ import { Logo } from './Logo';
3535
import { MenuBar } from './MenuBar';
3636
import UpdateFound from './UpdateFound';
3737

38-
type ButtonProps = {
38+
interface IButtonProps {
3939
style: React.CSSProperties;
4040
secondary?: boolean;
4141
};
4242

43-
type ForkButtonProps = ButtonProps & {
43+
interface ILikeButtonProps extends IButtonProps{
44+
likeCount: number;
45+
}
46+
interface IForkButtonProps extends IButtonProps {
4447
isForking: boolean;
4548
};
4649

47-
const LikeButton = inject('store')(
48-
hooksObserver(
49-
({
50-
style,
51-
likeCount,
52-
store: { editor },
53-
}: ButtonProps & { likeCount: string; store: any }) => (
54-
<LikeHeart
55-
colorless
56-
style={style}
57-
text={likeCount}
58-
sandbox={editor.currentSandbox}
59-
disableTooltip
60-
highlightHover
61-
/>
62-
)
50+
const LikeButton : React.FC<ILikeButtonProps> = ({ style, likeCount }) => {
51+
const {
52+
state : {
53+
editor
54+
}
55+
} = useOvermind();
56+
return (
57+
<LikeHeart
58+
colorless
59+
style={style}
60+
text={likeCount.toString()}
61+
sandbox={editor.currentSandbox}
62+
disableTooltip
63+
highlightHover
64+
/>
6365
)
64-
);
65-
66-
const ForkButton = inject('signals')(
67-
hooksObserver(
68-
({
69-
secondary,
70-
isForking,
71-
style,
72-
signals: { editor },
73-
}: ForkButtonProps & { signals: any }) => (
66+
}
67+
const ForkButton : React.FC<IForkButtonProps> = ({ secondary, style, isForking } ) => {
68+
const {
69+
actions: {
70+
editor
71+
}
72+
} = useOvermind();
73+
return (
7474
<ProgressButton
7575
onClick={editor.forkSandboxClicked}
7676
style={style}
@@ -84,20 +84,19 @@ const ForkButton = inject('signals')(
8484
</>
8585
</ProgressButton>
8686
)
87-
)
88-
);
89-
90-
const PickButton = inject('store', 'signals')(
91-
hooksObserver(
92-
({
93-
secondary,
94-
style,
95-
store: { editor },
96-
signals: { explore },
97-
}: ButtonProps & { store: any; signals: any }) => {
98-
const { id, title, description } = editor.currentSandbox;
87+
}
9988

100-
return (
89+
const PickButton : React.FC<IButtonProps> = ({ style, secondary }) => {
90+
const {
91+
state: {
92+
editor
93+
},
94+
actions: {
95+
explore
96+
}
97+
} = useOvermind();
98+
const { id, title, description } = editor.currentSandbox;
99+
return (
101100
<Button
102101
onClick={() =>
103102
explore.pickSandboxModal({
@@ -115,18 +114,15 @@ const PickButton = inject('store', 'signals')(
115114
Pick
116115
</Button>
117116
);
117+
}
118+
const ShareButton : React.FC<IButtonProps> = ({ secondary, style}) => {
119+
const {
120+
actions:{
121+
modalOpened
118122
}
119-
)
120-
);
121-
122-
const ShareButton = inject('signals')(
123-
hooksObserver(
124-
({
125-
secondary,
126-
style,
127-
signals: { modalOpened },
128-
}: ButtonProps & { signals: any }) => (
129-
<Button
123+
} = useOvermind();
124+
return (
125+
<Button
130126
onClick={() => modalOpened({ modal: 'share' })}
131127
secondary={secondary}
132128
style={style}
@@ -138,23 +134,34 @@ const ShareButton = inject('signals')(
138134
</>
139135
</Button>
140136
)
141-
)
142-
);
137+
}
143138

144-
interface Props {
145-
store: any;
146-
signals: any;
139+
interface IProps {
147140
zenMode: boolean;
148141
}
149142

150-
const HeaderComponent = ({ zenMode, store, signals }: Props) => {
151-
const sandbox = store.editor.currentSandbox;
152-
const vscode = store.preferences.settings.experimentVSCode;
143+
const HeaderComponent : React.FC<IProps> = ({ zenMode }) => {
144+
const {
145+
state: {
146+
editor,
147+
preferences,
148+
hasLogIn,
149+
isLoggedIn,
150+
updateStatus,
151+
user,
152+
isPatron
153+
},
154+
actions: {
155+
modalOpened
156+
}
157+
} = useOvermind();
158+
const sandbox = editor.currentSandbox;
159+
const vscode = preferences.settings.experimentVSCode;
153160

154161
return (
155162
<Container zenMode={zenMode}>
156163
<Left>
157-
{store.hasLogIn ? (
164+
{hasLogIn ? (
158165
<DashboardLink to={dashboardUrl()}>
159166
<DashboardIcon />
160167
</DashboardLink>
@@ -169,16 +176,16 @@ const HeaderComponent = ({ zenMode, store, signals }: Props) => {
169176
{
170177
<Action
171178
onClick={
172-
store.editor.isAllModulesSynced
179+
editor.isAllModulesSynced
173180
? null
174-
: () => saveAllModules(store, signals)
181+
: () => saveAllModules()
175182
}
176183
placeholder={
177-
store.editor.isAllModulesSynced
184+
editor.isAllModulesSynced
178185
? 'All modules are saved'
179186
: false
180187
}
181-
blink={store.editor.changedModuleShortids.length > 2}
188+
blink={editor.changedModuleShortids.length > 2}
182189
title="Save"
183190
Icon={SaveIcon}
184191
/>
@@ -190,24 +197,24 @@ const HeaderComponent = ({ zenMode, store, signals }: Props) => {
190197
{sandbox.owned && (
191198
<Centered style={{ margin: '0 3rem' }}>
192199
<CollectionInfo
193-
isLoggedIn={store.isLoggedIn}
200+
isLoggedIn={isLoggedIn}
194201
// Passing a clone of observable requires it to be called in render of observer
195202
sandbox={json(sandbox)}
196203
/>
197204
</Centered>
198205
)}
199206

200207
<Right>
201-
{store.updateStatus === 'available' && (
208+
{updateStatus === 'available' && (
202209
<Action
203210
onClick={() => document.location.reload()}
204211
Icon={UpdateFound}
205212
tooltip="Update Available! Click to Refresh."
206213
/>
207214
)}
208215

209-
{!store.isLoggedIn ||
210-
(!store.isPatron && (
216+
{!isLoggedIn ||
217+
(!isPatron && (
211218
<Action
212219
href={patronUrl()}
213220
tooltip="Support CodeSandbox"
@@ -220,10 +227,10 @@ const HeaderComponent = ({ zenMode, store, signals }: Props) => {
220227
/>
221228
))}
222229

223-
{!store.isLoggedIn && (
230+
{!isLoggedIn && (
224231
<Action
225232
onClick={() =>
226-
signals.modalOpened({
233+
modalOpened({
227234
modal: 'preferences',
228235
})
229236
}
@@ -234,23 +241,23 @@ const HeaderComponent = ({ zenMode, store, signals }: Props) => {
234241

235242
<Action
236243
onClick={() =>
237-
signals.modalOpened({
244+
modalOpened({
238245
modal: 'newSandbox',
239246
})
240247
}
241248
tooltip="New Sandbox"
242249
Icon={PlusIcon}
243250
/>
244251

245-
{store.isLoggedIn && (
252+
{isLoggedIn && (
246253
<LikeButton
247254
style={{ fontSize: '.75rem', margin: '0 0.5rem' }}
248255
secondary={!sandbox.owned}
249-
likeCount={store.editor.currentSandbox.likeCount}
256+
likeCount={editor.currentSandbox.likeCount}
250257
/>
251258
)}
252259

253-
{store.user && store.user.curatorAt && (
260+
{user && user.curatorAt && (
254261
<PickButton
255262
style={{ fontSize: '.75rem', marginLeft: '0.5rem' }}
256263
secondary={sandbox.owned}
@@ -264,7 +271,7 @@ const HeaderComponent = ({ zenMode, store, signals }: Props) => {
264271

265272
<ForkButton
266273
secondary={sandbox.owned}
267-
isForking={store.editor.isForkingSandbox}
274+
isForking={editor.isForkingSandbox}
268275
style={{ fontSize: '.75rem' }}
269276
/>
270277

@@ -278,7 +285,7 @@ const HeaderComponent = ({ zenMode, store, signals }: Props) => {
278285
left={1}
279286
right={1}
280287
>
281-
{store.isLoggedIn ? (
288+
{isLoggedIn ? (
282289
<div
283290
style={{
284291
fontSize: '0.8rem',
@@ -297,6 +304,4 @@ const HeaderComponent = ({ zenMode, store, signals }: Props) => {
297304
);
298305
};
299306

300-
export const Header = inject('signals', 'store')(
301-
hooksObserver(HeaderComponent)
302-
);
307+
export default HeaderComponent

0 commit comments

Comments
 (0)