Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 25, 2018
1 parent b5aa18d commit e095ec7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/state/get-drag-impact/in-home-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default ({
const isBeyondStartPosition: boolean =
currentCenter[axis.line] - originalCenter[axis.line] > 0;

console.log('original center', originalCenter);
console.log('current center', currentCenter);
console.log('isBeyondStartPosition', isBeyondStartPosition);

// Amount to move needs to include the margins
const amount: Position = patch(axis.line, draggable.client.marginBox[axis.size]);

Expand Down Expand Up @@ -86,18 +90,23 @@ export default ({
const ordered: Displacement[] = isBeyondStartPosition ? displaced.reverse() : displaced;
const index: number = (() => {
const startIndex = insideHome.indexOf(draggable);
console.log('start index', startIndex);
const length: number = ordered.length;
if (!length) {
return startIndex;
}

if (isBeyondStartPosition) {
console.log('is beyond start position');
return startIndex + length;
}
// is moving backwards
console.log('moving backwards yolo');
return startIndex - length;
})();

console.log('calculated index', index);

const movement: DragMovement = {
amount,
displaced: ordered,
Expand Down
20 changes: 19 additions & 1 deletion src/state/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,33 @@ export default (state: State = idle, action: Action): State => {
// The starting index of a draggable can change during a drag
const newCritical: Critical = critical || state.critical;

const homeImpact: DragImpact = {
movement: noMovement,
direction: dimensions.droppables[newCritical.droppable.id].axis.direction,
destination: {
index: newCritical.draggable.index,
droppableId: newCritical.droppable.id,
},
};

// this will get the impact
const impact: DragImpact = getDragImpact({
pageBorderBoxCenter: state.current.page.borderBoxCenter,
draggable: dimensions.draggables[newCritical.draggable.id],
draggables: dimensions.draggables,
droppables: dimensions.droppables,
previousImpact: state.impact,
previousImpact: homeImpact,
viewport,
});

if (critical) {
console.log('previous impact (home)', homeImpact);
console.log('critical', critical);
console.log('critical draggable', dimensions.draggables[newCritical.draggable.id]);
console.log('new impact', impact);
console.log('viewport', viewport);
}

// Moving into the DRAGGING phase
if (state.phase === 'BULK_COLLECTING') {
return {
Expand Down
4 changes: 2 additions & 2 deletions stories/src/dynamic/with-controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { grid } from '../constants';
import type { Quote, QuoteMap, Author } from '../types';
import type { DropResult } from '../../../src/types';

const intial: QuoteMap = generateQuoteMap(20);
const initial: QuoteMap = generateQuoteMap(4);

const ControlSection = styled.div`
margin: ${grid * 4}px;
Expand Down Expand Up @@ -59,7 +59,7 @@ const createQuote = (() => {

export default class WithControls extends React.Component<*, State> {
state: State = {
quoteMap: intial,
quoteMap: initial,
}

componentDidMount() {
Expand Down

0 comments on commit e095ec7

Please sign in to comment.