Skip to content

Commit d4673e1

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
🔨 Switch Description to use useOvermind (#2565)
1 parent 3ae8674 commit d4673e1

File tree

1 file changed

+57
-59
lines changed
  • packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/Description

1 file changed

+57
-59
lines changed
Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,68 @@
1-
import React, { useState } from 'react';
2-
import { inject, hooksObserver } from 'app/componentConnectors';
1+
import { ENTER } from '@codesandbox/common/lib/utils/keycodes';
2+
import React, { FunctionComponent, useState } from 'react';
3+
4+
import { useOvermind } from 'app/overmind';
35

46
import { WorkspaceInputContainer } from '../../elements';
7+
58
import { EditPen } from '../elements';
9+
610
import { SandboxDescription } from './elements';
711

8-
interface IDescriptionProps {
12+
type Props = {
913
editable: boolean;
10-
store: any;
11-
signals: any;
12-
}
13-
14-
export const Description = inject('store', 'signals')(
15-
hooksObserver(
16-
({
17-
editable,
18-
signals: {
19-
workspace: { sandboxInfoUpdated, valueChanged },
14+
};
15+
export const Description: FunctionComponent<Props> = ({ editable }) => {
16+
const {
17+
actions: {
18+
workspace: { sandboxInfoUpdated, valueChanged },
19+
},
20+
state: {
21+
workspace: {
22+
project: { description },
2023
},
21-
store: {
22-
workspace: {
23-
project: { description },
24-
},
25-
},
26-
}: IDescriptionProps) => {
27-
const [editing, setEditing] = useState(false);
24+
},
25+
} = useOvermind();
26+
const [editing, setEditing] = useState(false);
27+
28+
const onKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
29+
if (event.keyCode === ENTER && !event.shiftKey) {
30+
event.preventDefault();
31+
event.stopPropagation();
32+
sandboxInfoUpdated();
33+
setEditing(false);
34+
}
35+
};
2836

29-
const onKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
30-
if (event.keyCode === 13 && !event.shiftKey) {
31-
event.preventDefault();
32-
event.stopPropagation();
37+
return editing ? (
38+
<WorkspaceInputContainer style={{ margin: '0 -0.25rem' }}>
39+
<textarea
40+
rows={2}
41+
placeholder="Description"
42+
value={description}
43+
ref={el => {
44+
if (el) {
45+
el.focus();
46+
}
47+
}}
48+
onKeyDown={onKeyDown}
49+
onChange={event => {
50+
valueChanged({
51+
field: 'description',
52+
value: event.target.value,
53+
});
54+
}}
55+
onBlur={() => {
3356
sandboxInfoUpdated();
3457
setEditing(false);
35-
}
36-
};
58+
}}
59+
/>
60+
</WorkspaceInputContainer>
61+
) : (
62+
<SandboxDescription empty={Boolean(description)}>
63+
{description || (editable ? 'No description, create one!' : '')}
3764

38-
return editing ? (
39-
<WorkspaceInputContainer style={{ margin: '0 -0.25rem' }}>
40-
<textarea
41-
rows={2}
42-
placeholder="Description"
43-
value={description}
44-
ref={el => {
45-
if (el) {
46-
el.focus();
47-
}
48-
}}
49-
onKeyDown={onKeyDown}
50-
onChange={event => {
51-
valueChanged({
52-
field: 'description',
53-
value: event.target.value,
54-
});
55-
}}
56-
onBlur={() => {
57-
sandboxInfoUpdated();
58-
setEditing(false);
59-
}}
60-
/>
61-
</WorkspaceInputContainer>
62-
) : (
63-
<SandboxDescription empty={description}>
64-
{description || (editable ? 'No description, create one!' : '')}
65-
{editable && <EditPen onClick={() => setEditing(true)} />}
66-
</SandboxDescription>
67-
);
68-
}
69-
)
70-
);
65+
{editable && <EditPen onClick={() => setEditing(true)} />}
66+
</SandboxDescription>
67+
);
68+
};

0 commit comments

Comments
 (0)