新增列表更新管理
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { setListUpdateTime } from '@renderer/utils/data'
|
||||
import { setFetchingListStatus } from '@renderer/core/share/list'
|
||||
import { useAction, useCommit } from '@renderer/utils/vueTools'
|
||||
|
||||
export default () => {
|
||||
const getBoardListAll = useAction('leaderboard', 'getListAll')
|
||||
const getListDetailAll = useAction('songList', 'getListDetailAll')
|
||||
const setList = useCommit('list', 'setList')
|
||||
|
||||
const fetchList = (id, source, sourceListId) => {
|
||||
setFetchingListStatus(id, true)
|
||||
|
||||
let promise
|
||||
if (/board__/.test(sourceListId)) {
|
||||
const id = sourceListId.replace(/board__/, '')
|
||||
promise = getBoardListAll({ id, isRefresh: true })
|
||||
} else {
|
||||
promise = getListDetailAll({ source, id: sourceListId, isRefresh: true })
|
||||
}
|
||||
return promise.finally(() => {
|
||||
setFetchingListStatus(id, false)
|
||||
})
|
||||
}
|
||||
|
||||
return async targetListInfo => {
|
||||
const list = await fetchList(targetListInfo.id, targetListInfo.source, targetListInfo.sourceListId)
|
||||
// console.log(targetListInfo.list.length, list.length)
|
||||
setList({
|
||||
...targetListInfo,
|
||||
list,
|
||||
})
|
||||
setListUpdateTime(targetListInfo.id, Date.now())
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { throttle } from './index'
|
||||
|
||||
let listPosition = {}
|
||||
let listPrevSelectId
|
||||
let listUpdateInfo = {}
|
||||
|
||||
const saveListPosition = throttle(() => {
|
||||
rendererSend(NAMES.mainWindow.save_data, {
|
||||
@@ -43,3 +44,39 @@ export const setListPrevSelectId = id => {
|
||||
listPrevSelectId = id
|
||||
saveListPrevSelectId()
|
||||
}
|
||||
|
||||
export const initListUpdateInfo = () => {
|
||||
return rendererInvoke(NAMES.mainWindow.get_data, 'listUpdateInfo').then(data => {
|
||||
if (!data) data = {}
|
||||
// console.log(data)
|
||||
listUpdateInfo = data
|
||||
})
|
||||
}
|
||||
const saveListUpdateInfo = throttle(() => {
|
||||
rendererSend(NAMES.mainWindow.save_data, {
|
||||
path: 'listUpdateInfo',
|
||||
data: listUpdateInfo,
|
||||
})
|
||||
}, 1000)
|
||||
|
||||
export const getListUpdateInfo = () => listUpdateInfo
|
||||
export const setListAutoUpdate = (id, enable) => {
|
||||
const targetInfo = listUpdateInfo[id] ?? { updateTime: '', isAutoUpdate: false }
|
||||
targetInfo.isAutoUpdate = enable
|
||||
listUpdateInfo[id] = targetInfo
|
||||
saveListUpdateInfo()
|
||||
}
|
||||
export const setListUpdateTime = (id, time) => {
|
||||
const targetInfo = listUpdateInfo[id] ?? { updateTime: '', isAutoUpdate: false }
|
||||
targetInfo.updateTime = time
|
||||
listUpdateInfo[id] = targetInfo
|
||||
saveListUpdateInfo()
|
||||
}
|
||||
// export const setListUpdateInfo = (id, { updateTime, isAutoUpdate }) => {
|
||||
// listUpdateInfo[id] = { updateTime, isAutoUpdate }
|
||||
// saveListUpdateInfo()
|
||||
// }
|
||||
export const removeListUpdateInfo = id => {
|
||||
delete listUpdateInfo[id]
|
||||
saveListUpdateInfo()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user