Skip to content

Commit 36fb229

Browse files
committed
🔨 Switch Dashboard/Content to use useOvermind
1 parent aa31a5e commit 36fb229

File tree

24 files changed

+409
-353
lines changed

24 files changed

+409
-353
lines changed

‎packages/app/package.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@
190190
"react-content-loader": "^4.2.2",
191191
"react-day-picker": "^7.2.4",
192192
"react-devtools-inline": "^4.4.0",
193-
"react-dnd": "^9.4.0",
194-
"react-dnd-html5-backend": "^9.4.0",
193+
"react-dnd": "^9.5.1",
194+
"react-dnd-html5-backend": "^9.5.1",
195195
"react-dom": "^16.9.0",
196196
"react-draggable": "^3.0.5",
197197
"react-error-overlay": "^1.0.10",
@@ -213,7 +213,7 @@
213213
"react-stripe-elements": "^5.0.0",
214214
"react-tagsinput": "^3.19.0",
215215
"react-use": "^9.7.2",
216-
"react-virtualized": "^9.19.1",
216+
"react-virtualized": "^9.21.2",
217217
"reakit": "^1.0.0-beta.4",
218218
"rebound": "^0.1.0",
219219
"resize-observer-polyfill": "^1.5.1",
@@ -272,6 +272,7 @@
272272
"@types/react-helmet": "^5.0.11",
273273
"@types/react-icons": "2.2.7",
274274
"@types/react-instantsearch": "^5.2.3",
275+
"@types/react-virtualized": "^9.21.8",
275276
"@types/react-router-dom": "^5.1.3",
276277
"@types/react-stripe-elements": "^1.3.2",
277278
"@types/resolve": "^0.0.8",

‎packages/app/src/app/pages/Dashboard/Content/DragLayer/SelectedSandboxItems/index.tsx‎

Lines changed: 0 additions & 48 deletions
This file was deleted.

‎packages/app/src/app/pages/Dashboard/Content/DragLayer/index.js‎

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useEffect, FunctionComponent } from 'react';
22
import { Spring, animated, interpolate } from 'react-spring/renderprops';
33

