|
1 | | -import React, { useState } from 'react'; |
2 | | -import { inject, hooksObserver } from 'app/componentConnectors'; |
3 | 1 | import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name'; |
4 | 2 | import { ESC, ENTER } from '@codesandbox/common/lib/utils/keycodes'; |
| 3 | +import React, { FunctionComponent, useState } from 'react'; |
| 4 | + |
| 5 | +import { useOvermind } from 'app/overmind'; |
| 6 | + |
5 | 7 | import { WorkspaceInputContainer } from '../../elements'; |
| 8 | + |
6 | 9 | import { EditPen } from '../elements'; |
| 10 | + |
7 | 11 | import { SandboxTitle } from './elements'; |
8 | 12 |
|
9 | | -type ITitleProps = { |
| 13 | +type Props = { |
10 | 14 | editable: boolean; |
11 | | - store: any; |
12 | | - signals: any; |
13 | 15 | }; |
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 }, |
27 | 25 | }, |
28 | | - }: ITitleProps) => { |
29 | | - const [editing, setEditing] = useState(false); |
| 26 | + }, |
| 27 | + } = useOvermind(); |
| 28 | + const [editing, setEditing] = useState(false); |
30 | 29 |
|
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