|
1 | | -import { inject, hooksObserver } from 'app/componentConnectors'; |
2 | | -import React, { useState } from 'react'; |
| 1 | +import { ESC } from '@codesandbox/common/lib/utils/keycodes'; |
| 2 | +import React, { FunctionComponent, useState } from 'react'; |
| 3 | + |
| 4 | +import { useOvermind } from 'app/overmind'; |
3 | 5 |
|
4 | 6 | import { WorkspaceInputContainer } from '../../elements'; |
5 | 7 |
|
6 | 8 | import { EditPen } from '../elements'; |
7 | 9 |
|
8 | 10 | import { SandboxAlias } from './elements'; |
9 | 11 |
|
10 | | -type IAliasProps = { |
| 12 | +type Props = { |
11 | 13 | editable: boolean; |
12 | | - store: any; |
13 | | - signals: any; |
14 | 14 | }; |
| 15 | +export const Alias: FunctionComponent<Props> = ({ editable }) => { |
| 16 | + const { |
| 17 | + actions: { |
| 18 | + workspace: { sandboxInfoUpdated, valueChanged }, |
| 19 | + }, |
| 20 | + state: { |
| 21 | + isPatron, |
| 22 | + editor: { currentSandbox }, |
| 23 | + workspace: { project }, |
| 24 | + }, |
| 25 | + } = useOvermind(); |
| 26 | + const [editing, setEditing] = useState(false); |
15 | 27 |
|
16 | | -export const Alias = inject('store', 'signals')( |
17 | | - hooksObserver( |
18 | | - ({ |
19 | | - editable, |
20 | | - signals: { |
21 | | - workspace: { sandboxInfoUpdated, valueChanged }, |
22 | | - }, |
23 | | - store: { |
24 | | - isPatron, |
25 | | - editor: { currentSandbox }, |
26 | | - workspace: { project }, |
27 | | - }, |
28 | | - }: IAliasProps) => { |
29 | | - const [editing, setEditing] = useState(false); |
30 | | - |
31 | | - const alias = project.alias || currentSandbox.alias; |
| 28 | + const alias = project.alias || currentSandbox.alias; |
32 | 29 |
|
33 | | - return isPatron ? ( |
34 | | - <> |
35 | | - {editing ? ( |
36 | | - <WorkspaceInputContainer> |
37 | | - <input |
38 | | - value={alias} |
39 | | - onChange={event => { |
40 | | - valueChanged({ |
41 | | - field: 'alias', |
42 | | - value: event.target.value, |
43 | | - }); |
44 | | - }} |
45 | | - type="text" |
46 | | - onBlur={() => { |
47 | | - sandboxInfoUpdated(); |
48 | | - setEditing(false); |
49 | | - }} |
50 | | - onKeyUp={event => { |
51 | | - if (event.keyCode === 13) { |
52 | | - sandboxInfoUpdated(); |
53 | | - setEditing(false); |
54 | | - } |
55 | | - }} |
56 | | - ref={el => { |
57 | | - if (el) { |
58 | | - el.focus(); |
59 | | - } |
60 | | - }} |
61 | | - placeholder="Alias" |
62 | | - /> |
63 | | - </WorkspaceInputContainer> |
64 | | - ) : ( |
65 | | - <SandboxAlias> |
66 | | - {alias} |
67 | | - {editable && <EditPen onClick={() => setEditing(true)} />} |
68 | | - </SandboxAlias> |
69 | | - )} |
70 | | - </> |
71 | | - ) : null; |
72 | | - } |
73 | | - ) |
74 | | -); |
| 30 | + return isPatron ? ( |
| 31 | + <> |
| 32 | + {editing ? ( |
| 33 | + <WorkspaceInputContainer> |
| 34 | + <input |
| 35 | + value={alias} |
| 36 | + onChange={event => { |
| 37 | + valueChanged({ |
| 38 | + field: 'alias', |
| 39 | + value: event.target.value, |
| 40 | + }); |
| 41 | + }} |
| 42 | + type="text" |
| 43 | + onBlur={() => { |
| 44 | + sandboxInfoUpdated(); |
| 45 | + setEditing(false); |
| 46 | + }} |
| 47 | + onKeyUp={event => { |
| 48 | + if (event.keyCode === ESC) { |
| 49 | + sandboxInfoUpdated(); |
| 50 | + setEditing(false); |
| 51 | + } |
| 52 | + }} |
| 53 | + ref={el => { |
| 54 | + if (el) { |
| 55 | + el.focus(); |
| 56 | + } |
| 57 | + }} |
| 58 | + placeholder="Alias" |
| 59 | + /> |
| 60 | + </WorkspaceInputContainer> |
| 61 | + ) : ( |
| 62 | + <SandboxAlias> |
| 63 | + {alias} |
| 64 | + {editable && <EditPen onClick={() => setEditing(true)} />} |
| 65 | + </SandboxAlias> |
| 66 | + )} |
| 67 | + </> |
| 68 | + ) : null; |
| 69 | +}; |
0 commit comments