Skip to content

Commit

Permalink
Merge pull request agalwood#57 from Raistlin916/master
Browse files Browse the repository at this point in the history
feat: drag & drop torrent file to add task
  • Loading branch information
agalwood authored Feb 15, 2019
2 parents ed4f3af + 2e6b8bb commit 3970558
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/renderer/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@
})
},
methods: {
},
created () {
document.ondragover = document.ondrop = (ev) => {
ev.preventDefault()
}
document.body.ondrop = (ev) => {
ev.preventDefault()
const fileList = [...ev.dataTransfer.files]
.map(item => ({ raw: item, name: item.name }))
.filter(item => /\.torrent$/.test(item.name))
if (!fileList.length) {
return
}
this.$store.dispatch('app/showAddTaskDialog', 'torrent')
this.$nextTick(() => {
this.$store.dispatch('app/addTaskAddTorrents', { fileList })
})
}
}
}
</script>
Expand Down
19 changes: 16 additions & 3 deletions src/renderer/components/Task/SelectTorrent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@
computed: {
...mapState('preference', {
config: state => state.config
}),
...mapState('app', {
torrents: state => state.addTaskTorrents
})
},
methods: {
handleChange (file, fileList) {
console.log('file===>', file)
watch: {
torrents (fileList) {
const file = fileList[0]
if (fileList.length === 0) {
this.name = ''
return
}
if (!file.raw) {
return
}
Expand All @@ -54,6 +61,12 @@
this.$emit('change', torrent, file, fileList)
})
}
},
methods: {
handleChange (file, fileList) {
this.$store.dispatch('app/addTaskAddTorrents', { fileList })
console.log('file===>', file)
}
}
}
</script>
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/store/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const state = {
numWaiting: 0
},
addTaskVisible: false,
addTaskType: 'uri'
addTaskType: 'uri',
addTaskTorrents: []
}

const getters = {
Expand All @@ -43,6 +44,9 @@ const mutations = {
CHANGE_ADD_TASK_TYPE (state, taskType) {
state.addTaskType = taskType
},
CHANGE_ADD_TASK_TORRENTS (state, fileList) {
state.addTaskTorrents = [...fileList]
},
UPDATE_INTERVAL (state, millisecond) {
let interval = millisecond
if (millisecond > MAX_INTERVAL) {
Expand Down Expand Up @@ -121,10 +125,14 @@ const actions = {
},
hideAddTaskDialog ({ commit }) {
commit('CHANGE_ADD_TASK_VISIBLE', false)
commit('CHANGE_ADD_TASK_TORRENTS', [])
},
changeAddTaskType ({ commit }, taskType) {
commit('CHANGE_ADD_TASK_TYPE', taskType)
},
addTaskAddTorrents ({ commit }, { fileList }) {
commit('CHANGE_ADD_TASK_TORRENTS', fileList)
},
updateInterval ({ commit }, millisecond) {
commit('UPDATE_INTERVAL', millisecond)
},
Expand Down

0 comments on commit 3970558

Please sign in to comment.