Skip to content

Commit 0a33587

Browse files
authored
Improve performance of switching files (codesandbox#4014)
1 parent 4dbb7a9 commit 0a33587

File tree

2 files changed

+94
-79
lines changed

2 files changed

+94
-79
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import * as React from 'react';
2+
import css from '@styled-system/css';
3+
4+
import Tooltip from '@codesandbox/common/lib/components/Tooltip';
5+
import getTemplateDefinition from '@codesandbox/common/lib/templates';
6+
import { Icons } from 'app/components/CodeEditor/elements';
7+
import { useOvermind } from 'app/overmind';
8+
import QuestionIcon from 'react-icons/lib/go/question';
9+
10+
import { LiveUser } from '@codesandbox/common/lib/types';
11+
import { Stack } from '@codesandbox/components';
12+
13+
export const EditorToast = () => {
14+
const { state } = useOvermind();
15+
16+
const sandbox = state.editor.currentSandbox;
17+
const { currentModule } = state.editor;
18+
const modulePath = currentModule.path;
19+
const template = sandbox && getTemplateDefinition(sandbox.template);
20+
const config = template && template.configurationFiles[modulePath];
21+
22+
const followingUserId = state.live.followingUserId;
23+
let followingUser: LiveUser | undefined;
24+
25+
if (followingUserId && state.live.roomInfo && state.live.isLive) {
26+
followingUser = state.live.roomInfo.users.find(
27+
u => u.id === followingUserId
28+
);
29+
}
30+
31+
return (
32+
<Stack
33+
css={css({
34+
position: 'absolute',
35+
top: 34,
36+
zIndex: 45,
37+
right: 0,
38+
})}
39+
gap={1}
40+
direction="vertical"
41+
align="flex-end"
42+
>
43+
{followingUser && (
44+
<div
45+
css={{
46+
transition: '0.3s ease opacity',
47+
background: `rgb(${followingUser.color.join(',')})`,
48+
padding: '2px 8px',
49+
fontSize: '12px',
50+
float: 'right',
51+
width: 'max-content',
52+
borderBottomLeftRadius: 2,
53+
color:
54+
(followingUser.color[0] * 299 +
55+
followingUser.color[1] * 587 +
56+
followingUser.color[2] * 114) /
57+
1000 >
58+
128
59+
? 'rgba(0, 0, 0, 0.8)'
60+
: 'white',
61+
62+
':hover': {
63+
opacity: 0.5,
64+
},
65+
}}
66+
>
67+
Following {followingUser.username}
68+
</div>
69+
)}
70+
71+
{config ? (
72+
<Icons>
73+
{config.partialSupportDisclaimer ? (
74+
<Tooltip
75+
placement="bottom"
76+
content={config.partialSupportDisclaimer}
77+
style={{
78+
display: 'flex',
79+
'align-items': 'center',
80+
}}
81+
>
82+
Partially Supported Config{' '}
83+
<QuestionIcon style={{ marginLeft: '.5rem' }} />
84+
</Tooltip>
85+
) : (
86+
<div>Supported Configuration</div>
87+
)}
88+
</Icons>
89+
) : null}
90+
</Stack>
91+
);
92+
};

packages/app/src/app/pages/Sandbox/Editor/Content/index.tsx

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
import css from '@styled-system/css';
2-
3-
import Tooltip from '@codesandbox/common/lib/components/Tooltip';
41
import getTemplateDefinition from '@codesandbox/common/lib/templates';
52
import { BACKTICK } from '@codesandbox/common/lib/utils/keycodes';
6-
import { Icons } from 'app/components/CodeEditor/elements';
73
import { VSCode as CodeEditor } from 'app/components/CodeEditor/VSCode';
84
import { DevTools } from 'app/components/Preview/DevTools';
95
import { useOvermind } from 'app/overmind';
106
import useKey from 'react-use/lib/useKey';
117
import React, { useCallback, useEffect, useRef, useState } from 'react';
12-
import QuestionIcon from 'react-icons/lib/go/question';
138
import SplitPane from 'react-split-pane';
149
import { ThemeProvider } from 'styled-components';
1510

16-
import { LiveUser } from '@codesandbox/common/lib/types';
17-
import { Stack } from '@codesandbox/components';
1811
import preventGestureScroll, { removeListener } from './prevent-gesture-scroll';
1912
import { Preview } from './Preview';
13+
import { EditorToast } from './EditorToast';
2014

2115
export const MainWorkspace: React.FC<{ theme: any }> = ({ theme }) => {
2216
const { state, actions, effects, reaction } = useOvermind();
@@ -87,23 +81,11 @@ export const MainWorkspace: React.FC<{ theme: any }> = ({ theme }) => {
8781
[]
8882
);
8983

90-
const { currentModule } = state.editor;
9184
const sandbox = state.editor.currentSandbox;
9285
const { preferences } = state;
9386
const windowVisible = state.editor.previewWindowVisible;
9487
const template = sandbox && getTemplateDefinition(sandbox.template);
9588
const currentPosition = state.editor.currentDevToolsPosition;
96-
const modulePath = currentModule.path;
97-
const config = template && template.configurationFiles[modulePath];
98-
99-
const followingUserId = state.live.followingUserId;
100-
let followingUser: LiveUser | undefined;
101-
102-
if (followingUserId && state.live.roomInfo && state.live.isLive) {
103-
followingUser = state.live.roomInfo.users.find(
104-
u => u.id === followingUserId
105-
);
106-
}
10789

10890
const browserConfig = {
10991
id: 'codesandbox.browser',
@@ -204,66 +186,7 @@ export const MainWorkspace: React.FC<{ theme: any }> = ({ theme }) => {
204186
bottom: 0,
205187
}}
206188
>
207-
<Stack
208-
css={css({
209-
position: 'absolute',
210-
top: 34,
211-
zIndex: 45,
212-
right: 0,
213-
})}
214-
gap={1}
215-
direction="vertical"
216-
align="flex-end"
217-
>
218-
{followingUser && (
219-
<div
220-
css={{
221-
transition: '0.3s ease opacity',
222-
background: `rgb(${followingUser.color.join(',')})`,
223-
padding: '2px 8px',
224-
fontSize: '12px',
225-
float: 'right',
226-
width: 'max-content',
227-
borderBottomLeftRadius: 2,
228-
color:
229-
(followingUser.color[0] * 299 +
230-
followingUser.color[1] * 587 +
231-
followingUser.color[2] * 114) /
232-
1000 >
233-
128
234-
? 'rgba(0, 0, 0, 0.8)'
235-
: 'white',
236-
237-
':hover': {
238-
opacity: 0.5,
239-
},
240-
}}
241-
>
242-
Following {followingUser.username}
243-
</div>
244-
)}
245-
246-
{config ? (
247-
<Icons>
248-
{config.partialSupportDisclaimer ? (
249-
<Tooltip
250-
placement="bottom"
251-
content={config.partialSupportDisclaimer}
252-
style={{
253-
display: 'flex',
254-
'align-items': 'center',
255-
}}
256-
>
257-
Partially Supported Config{' '}
258-
<QuestionIcon style={{ marginLeft: '.5rem' }} />
259-
</Tooltip>
260-
) : (
261-
<div>Supported Configuration</div>
262-
)}
263-
</Icons>
264-
) : null}
265-
</Stack>
266-
189+
<EditorToast />
267190
{state.editor.isLoading ? null : <CodeEditor />}
268191
</div>
269192
</div>

0 commit comments

Comments
 (0)