-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task Hierarchy: drag-and-drop task from one part of the hierarchy to another #37
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; | ||
import { DragDropContext } from 'react-dnd'; | ||
import HTML5Backend from 'react-dnd-html5-backend'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make sure there's no negative privacy repercussions here. Is HTML5 the only back end option that exists for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the only other one is the TouchBackend which doesn't seem to work using the mouse (one could say, obviously). The thing is HTML5 backend doesn't work on touch devices (again, obviously). I've checked the TouchBackend on iPhone6 (browserstack) and drag and drop seems to work ... sometimes. I guess it's and IOS issue: https://github.com/yahoo/react-dnd-touch-backend/issues/78. Although Android (Pixel 3) seemed to work even worse (I managed to delete some tasks trying to drag and drop 👎) Anyway, if we're still up for it we could use https://louisbrunner.github.io/dnd-multi-backend/packages/react-dnd-multi-backend/ But as far as your original question goes re. privacy repercussions. No, I don't think we have any other backend option with react-dnd for desktop. Is HTML5 a privacy problem? |
||
import { setCurrentPursuance } from '../../../actions'; | ||
import PursuanceMenu from './PursuanceMenu'; | ||
import MyTasksView from './views/MyTasksView'; | ||
|
@@ -50,7 +52,7 @@ class PursuancePage extends Component { | |
} | ||
} | ||
|
||
export default connect(({currentPursuanceId}) => | ||
export default DragDropContext(HTML5Backend)(connect(({currentPursuanceId}) => | ||
({ currentPursuanceId }), { | ||
setCurrentPursuance | ||
})(PursuancePage); | ||
})(PursuancePage)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,45 @@ export default function(state = initialState, action) { | |
}); | ||
} | ||
|
||
case 'MOVE_TASK': | ||
const { oldParentGid, newParentGid, taskGid } = action; | ||
const newMap = Object.assign({}, state.taskMap); | ||
const newParentTask = newMap[newParentGid]; | ||
const oldParentTask = newMap[oldParentGid]; | ||
const oldParentSubtaskGids = oldParentTask.subtask_gids.filter( | ||
gid => gid !== taskGid | ||
); | ||
const newSubtaskGids = [...newParentTask.subtask_gids, taskGid]; | ||
const newSubtasks = newSubtaskGids.filter( | ||
(gid, idx) => newSubtaskGids.indexOf(gid) === idx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every subtask gid has the same index as itself... or am I reading this wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading well ... I'll remove this bit. |
||
); | ||
|
||
newSubtasks.sort(function(gid1, gid2) { | ||
newMap[gid1].created_parsed = newMap[gid1].created_parsed || new Date(newMap[gid1].created); | ||
newMap[gid2].created_parsed = newMap[gid2].created_parsed || new Date(newMap[gid2].created); | ||
const t1Date = newMap[gid1].created_parsed; | ||
const t2Date = newMap[gid2].created_parsed; | ||
|
||
if (t1Date === t2Date) { | ||
return ( gid1 < gid2) ? -1 : ( gid1 > gid2 ) ? 1 : 0; | ||
} else { | ||
return (t1Date > t2Date) ? 1 : -1; | ||
} | ||
}); | ||
|
||
return Object.assign({}, state, { | ||
taskMap: Object.assign(newMap, { | ||
[oldParentGid]: { | ||
...oldParentTask, | ||
subtask_gids: oldParentSubtaskGids | ||
}, | ||
[newParentGid]: { | ||
...newParentTask, | ||
subtask_gids: newSubtasks | ||
} | ||
}) | ||
}); | ||
|
||
default: | ||
return state; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
MOVE_TASK_IN_HIERARCHY
? Soon we may be reordering task lists in My Tasks