修复潜在列表加载问题

This commit is contained in:
lyswhut 2023-03-21 09:22:43 +08:00
parent b33f848589
commit fe78fc251a
7 changed files with 24 additions and 7 deletions

View File

@ -49,7 +49,10 @@ export const search = async(text: string, page: number, sourceId: Source): Promi
return (musicSdk[sourceId]?.musicSearch.search(text, page, listInfo.limit).then((data: SearchResult) => { return (musicSdk[sourceId]?.musicSearch.search(text, page, listInfo.limit).then((data: SearchResult) => {
if (key != listInfo.key) return [] if (key != listInfo.key) return []
return setListInfo(data, page, text) return setListInfo(data, page, text)
}) ?? Promise.reject(new Error('source not found: ' + sourceId))) }) ?? Promise.reject(new Error('source not found: ' + sourceId))).catch((err: any) => {
if (listInfo.list.length && page == 1) clearListInfo(sourceId)
throw err
})
} }
} }

View File

@ -49,6 +49,9 @@ export const search = async(text: string, page: number, sourceId: Source): Promi
return ((musicSdk[sourceId]?.songList.search(text, page, listInfo.limit) as Promise<SearchResult>).then((data: SearchResult) => { return ((musicSdk[sourceId]?.songList.search(text, page, listInfo.limit) as Promise<SearchResult>).then((data: SearchResult) => {
if (key != listInfo.key) return [] if (key != listInfo.key) return []
return setListInfo(data, page, text) return setListInfo(data, page, text)
}) ?? Promise.reject(new Error('source not found: ' + sourceId))) }) ?? Promise.reject(new Error('source not found: ' + sourceId))).catch((err: any) => {
if (listInfo.list.length && page == 1) clearListInfo(sourceId)
throw err
})
} }
} }

View File

@ -43,7 +43,8 @@ export default ({ musicInfo, onUpdateTotal }: {
} }
const handleListLoadMore = () => { const handleListLoadMore = () => {
if (listInfo.current.isLoading || listInfo.current.isEnd) return if (listInfo.current.isLoading || listInfo.current.isEnd) return
const page = listInfo.current.page + 1 const list = listRef.current?.getList() ?? []
const page = list.length ? listInfo.current.page + 1 : 1
listRef.current?.setStatus('loading') listRef.current?.setStatus('loading')
void handleGetComment(musicInfo, page).then(({ comments }) => { void handleGetComment(musicInfo, page).then(({ comments }) => {
let isEnd = page >= listInfo.current.maxPage let isEnd = page >= listInfo.current.maxPage

View File

@ -44,7 +44,8 @@ export default ({ musicInfo, onUpdateTotal }: {
const handleListLoadMore = () => { const handleListLoadMore = () => {
console.log('load') console.log('load')
if (listInfo.current.isLoading || listInfo.current.isEnd) return if (listInfo.current.isLoading || listInfo.current.isEnd) return
const page = listInfo.current.page + 1 const list = listRef.current?.getList() ?? []
const page = list.length ? listInfo.current.page + 1 : 1
listRef.current?.setStatus('loading') listRef.current?.setStatus('loading')
void handleGetComment(musicInfo, page).then(({ comments }) => { void handleGetComment(musicInfo, page).then(({ comments }) => {
let isEnd = page >= listInfo.current.maxPage let isEnd = page >= listInfo.current.maxPage

View File

@ -1,6 +1,6 @@
import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react' import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react'
import OnlineList, { type OnlineListType, type OnlineListProps } from '@/components/OnlineList' import OnlineList, { type OnlineListType, type OnlineListProps } from '@/components/OnlineList'
import { getListDetail, setListDetail, setListDetailInfo } from '@/core/leaderboard' import { clearListDetail, getListDetail, setListDetail, setListDetailInfo } from '@/core/leaderboard'
import boardState from '@/store/leaderboard/state' import boardState from '@/store/leaderboard/state'
import { handlePlay } from './listAction' import { handlePlay } from './listAction'
@ -37,6 +37,7 @@ export default forwardRef<MusicListType, {}>((props, ref) => {
listRef.current?.setStatus(boardState.listDetailInfo.maxPage == page ? 'end' : 'idle') listRef.current?.setStatus(boardState.listDetailInfo.maxPage == page ? 'end' : 'idle')
}) })
}).catch(() => { }).catch(() => {
if (boardState.listDetailInfo.list.length && page == 1) clearListDetail()
listRef.current?.setStatus('error') listRef.current?.setStatus('error')
}) })
} }
@ -65,6 +66,7 @@ export default forwardRef<MusicListType, {}>((props, ref) => {
listRef.current?.setList(result.list) listRef.current?.setList(result.list)
listRef.current?.setStatus(boardState.listDetailInfo.maxPage == page ? 'end' : 'idle') listRef.current?.setStatus(boardState.listDetailInfo.maxPage == page ? 'end' : 'idle')
}).catch(() => { }).catch(() => {
if (boardState.listDetailInfo.list.length && page == 1) clearListDetail()
listRef.current?.setStatus('error') listRef.current?.setStatus('error')
}) })
} }
@ -77,6 +79,7 @@ export default forwardRef<MusicListType, {}>((props, ref) => {
listRef.current?.setList(result.list) listRef.current?.setList(result.list)
listRef.current?.setStatus(boardState.listDetailInfo.maxPage == page ? 'end' : 'idle') listRef.current?.setStatus(boardState.listDetailInfo.maxPage == page ? 'end' : 'idle')
}).catch(() => { }).catch(() => {
if (boardState.listDetailInfo.list.length && page == 1) clearListDetail()
listRef.current?.setStatus('error') listRef.current?.setStatus('error')
}) })
} }

