Skip to content

Commit ebf9bed

Browse files
improve transition
1 parent 9e49a55 commit ebf9bed

File tree

5 files changed

+51
-48
lines changed

5 files changed

+51
-48
lines changed

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import {
1010
} from '@codesandbox/common/lib/types';
1111
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
1212
import { COMMENTS } from '@codesandbox/common/lib/utils/feature-flags';
13-
import { hasPermission } from '@codesandbox/common/lib/utils/permission';
1413
import { convertTypeToStatus } from '@codesandbox/common/lib/utils/notifications';
15-
import { NotificationStatus } from '@codesandbox/notifications';
14+
import { hasPermission } from '@codesandbox/common/lib/utils/permission';
1615
import { signInPageUrl } from '@codesandbox/common/lib/utils/url-generator';
16+
import { NotificationStatus } from '@codesandbox/notifications';
1717
import {
1818
Authorization,
1919
CollaboratorFragment,
@@ -472,6 +472,8 @@ export const moduleSelected: Action<
472472
> = ({ actions, effects, state }, { id, path }) => {
473473
effects.analytics.track('Open File');
474474

475+
state.editor.hasLoadedInitialModule = true;
476+
475477
const sandbox = state.editor.currentSandbox;
476478

477479
if (!sandbox) {

packages/app/src/app/overmind/namespaces/editor/state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ type State = {
8484
selectedCommentsFilter: CommentsFilterOption;
8585
currentCommentId: string | null;
8686
currentComment: Derive<State, Comment | null>;
87+
hasLoadedInitialModule: boolean;
8788
};
8889

8990
export const state: State = {
91+
hasLoadedInitialModule: false,
9092
comments: {},
9193
currentCommentId: null, // '5e5961e0c277a40fef1e391b',
9294
currentComment: ({ comments, currentSandbox, currentCommentId }) => {

packages/app/src/app/pages/Sandbox/Editor/Skeleton/elements.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export const SkeletonTextBlock = styled.div(
2525
export const SkeletonWrapper = styled.div`
2626
position: absolute;
2727
font-family: Inter, sans-serif;
28-
transition: opacity 0.5s ease-out;
2928
opacity: 1;
29+
transition: opacity 0.5s ease-out;
3030
background-color: ${props =>
3131
props.theme.colors?.editor?.background || 'black'};
3232
width: 100%;

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

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React from 'react';
21
import Navigator from '@codesandbox/common/lib/components/Preview/Navigator';
3-
4-
import { Stack, Collapsible, List, ListItem } from '@codesandbox/components';
2+
import { Collapsible, List, ListItem, Stack } from '@codesandbox/components';
53
import css from '@styled-system/css';
4+
import React from 'react';
65

76
import {
87
SkeletonDevtools,
@@ -12,42 +11,33 @@ import {
1211
SkeletonEditor,
1312
SkeletonEditorTop,
1413
SkeletonExplorer,
15-
SkeletonWrapper,
1614
SkeletonTextBlock,
15+
SkeletonWrapper,
1716
} from './elements';
1817

19-
export const ContentSkeleton = ({ style, onTransitionEnd }) => {
20-
React.useEffect(() => {
21-
// In case we started already with opacity 0
22-
if (style.opacity === 0) {
23-
// onTransitionEnd();
24-
}
25-
}, [onTransitionEnd, style.opacity]); // eslint-disable-line we don't want to check style on purpose
26-
27-
return (
28-
<SkeletonWrapper style={style} onTransitionEnd={onTransitionEnd}>
29-
<SkeletonExplorer>
30-
<SkeletonExplorerContents />
31-
</SkeletonExplorer>
32-
<SkeletonEditor>
33-
<SkeletonEditorTop />
34-
</SkeletonEditor>
35-
<SkeletonDevtools>
36-
<SkeletonDevtoolsTop />
37-
<SkeletonDevtoolsNavigator>
38-
<Navigator
39-
url=""
40-
onChange={() => {}}
41-
onConfirm={() => {}}
42-
onRefresh={() => {}}
43-
isProjectView
44-
/>
45-
</SkeletonDevtoolsNavigator>
46-
<SkeletonDevtoolsIframe />
47-
</SkeletonDevtools>
48-
</SkeletonWrapper>
49-
);
50-
};
18+
export const ContentSkeleton = ({ style, onTransitionEnd }) => (
19+
<SkeletonWrapper style={style}>
20+
<SkeletonExplorer>
21+
<SkeletonExplorerContents />
22+
</SkeletonExplorer>
23+
<SkeletonEditor>
24+
<SkeletonEditorTop />
25+
</SkeletonEditor>
26+
<SkeletonDevtools>
27+
<SkeletonDevtoolsTop />
28+
<SkeletonDevtoolsNavigator>
29+
<Navigator
30+
url=""
31+
onChange={() => {}}
32+
onConfirm={() => {}}
33+
onRefresh={() => {}}
34+
isProjectView
35+
/>
36+
</SkeletonDevtoolsNavigator>
37+
<SkeletonDevtoolsIframe />
38+
</SkeletonDevtools>
39+
</SkeletonWrapper>
40+
);
5141

5242
const SkeletonExplorerContents = () => (
5343
<>

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Fullscreen from '@codesandbox/common/lib/components/flex/Fullscreen';
2-
32
import getTemplateDefinition from '@codesandbox/common/lib/templates';
43
import codesandbox from '@codesandbox/common/lib/themes/codesandbox.json';
54
import { REDESIGNED_SIDEBAR } from '@codesandbox/common/lib/utils/feature-flags';
@@ -17,9 +16,9 @@ import { Header } from './Header';
1716
import { Header as HeaderOld } from './HeaderOld';
1817
import { Navigation } from './Navigation';
1918
import { Navigation as NavigationOld } from './NavigationOld';
19+
import { ContentSkeleton } from './Skeleton';
2020
import getVSCodeTheme from './utils/get-vscode-theme';
2121
import { Workspace } from './Workspace';
22-
import { ContentSkeleton } from './Skeleton';
2322

2423
const STATUS_BAR_SIZE = 22;
2524

@@ -30,7 +29,7 @@ const StatusBar = styled.div`
3029
`;
3130

3231
const ContentSplit = () => {
33-
const { state, actions, effects } = useOvermind();
32+
const { state, actions, effects, reaction } = useOvermind();
3433
const statusbarEl = useRef(null);
3534
const [showSkeleton, setShowSkeleton] = useState(true);
3635
const [localState, setLocalState] = useState({
@@ -41,6 +40,13 @@ const ContentSplit = () => {
4140
customVSCodeTheme: null,
4241
});
4342

43+
useEffect(() =>
44+
reaction(
45+
reactionState => reactionState.editor.hasLoadedInitialModule,
46+
() => setShowSkeleton(false)
47+
)
48+
);
49+
4450
useEffect(() => {
4551
async function loadTheme() {
4652
const vsCodeTheme = state.preferences.settings.customVSCodeTheme;
@@ -158,12 +164,15 @@ const ContentSplit = () => {
158164
{showSkeleton ? (
159165
<NewThemeProvider theme={localState.theme.vscodeTheme}>
160166
<ContentSkeleton
161-
style={{
162-
opacity: state.editor.isLoading ? 1 : 0,
163-
}}
164-
onTransitionEnd={() => {
165-
setShowSkeleton(false);
166-
}}
167+
style={
168+
state.editor.hasLoadedInitialModule
169+
? {
170+
opacity: 0,
171+
}
172+
: {
173+
opacity: 1,
174+
}
175+
}
167176
/>
168177
</NewThemeProvider>
169178
) : null}

0 commit comments

Comments
 (0)