diff --git a/src/renderer/core/useApp/useSync.js b/src/renderer/core/useApp/useSync.js index fcbb33b4..542cc71d 100644 --- a/src/renderer/core/useApp/useSync.js +++ b/src/renderer/core/useApp/useSync.js @@ -17,10 +17,9 @@ export default () => { const createUserList = useCommit('list', 'createUserList') const removeUserList = useCommit('list', 'removeUserList') const setUserListName = useCommit('list', 'setUserListName') - const moveupUserList = useCommit('list', 'moveupUserList') - const movedownUserList = useCommit('list', 'movedownUserList') const setMusicPosition = useCommit('list', 'setMusicPosition') const setSyncListData = useCommit('list', 'setSyncListData') + const setUserListPosition = useCommit('list', 'setUserListPosition') const setting = useRefGetter('setting') @@ -65,11 +64,8 @@ export default () => { case 'set_user_list_name': setUserListName(data) break - case 'moveup_user_list': - moveupUserList(data) - break - case 'movedown_user_list': - movedownUserList(data) + case 'set_user_list_position': + setUserListPosition(data) break case 'set_music_position': setMusicPosition(data) diff --git a/src/renderer/store/modules/list.js b/src/renderer/store/modules/list.js index 1e282a34..08071c93 100644 --- a/src/renderer/store/modules/list.js +++ b/src/renderer/store/modules/list.js @@ -362,11 +362,7 @@ const mutations = { const index = userLists.findIndex(l => l.id == id) if (index < 0) return - let targetList = userLists[index] - userLists.splice(index, 1) - userLists.splice(index - 1, 0, targetList) - targetList.locationUpdateTime = Date.now() - window.eventHub.emit(eventListNames.listChange, [id]) + this.commit('list/setUserListPosition', { id, position: index - 1 }) }, movedownUserList(state, { id, isSync }) { if (!isSync) { @@ -377,9 +373,20 @@ const mutations = { } const index = userLists.findIndex(l => l.id == id) if (index < 0) return + this.commit('list/setUserListPosition', { id, position: index + 1 }) + }, + setUserListPosition(state, { id, position, isSync }) { + if (!isSync) { + window.eventHub.emit(eventSyncName.send_action_list, { + action: 'set_user_list_position', + data: { id, position }, + }) + } + const index = userLists.findIndex(l => l.id == id) + if (index < 0) return let targetList = userLists[index] userLists.splice(index, 1) - userLists.splice(index + 1, 0, targetList) + userLists.splice(Math.max(Math.min(position, userLists.length - 1), 0), 0, targetList) targetList.locationUpdateTime = Date.now() window.eventHub.emit(eventListNames.listChange, [id]) },