Skip to content

Commit 8d11130

Browse files
🔨 Refactor, 🧠 Overmind | /app/pages/Sandbox/Editor/Workspace/… (codesandbox#2826)
🔨 Refactor, 🧠 Overmind | /app/pages/Sandbox/Editor/Workspace/items/ConfigurationFiles/index.js
2 parents 3321ac5 + 22c259b commit 8d11130

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/ConfigurationFiles/elements.js renamed to packages/app/src/app/pages/Sandbox/Editor/Workspace/items/ConfigurationFiles/elements.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import styled from 'styled-components';
1+
import styled, { css } from 'styled-components';
22

33
export const FilesContainer = styled.div`
44
margin-top: 1rem;
55
`;
66

7-
export const File = styled.div`
8-
position: relative;
9-
transition: 0.3s ease background-color;
10-
padding: 0.75rem 1rem;
7+
export const File = styled.div<{ created: boolean }>`
8+
${({ created }) => css`
9+
position: relative;
10+
transition: 0.3s ease background-color;
11+
padding: 0.75rem 1rem;
1112
12-
${props => props.created && `cursor: pointer`};
13-
${props => !props.created && `opacity: 0.9`};
13+
${created && `cursor: pointer`};
14+
${!created && `opacity: 0.9`};
15+
`}
1416
`;
1517

1618
export const CreateButton = styled.button`

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/ConfigurationFiles/index.js renamed to packages/app/src/app/pages/Sandbox/Editor/Workspace/items/ConfigurationFiles/index.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import getUI from '@codesandbox/common/lib/templates/configuration/ui';
44
import { Module, Configuration } from '@codesandbox/common/lib/types';
55
import { resolveModule } from '@codesandbox/common/lib/sandbox/modules';
66

7-
import { inject, observer } from 'app/componentConnectors';
7+
import { useOvermind } from 'app/overmind';
88

99
import BookIcon from 'react-icons/lib/md/library-books';
1010
import UIIcon from 'react-icons/lib/md/dvr';
@@ -21,12 +21,13 @@ import {
2121
} from './elements';
2222

2323
type FileConfigProps = {
24-
path: string,
24+
path: string;
2525
info: {
26-
module?: Module,
27-
config: Configuration,
28-
},
29-
createModule: (title: string) => void,
26+
module?: Module;
27+
config: Configuration;
28+
};
29+
createModule?: (title: string) => void;
30+
openModule?: (id: string) => void;
3031
};
3132

3233
const FileConfig = ({
@@ -82,8 +83,13 @@ const FileConfig = ({
8283
);
8384
};
8485

85-
const ConfigurationFiles = ({ store, signals }) => {
86-
const sandbox = store.editor.currentSandbox;
86+
const ConfigurationFiles = () => {
87+
const {
88+
state,
89+
actions: { files, editor },
90+
} = useOvermind();
91+
92+
const sandbox = state.editor.currentSandbox;
8793
const { configurationFiles } = getDefinition(sandbox.template);
8894

8995
const createdPaths = {};
@@ -123,7 +129,7 @@ const ConfigurationFiles = ({ store, signals }) => {
123129
<FileConfig
124130
key={path}
125131
openModule={id => {
126-
signals.editor.moduleSelected({ id });
132+
editor.moduleSelected({ id });
127133
}}
128134
path={path}
129135
info={info}
@@ -140,7 +146,7 @@ const ConfigurationFiles = ({ store, signals }) => {
140146
<FileConfig
141147
key={path}
142148
createModule={title => {
143-
signals.files.moduleCreated({ title });
149+
files.moduleCreated({ title, directoryShortid: null });
144150
}}
145151
path={path}
146152
info={info}
@@ -152,4 +158,4 @@ const ConfigurationFiles = ({ store, signals }) => {
152158
);
153159
};
154160

155-
export default inject('signals', 'store')(observer(ConfigurationFiles));
161+
export default ConfigurationFiles;

‎packages/common/src/types/index.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ export type Module = {
6161
type: 'file';
6262
};
6363

64+
export type Configuration = {
65+
title: string;
66+
moreInfoUrl: string;
67+
type: string;
68+
description: string;
69+
};
70+
6471
export type Directory = {
6572
id: string;
6673
title: string;

0 commit comments

Comments
 (0)