Skip to content

Commit 3ae8674

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
🔨 Switch Title to use useOvermind (#2561)
1 parent 22675e2 commit 3ae8674

File tree

1 file changed

+68
-70
lines changed
  • packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/Title

1 file changed

+68
-70
lines changed
Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,78 @@
1-
import React, { useState } from 'react';
2-
import { inject, hooksObserver } from 'app/componentConnectors';
31
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
42
import { ESC, ENTER } from '@codesandbox/common/lib/utils/keycodes';
3+
import React, { FunctionComponent, useState } from 'react';
4+
5+
import { useOvermind } from 'app/overmind';
6+
57
import { WorkspaceInputContainer } from '../../elements';
8+
69
import { EditPen } from '../elements';
10+
711
import { SandboxTitle } from './elements';
812

9-
type ITitleProps = {
13+
type Props = {
1014
editable: boolean;
11-
store: any;
12-
signals: any;
1315
};
14-
15-
export const Title = inject('store', 'signals')(
16-
hooksObserver(
17-
({
18-
editable,
19-
store: {
20-
editor: { currentSandbox },
21-
workspace: {
22-
project: { title },
23-
},
24-
},
25-
signals: {
26-
workspace: { valueChanged, sandboxInfoUpdated },
16+
export const Title: FunctionComponent<Props> = ({ editable }) => {
17+
const {
18+
actions: {
19+
workspace: { valueChanged, sandboxInfoUpdated },
20+
},
21+
state: {
22+
editor: { currentSandbox },
23+
workspace: {
24+
project: { title },
2725
},
28-
}: ITitleProps) => {
29-
const [editing, setEditing] = useState(false);
26+
},
27+
} = useOvermind();
28+
const [editing, setEditing] = useState(false);
3029

31-
return editing ? (
32-
<WorkspaceInputContainer style={{ margin: '0 -0.25rem' }}>
33-
<input
34-
type="text"
35-
placeholder="Title"
36-
ref={el => {
37-
if (el) {
38-
el.focus();
39-
}
40-
}}
41-
value={title}
42-
onChange={event => {
43-
valueChanged({
44-
field: 'title',
45-
value: event.target.value,
46-
});
47-
}}
48-
onBlur={() => {
49-
sandboxInfoUpdated();
50-
setEditing(false);
51-
}}
52-
onKeyUp={event => {
53-
if (event.keyCode === ENTER) {
54-
sandboxInfoUpdated();
55-
setEditing(false);
56-
} else if (event.keyCode === ESC) {
57-
setEditing(false);
58-
}
59-
}}
60-
/>
61-
</WorkspaceInputContainer>
62-
) : (
63-
<SandboxTitle>
64-
{getSandboxName(currentSandbox)}
65-
{editable && (
66-
<EditPen
67-
onClick={() => {
68-
valueChanged({
69-
field: 'title',
70-
value: getSandboxName(currentSandbox),
71-
});
72-
setEditing(true);
73-
}}
74-
/>
75-
)}
76-
</SandboxTitle>
77-
);
78-
}
79-
)
80-
);
30+
return editing ? (
31+
<WorkspaceInputContainer style={{ margin: '0 -0.25rem' }}>
32+
<input
33+
type="text"
34+
placeholder="Title"
35+
ref={el => {
36+
if (el) {
37+
el.focus();
38+
}
39+
}}
40+
value={title}
41+
onChange={event => {
42+
valueChanged({
43+
field: 'title',
44+
value: event.target.value,
45+
});
46+
}}
47+
onBlur={() => {
48+
sandboxInfoUpdated();
49+
setEditing(false);
50+
}}
51+
onKeyUp={event => {
52+
if (event.keyCode === ENTER) {
53+
sandboxInfoUpdated();
54+
setEditing(false);
55+
} else if (event.keyCode === ESC) {
56+
setEditing(false);
57+
}
58+
}}
59+
/>
60+
</WorkspaceInputContainer>
61+
) : (
62+
<SandboxTitle>
63+
{getSandboxName(currentSandbox)}
64+
65+
{editable && (
66+
<EditPen
67+
onClick={() => {
68+
valueChanged({
69+
field: 'title',
70+
value: getSandboxName(currentSandbox),
71+
});
72+
setEditing(true);
73+
}}
74+
/>
75+
)}
76+
</SandboxTitle>
77+
);
78+
};

0 commit comments

Comments
 (0)