Skip to content

Commit a3ed79c

Browse files
committed
Refactor src/app/pages/Dashboard/Content/DragLayer/SelectedSandboxItems/index to Typescript and useOvermind
1 parent 263774c commit a3ed79c

File tree

3 files changed

+50
-43
lines changed

3 files changed

+50
-43
lines changed

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

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { useMemo } from 'react';
2+
import { useOvermind } from 'app/overmind';
3+
4+
import AnimatedSandboxItem from './AnimatedSandboxItem';
5+
6+
interface ISelectedSandboxItemsProps {
7+
x: number;
8+
y: number;
9+
isOverPossibleTargets: boolean;
10+
id: string;
11+
}
12+
13+
export const SelectedSandboxItems: React.FC<ISelectedSandboxItemsProps> = ({
14+
x,
15+
y,
16+
isOverPossibleTargets,
17+
id,
18+
}) => {
19+
const {
20+
state: {
21+
dashboard: { selectedSandboxes },
22+
},
23+
} = useOvermind();
24+
25+
const selectedIds = useMemo(
26+
() => [id, ...selectedSandboxes.filter(b => b !== id)],
27+
[id, selectedSandboxes]
28+
);
29+
30+
const scale = isOverPossibleTargets ? 0.4 : 0.8;
31+
32+
return (
33+
<>
34+
{selectedIds.map((sid, i) => (
35+
<AnimatedSandboxItem
36+
key={sid}
37+
id={sid}
38+
i={i}
39+
isLast={i === selectedIds.length - 1}
40+
x={x}
41+
y={y}
42+
scale={scale}
43+
selectedSandboxes={selectedIds}
44+
/>
45+
))}
46+
</>
47+
);
48+
};

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22

33
import { DragLayer as DNDDragLayer } from 'react-dnd';
44

5-
import SelectedSandboxItems from './SelectedSandboxItems';
5+
import { SelectedSandboxItems } from './SelectedSandboxItems';
66

77
const layerStyles = {
88
position: 'fixed',
@@ -22,13 +22,11 @@ function getItemCoords(props) {
2222
return {
2323
x,
2424
y,
25-
left: props.item.left,
26-
top: props.item.top,
2725
};
2826
}
2927

3028
class CustomDragLayer extends React.Component {
31-
renderItem(type, item, isOverPossibleTargets, { x, y, left, top }) {
29+
renderItem(type, item, isOverPossibleTargets, { x, y }) {
3230
if (type !== 'SANDBOX') {
3331
return null;
3432
}
@@ -37,8 +35,6 @@ class CustomDragLayer extends React.Component {
3735
isOverPossibleTargets={isOverPossibleTargets}
3836
x={x}
3937
y={y}
40-
left={left}
41-
top={top}
4238
id={item.id}
4339
/>
4440
);

0 commit comments

Comments
 (0)