Skip to content

Commit 13c6b7e

Browse files
committed
Merge branch 'master' of github.com:codesandbox/codesandbox-client
2 parents c3f2486 + efc23ba commit 13c6b7e

File tree

7 files changed

+155
-39
lines changed

7 files changed

+155
-39
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/DirectoryChildren/index.js renamed to packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/DirectoryChildren/index.tsx

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,53 @@
11
import { HIDDEN_DIRECTORIES } from '@codesandbox/common/lib/templates/constants/files';
2-
import { inject, observer } from 'app/componentConnectors';
2+
import { Module, Directory } from '@codesandbox/common/lib/types';
3+
import { useOvermind } from 'app/overmind';
34
import { sortBy } from 'lodash-es';
45
import * as React from 'react';
5-
6-
import ModuleEntry from './ModuleEntry';
76
import DirectoryEntry from '..';
7+
import ModuleEntry from './ModuleEntry';
88

9-
const DirectoryChildren = ({
9+
interface IDirectoryChildrenProps {
10+
depth: number;
11+
renameModule: (title: string, moduleShortid: string) => void;
12+
setCurrentModule: (id: string) => void;
13+
parentShortid: string;
14+
deleteEntry: (shortid: string, title: string) => void;
15+
isInProjectView: boolean;
16+
markTabsNotDirty: () => void;
17+
discardModuleChanges: (shortid: string) => void;
18+
getModulePath: (
19+
modules: Module[],
20+
directories: Directory[],
21+
id: string
22+
) => string;
23+
renameValidator: (id: string, title: string) => boolean;
24+
}
25+
26+
const DirectoryChildren: React.FC<IDirectoryChildrenProps> = ({
1027
depth = 0,
1128
renameModule,
1229
setCurrentModule,
1330
parentShortid,
1431
deleteEntry,
1532
isInProjectView,
1633
markTabsNotDirty,
17-
store,
1834
discardModuleChanges,
1935
getModulePath,
20-
signals,
2136
renameValidator,
2237
}) => {
38+
const {
39+
state: {
40+
editor: { currentSandbox, mainModule, currentModuleShortid },
41+
},
42+
actions: { files, editor },
43+
} = useOvermind();
44+
2345
const {
2446
id: sandboxId,
2547
modules,
2648
directories,
2749
template: sandboxTemplate,
28-
} = store.editor.currentSandbox;
29-
const { mainModule, currentModuleShortid } = store.editor;
30-
const mainModuleId = mainModule.id;
50+
} = currentSandbox;
3151

3252
return (
3353
<div>
@@ -44,15 +64,13 @@ const DirectoryChildren = ({
4464
key={dir.id}
4565
siblings={[...directories, ...modules]}
4666
depth={depth + 1}
47-
signals={
48-
signals /* TODO: Just pass what is needed by the DragDrop */
49-
}
67+
signals={{ files, editor }}
5068
id={dir.id}
5169
shortid={dir.shortid}
5270
title={dir.title}
5371
sandboxId={sandboxId}
5472
sandboxTemplate={sandboxTemplate}
55-
mainModuleId={mainModuleId}
73+
mainModuleId={mainModule.id}
5674
modules={modules}
5775
directories={directories}
5876
currentModuleShortid={currentModuleShortid}
@@ -82,4 +100,4 @@ const DirectoryChildren = ({
82100
);
83101
};
84102

85-
export default inject('store', 'signals')(observer(DirectoryChildren));
103+
export default DirectoryChildren;

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EntryIcons/elements.js renamed to packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EntryIcons/elements.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import styled from 'styled-components';
22

3-
export const RedIcon = styled.span`
3+
export const RedIcon = styled.span<{
4+
width: number;
5+
height: number;
6+
}>`
47
color: ${props => props.theme.red};
58
width: ${props => props.width}px;
69
height: ${props => props.height}px;
710
`;
811

9-
export const SVGIcon = styled.span`
12+
export const SVGIcon = styled.span<{
13+
url: string;
14+
width: number;
15+
height: number;
16+
}>`
1017
background-image: url(${props => props.url});
1118
background-size: ${props => props.width}px;
1219
background-position: 0;

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EntryIcons/index.js renamed to packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EntryIcons/index.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import React, { Component } from 'react';
2-
32
import ErrorIcon from 'react-icons/lib/md/error';
43

54
import { RedIcon, SVGIcon } from './elements';
65
import getIconURL from './GetIconURL';
76

8-
class GetIcon extends Component {
7+
type Props = {
8+
type: string;
9+
width?: number;
10+
height?: number;
11+
error?: boolean;
12+
};
13+
14+
class GetIcon extends Component<Props> {
915
state = { icon: null };
1016

1117
getIcon = async type => {
@@ -27,36 +33,29 @@ class GetIcon extends Component {
2733
}
2834

2935
render() {
30-
const { type, error, width, height } = this.props;
36+
const { error, width, height } = this.props;
3137
const { icon } = this.state;
3238

3339
if (error) {
3440
return (
35-
<RedIcon>
41+
<RedIcon width={width} height={height}>
3642
<ErrorIcon width={width} height={height} />
3743
</RedIcon>
3844
);
3945
}
40-
return <SVGIcon url={icon} type={type} width={width} height={height} />;
46+
return <SVGIcon url={icon} width={width} height={height} />;
4147
}
4248
}
4349

44-
function EntryIcon({
50+
const EntryIcon: React.FC<Props> = ({
4551
type,
4652
width = 16,
4753
height = 16,
4854
error,
49-
}: {
50-
type: string,
51-
width?: number,
52-
height?: number,
53-
error?: boolean,
54-
}) {
55-
return (
56-
<div style={{ display: 'inline-block', verticalAlign: 'middle' }}>
57-
<GetIcon type={type} error={error} width={width} height={height} />
58-
</div>
59-
);
60-
}
55+
}) => (
56+
<div style={{ display: 'inline-block', verticalAlign: 'middle' }}>
57+
<GetIcon type={type} error={error} width={width} height={height} />
58+
</div>
59+
);
6160

6261
export default EntryIcon;

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/elements.js renamed to packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/elements.ts

File renamed without changes.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { getModulePath } from '@codesandbox/common/lib/sandbox/modules';
2+
import { ModuleTab } from '@codesandbox/common/lib/types';
3+
import { useOvermind } from 'app/overmind';
4+
import EntryIcons from 'app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EntryIcons';
5+
import { saveAllModules } from 'app/store/modules/editor/utils';
6+
// eslint-disable-next-line import/extensions
7+
import getType from 'app/utils/get-type.ts';
8+
import React from 'react';
9+
import CrossIcon from 'react-icons/lib/md/clear';
10+
import { EntryContainer } from '../elements';
11+
import { WorkspaceItem } from '../WorkspaceItem';
12+
import { CrossIconContainer, Dir, Title } from './elements';
13+
import SaveIcon from './SaveIcon';
14+
15+
export const OpenedTabs: React.FC = () => {
16+
const { state, actions } = useOvermind();
17+
const sandbox = state.editor.currentSandbox;
18+
const { currentModuleShortid } = state.editor;
19+
const moduleObject = {};
20+
sandbox.modules.forEach(m => {
21+
moduleObject[m.shortid] = m;
22+
});
23+
24+
const openModules = (state.editor.tabs as ModuleTab[])
25+
.map(t => moduleObject[t.moduleShortid])
26+
.filter(x => x);
27+
28+
return (
29+
<WorkspaceItem
30+
title="Open Tabs"
31+
actions={
32+
<SaveIcon
33+
disabled={state.editor.isAllModulesSynced}
34+
onClick={e => {
35+
if (e) {
36+
e.preventDefault();
37+
e.stopPropagation();
38+
}
39+
saveAllModules(state, actions);
40+
}}
41+
/>
42+
}
43+
>
44+
{openModules.map((m, i) => (
45+
<EntryContainer
46+
onClick={() => {
47+
actions.editor.moduleSelected({ id: m.id });
48+
}}
49+
active={currentModuleShortid === m.shortid}
50+
key={m.id}
51+
>
52+
<EntryIcons
53+
type={getType(m.title)}
54+
error={m.errors && m.errors.length > 0}
55+
/>
56+
<Title>{m.title}</Title>
57+
<Dir>
58+
{getModulePath(sandbox.modules, sandbox.directories, m.id)
59+
.replace('/', '')
60+
.replace(new RegExp(m.title + '$'), '')}
61+
</Dir>
62+
{currentModuleShortid !== m.shortid && (
63+
<CrossIconContainer
64+
onClick={e => {
65+
if (e) {
66+
e.preventDefault();
67+
e.stopPropagation();
68+
}
69+
70+
actions.editor.tabClosed(i);
71+
}}
72+
>
73+
<CrossIcon />
74+
</CrossIconContainer>
75+
)}
76+
</EntryContainer>
77+
))}
78+
</WorkspaceItem>
79+
);
80+
};

packages/app/src/app/pages/Sandbox/Editor/Workspace/WorkspaceItem/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Props = {
1515
keepState?: boolean;
1616
disabled?: boolean;
1717
defaultOpen?: boolean;
18-
actions?: React.Component<any, any>;
18+
actions?: React.ReactNode;
1919
style?: React.CSSProperties;
2020
showOverflow?: boolean;
2121
};

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
import styled from 'styled-components';
21
import fadeIn from '@codesandbox/common/lib/utils/animation/fade-in';
2+
import styled from 'styled-components';
3+
4+
type ContainerStylesProps = {
5+
theme?: any;
6+
color?: string;
7+
alternative?: boolean;
8+
noTransition?: boolean;
9+
depth?: number;
10+
active?: boolean;
11+
editing?: boolean;
12+
nameValidationError?: string;
13+
rightColors?: string[];
14+
};
315

4-
export const getContainerStyles = props => {
16+
export const getContainerStyles = (props: ContainerStylesProps) => {
517
const { theme } = props;
618
const getSelectedColor = activeColor => {
719
// some have active as full white and should never be
@@ -94,7 +106,7 @@ export const getContainerStyles = props => {
94106
return styles;
95107
};
96108

97-
export const EntryContainer = styled.div`
109+
export const EntryContainer = styled.div<ContainerStylesProps>`
98110
${props => getContainerStyles(props)};
99111
`;
100112

@@ -152,7 +164,7 @@ export const IconArea = styled.div`
152164
${fadeIn(0)};
153165
`;
154166

155-
export const WorkspaceInputContainer = styled.div`
167+
export const WorkspaceInputContainer = styled.div<{ errorMessage?: string }>`
156168
display: inline-block;
157169
display: flex;
158170
overflow: visible;

0 commit comments

Comments
 (0)