View File

@ -1,6 +1,6 @@
import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react' import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react'
import Songlist, { type SonglistProps, type SonglistType } from './components/Songlist' import Songlist, { type SonglistProps, type SonglistType } from './components/Songlist'
import { getList, setList, setListInfo } from '@/core/songlist' import { clearList, getList, setList, setListInfo } from '@/core/songlist'
import songlistState from '@/store/songlist/state' import songlistState from '@/store/songlist/state'
import { type Source } from '@/store/songlist/state' import { type Source } from '@/store/songlist/state'
@ -32,6 +32,7 @@ export default forwardRef<ListType, {}>((props, ref) => {
listRef.current?.setStatus(songlistState.listInfo.maxPage == page ? 'end' : 'idle') listRef.current?.setStatus(songlistState.listInfo.maxPage == page ? 'end' : 'idle')
}) })
}).catch(() => { }).catch(() => {
if (songlistState.listInfo.list.length && page == 1) clearList()
listRef.current?.setStatus('error') listRef.current?.setStatus('error')
}) })
} }
@ -55,6 +56,7 @@ export default forwardRef<ListType, {}>((props, ref) => {
listRef.current?.setList(result.list) listRef.current?.setList(result.list)
listRef.current?.setStatus(songlistState.listInfo.maxPage == page ? 'end' : 'idle') listRef.current?.setStatus(songlistState.listInfo.maxPage == page ? 'end' : 'idle')
}).catch(() => { }).catch(() => {
if (songlistState.listInfo.list.length && page == 1) clearList()
listRef.current?.setStatus('error') listRef.current?.setStatus('error')
}) })
} }
@ -67,6 +69,7 @@ export default forwardRef<ListType, {}>((props, ref) => {
listRef.current?.setList(result.list) listRef.current?.setList(result.list)
listRef.current?.setStatus(songlistState.listInfo.maxPage == page ? 'end' : 'idle') listRef.current?.setStatus(songlistState.listInfo.maxPage == page ? 'end' : 'idle')
}).catch(() => { }).catch(() => {
if (songlistState.listInfo.list.length && page == 1) clearList()
listRef.current?.setStatus('error') listRef.current?.setStatus('error')
}) })
} }

View File

@ -1,6 +1,6 @@
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react' import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react'
import OnlineList, { type OnlineListType, type OnlineListProps } from '@/components/OnlineList' import OnlineList, { type OnlineListType, type OnlineListProps } from '@/components/OnlineList'
import { getListDetail, setListDetail, setListDetailInfo } from '@/core/songlist' import { clearListDetail, getListDetail, setListDetail, setListDetailInfo } from '@/core/songlist'
import songlistState from '@/store/songlist/state' import songlistState from '@/store/songlist/state'
import { handlePlay } from './listAction' import { handlePlay } from './listAction'
import Header, { type HeaderType } from './Header' import Header, { type HeaderType } from './Header'
@ -55,6 +55,7 @@ export default forwardRef<MusicListType, MusicListProps>(({ componentId }, ref)
listRef.current?.setStatus(songlistState.listDetailInfo.maxPage == page ? 'end' : 'idle') listRef.current?.setStatus(songlistState.listDetailInfo.maxPage == page ? 'end' : 'idle')
}) })
}).catch(() => { }).catch(() => {
if (songlistState.listDetailInfo.list.length && page == 1) clearListDetail()
listRef.current?.setStatus('error') listRef.current?.setStatus('error')
}) })
} }
@ -83,6 +84,7 @@ export default forwardRef<MusicListType, MusicListProps>(({ componentId }, ref)
listRef.current?.setList(result.list) listRef.current?.setList(result.list)
listRef.current?.setStatus(songlistState.listDetailInfo.maxPage == page ? 'end' : 'idle') listRef.current?.setStatus(songlistState.listDetailInfo.maxPage == page ? 'end' : 'idle')
}).catch(() => { }).catch(() => {
if (songlistState.listDetailInfo.list.length && page == 1) clearListDetail()
listRef.current?.setStatus('error') listRef.current?.setStatus('error')
}) })
} }
@ -95,6 +97,7 @@ export default forwardRef<MusicListType, MusicListProps>(({ componentId }, ref)
listRef.current?.setList(result.list) listRef.current?.setList(result.list)
listRef.current?.setStatus(songlistState.listDetailInfo.maxPage == page ? 'end' : 'idle') listRef.current?.setStatus(songlistState.listDetailInfo.maxPage == page ? 'end' : 'idle')
}).catch(() => { }).catch(() => {
if (songlistState.listDetailInfo.list.length && page == 1) clearListDetail()
listRef.current?.setStatus('error') listRef.current?.setStatus('error')
}) })
} }