From fe78fc251a9f83b7dd36883a5c9013e47725f234 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Tue, 21 Mar 2023 09:22:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BD=9C=E5=9C=A8=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8A=A0=E8=BD=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/search/music.ts | 5 ++++- src/core/search/songlist.ts | 5 ++++- src/screens/Comment/CommentHot.tsx | 3 ++- src/screens/Comment/CommentNew.tsx | 3 ++- src/screens/Home/Views/Leaderboard/MusicList.tsx | 5 ++++- src/screens/Home/Views/SongList/List.tsx | 5 ++++- src/screens/SonglistDetail/MusicList.tsx | 5 ++++- 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/core/search/music.ts b/src/core/search/music.ts index 25dbe40..af49918 100644 --- a/src/core/search/music.ts +++ b/src/core/search/music.ts @@ -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) => { if (key != listInfo.key) return [] 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 + }) } } diff --git a/src/core/search/songlist.ts b/src/core/search/songlist.ts index 9322c99..00fdb67 100644 --- a/src/core/search/songlist.ts +++ b/src/core/search/songlist.ts @@ -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).then((data: SearchResult) => { if (key != listInfo.key) return [] 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 + }) } } diff --git a/src/screens/Comment/CommentHot.tsx b/src/screens/Comment/CommentHot.tsx index b142d56..42bd79d 100644 --- a/src/screens/Comment/CommentHot.tsx +++ b/src/screens/Comment/CommentHot.tsx @@ -43,7 +43,8 @@ export default ({ musicInfo, onUpdateTotal }: { } const handleListLoadMore = () => { 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') void handleGetComment(musicInfo, page).then(({ comments }) => { let isEnd = page >= listInfo.current.maxPage diff --git a/src/screens/Comment/CommentNew.tsx b/src/screens/Comment/CommentNew.tsx index 4c4f958..99c691c 100644 --- a/src/screens/Comment/CommentNew.tsx +++ b/src/screens/Comment/CommentNew.tsx @@ -44,7 +44,8 @@ export default ({ musicInfo, onUpdateTotal }: { const handleListLoadMore = () => { console.log('load') 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') void handleGetComment(musicInfo, page).then(({ comments }) => { let isEnd = page >= listInfo.current.maxPage diff --git a/src/screens/Home/Views/Leaderboard/MusicList.tsx b/src/screens/Home/Views/Leaderboard/MusicList.tsx index 64a78a1..5249355 100644 --- a/src/screens/Home/Views/Leaderboard/MusicList.tsx +++ b/src/screens/Home/Views/Leaderboard/MusicList.tsx @@ -1,6 +1,6 @@ import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react' 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 { handlePlay } from './listAction' @@ -37,6 +37,7 @@ export default forwardRef((props, ref) => { listRef.current?.setStatus(boardState.listDetailInfo.maxPage == page ? 'end' : 'idle') }) }).catch(() => { + if (boardState.listDetailInfo.list.length && page == 1) clearListDetail() listRef.current?.setStatus('error') }) } @@ -65,6 +66,7 @@ export default forwardRef((props, ref) => { listRef.current?.setList(result.list) listRef.current?.setStatus(boardState.listDetailInfo.maxPage == page ? 'end' : 'idle') }).catch(() => { + if (boardState.listDetailInfo.list.length && page == 1) clearListDetail() listRef.current?.setStatus('error') }) } @@ -77,6 +79,7 @@ export default forwardRef((props, ref) => { listRef.current?.setList(result.list) listRef.current?.setStatus(boardState.listDetailInfo.maxPage == page ? 'end' : 'idle') }).catch(() => { + if (boardState.listDetailInfo.list.length && page == 1) clearListDetail() listRef.current?.setStatus('error') }) } diff --git a/src/screens/Home/Views/SongList/List.tsx b/src/screens/Home/Views/SongList/List.tsx index 6053653..b10787c 100644 --- a/src/screens/Home/Views/SongList/List.tsx +++ b/src/screens/Home/Views/SongList/List.tsx @@ -1,6 +1,6 @@ import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react' 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 { type Source } from '@/store/songlist/state' @@ -32,6 +32,7 @@ export default forwardRef((props, ref) => { listRef.current?.setStatus(songlistState.listInfo.maxPage == page ? 'end' : 'idle') }) }).catch(() => { + if (songlistState.listInfo.list.length && page == 1) clearList() listRef.current?.setStatus('error') }) } @@ -55,6 +56,7 @@ export default forwardRef((props, ref) => { listRef.current?.setList(result.list) listRef.current?.setStatus(songlistState.listInfo.maxPage == page ? 'end' : 'idle') }).catch(() => { + if (songlistState.listInfo.list.length && page == 1) clearList() listRef.current?.setStatus('error') }) } @@ -67,6 +69,7 @@ export default forwardRef((props, ref) => { listRef.current?.setList(result.list) listRef.current?.setStatus(songlistState.listInfo.maxPage == page ? 'end' : 'idle') }).catch(() => { + if (songlistState.listInfo.list.length && page == 1) clearList() listRef.current?.setStatus('error') }) } diff --git a/src/screens/SonglistDetail/MusicList.tsx b/src/screens/SonglistDetail/MusicList.tsx index b1d823e..0bf51a4 100644 --- a/src/screens/SonglistDetail/MusicList.tsx +++ b/src/screens/SonglistDetail/MusicList.tsx @@ -1,6 +1,6 @@ import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react' 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 { handlePlay } from './listAction' import Header, { type HeaderType } from './Header' @@ -55,6 +55,7 @@ export default forwardRef(({ componentId }, ref) listRef.current?.setStatus(songlistState.listDetailInfo.maxPage == page ? 'end' : 'idle') }) }).catch(() => { + if (songlistState.listDetailInfo.list.length && page == 1) clearListDetail() listRef.current?.setStatus('error') }) } @@ -83,6 +84,7 @@ export default forwardRef(({ componentId }, ref) listRef.current?.setList(result.list) listRef.current?.setStatus(songlistState.listDetailInfo.maxPage == page ? 'end' : 'idle') }).catch(() => { + if (songlistState.listDetailInfo.list.length && page == 1) clearListDetail() listRef.current?.setStatus('error') }) } @@ -95,6 +97,7 @@ export default forwardRef(({ componentId }, ref) listRef.current?.setList(result.list) listRef.current?.setStatus(songlistState.listDetailInfo.maxPage == page ? 'end' : 'idle') }).catch(() => { + if (songlistState.listDetailInfo.list.length && page == 1) clearListDetail() listRef.current?.setStatus('error') }) }