44
import {
@@ -10,22 +10,21 @@ import {
1010

1111
type Props = {
1212
id: string;
13-
i: number;
13+
index: number;
14+
isLast: boolean;
15+
scale: number;
16+
selectedSandboxes: string[];
1417
x: number;
1518
y: number;
16-
scale: number;
17-
isLast: boolean;
18-
selectedSandboxes: Array<string>;
1919
};
20-
21-
export const AnimatedSandboxItem: React.FC<Props> = ({
20+
export const AnimatedSandboxItem: FunctionComponent<Props> = ({
2221
id,
23-
i,
24-
x,
25-
y,
26-
scale,
22+
index,
2723
isLast,
24+
scale,
2825
selectedSandboxes,
26+
x,
27+
y,
2928
}) => {
3029
const [render, setRender] = useState(true);
3130
const [position, setPosition] = useState<DOMRect>(null);
@@ -39,7 +38,7 @@ export const AnimatedSandboxItem: React.FC<Props> = ({
3938
setPosition(sandboxBrotherItem.getBoundingClientRect() as DOMRect);
4039
}
4140

42-
if (i !== 0 && !isLast) {
41+
if (index !== 0 && !isLast) {
4342
timeout = global.setTimeout(() => {
4443
setRender(false);
4544
}, 200);
@@ -50,7 +49,7 @@ export const AnimatedSandboxItem: React.FC<Props> = ({
5049
global.clearTimeout(timeout);
5150
}
5251
};
53-
}, [id, i, isLast]);
52+
}, [id, index, isLast]);
5453

5554
if (!render || !position) {
5655
return null;
@@ -59,7 +58,7 @@ export const AnimatedSandboxItem: React.FC<Props> = ({
5958
return (
6059
<Spring
6160
native
62-
immediate={i === 0 ? el => el !== 'scale' : false}
61+
immediate={index === 0 ? el => el !== 'scale' : false}
6362
from={{ x: position.x, y: position.y, shadow: 2, scale: 1 }}
6463
to={{ scale, x, y, shadow: isLast ? 16 : 2 }}
6564
key={id}
@@ -70,7 +69,7 @@ export const AnimatedSandboxItem: React.FC<Props> = ({
7069
position: 'absolute',
7170
willChange: 'transform',
7271
boxShadow:
73-
i === 0 || isLast
72+
index === 0 || isLast
7473
? interpolate(
7574
[newShadow],
7675
s => `0 ${s}px ${s * 2}px rgba(0, 0, 0, 0.3)`
@@ -81,20 +80,22 @@ export const AnimatedSandboxItem: React.FC<Props> = ({
8180
(xx, yy, zz) =>
8281
`translate3d(${xx}px, ${yy}px, 0px) scale3d(${zz}, ${zz}, ${zz})`
8382
),
84-
zIndex: i === 0 ? 20 : 10,
83+
zIndex: index === 0 ? 20 : 10,
8584
}}
8685
>
8786
<Container>
8887
<SandboxImageContainer>
8988
<SandboxImage
9089
style={{
91-
backgroundImage: `url(${`https://codesandbox.io/api/v1/sandboxes/${id}/screenshot.png`})`,
90+
backgroundImage: `url(https://codesandbox.io/api/v1/sandboxes/${id}/screenshot.png)`,
9291
}}
9392
/>
9493
</SandboxImageContainer>
94+
9595
<SandboxInfo>
96-
{selectedSandboxes.length}{' '}
97-
{selectedSandboxes.length === 1 ? 'Sandbox' : 'Sandboxes'}
96+
{`${selectedSandboxes.length} ${
97+
selectedSandboxes.length === 1 ? 'Sandbox' : 'Sandboxes'
98+
}`}
9899
</SandboxInfo>
99100
</Container>
100101
</animated.div>
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import styled from 'styled-components';
1+
import styled, { css } from 'styled-components';
22

33
export const Container = styled.div`
4-
height: 210px;
5-
width: 346px;
4+
${({ theme }) => css`
5+
height: 210px;
6+
width: 346px;
67
7-
background-color: ${props => props.theme.background};
8-
border-radius: 2px;
8+
background-color: ${theme.background};
9+
border-radius: 2px;
10+
`};
911
`;
1012

1113
export const SandboxImageContainer = styled.div`
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { FunctionComponent } from 'react';
2+
import { useOvermind } from 'app/overmind';
3+
4+
import { AnimatedSandboxItem } from './AnimatedSandboxItem';
5+
6+
type Props = {
7+
id: string;
8+
isOverPossibleTargets: boolean;
9+
x: number;
10+
y: number;
11+
};
12+
export const SelectedSandboxItems: FunctionComponent<Props> = ({
13+
id,
14+
isOverPossibleTargets,
15+
x,
16+
y,
17+
}) => {
18+
const {
19+
state: {
20+
dashboard: { selectedSandboxes },
21+
},
22+
} = useOvermind();
23+
const selectedIds = [id, ...selectedSandboxes.filter(b => b !== id)];
24+
25+
return (
26+
<>
27+
{selectedIds.map((selectedId, index) => (
28+
<AnimatedSandboxItem
29+
id={selectedId}
30+
index={index}
31+
isLast={index === selectedIds.length - 1}
32+
key={selectedId}
33+
scale={isOverPossibleTargets ? 0.4 : 0.8}
34+
selectedSandboxes={selectedIds}
35+
x={x}
36+
y={y}
37+
/>
38+
))}
39+
</>
40+
);
41+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import styled from 'styled-components';
2+
3+
export const Container = styled.div`
4+
position: fixed;
5+
pointer-events: none;
6+
z-index: 100;
7+
left: 0;
8+
top: 0;
9+
width: 100%;
10+
height: 100%;
11+
`;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React, { FunctionComponent } from 'react';
2+
import {
3+
DragLayer as DNDDragLayer,
4+
DragLayerCollector,
5+
DragLayerMonitor,
6+
} from 'react-dnd';
7+
8+
import { Container } from './elements';
9+
import { SelectedSandboxItems } from './SelectedSandboxItems';
10+
11+
type OwnProps = {};
12+
type Props = OwnProps & CollectedProps;
13+
const DragLayerComponent: FunctionComponent<Props> = ({
14+
currentOffset,
15+
isDragging,
16+
isOverPossibleTargets,
17+
item,
18+
itemType,
19+
}) => {
20+
if (!isDragging || !currentOffset) {
21+
return null;
22+
}
23+
24+
return (
25+
<Container>
26+
{itemType === 'SANDBOX' ? (
27+
<SelectedSandboxItems
28+
isOverPossibleTargets={isOverPossibleTargets}
29+
x={currentOffset.x}
30+
y={currentOffset.y}
31+
id={item.id}
32+
/>
33+
) : null}
34+
</Container>
35+
);
36+
};
37+
38+
const collect: DragLayerCollector<OwnProps, CollectedProps> = monitor => {
39+
// @ts-ignore
40+
const isOverPossibleTargets = monitor.getTargetIds().length > 0;
41+
42+
return {
43+
currentOffset: monitor.getSourceClientOffset(),
44+
isDragging: monitor.isDragging(),
45+
isOverPossibleTargets,
46+
item: monitor.getItem(),
47+
itemType: monitor.getItemType(),
48+
};
49+
};
50+
51+
type CollectedProps = {
52+
currentOffset: ReturnType<DragLayerMonitor['getSourceClientOffset']>;
53+
isDragging: ReturnType<DragLayerMonitor['isDragging']>;
54+
isOverPossibleTargets: boolean;
55+
item: ReturnType<DragLayerMonitor['getItem']>;
56+
itemType: ReturnType<DragLayerMonitor['getItemType']>;
57+
};
58+
export const DragLayer = DNDDragLayer<OwnProps, CollectedProps>(collect)(
59+
DragLayerComponent
60+
);

0 commit comments

Comments
 (0)