xref: /MusicFree/src/pages/recommendSheets/components/body/sheetList.tsx (revision 5500cea7e936041b68a2f3709a583c2f0181b9e6)
1*5500cea7S猫头猫import React, {memo, useCallback} from 'react';
2ceb900cdS猫头猫import rpx from '@/utils/rpx';
3ceb900cdS猫头猫import {FlashList} from '@shopify/flash-list';
4ceb900cdS猫头猫import useRecommendSheets from '../../hooks/useRecommendSheets';
5ceb900cdS猫头猫import Empty from '@/components/base/empty';
6ceb900cdS猫头猫import ListLoading from '@/components/base/listLoading';
7ceb900cdS猫头猫import ListReachEnd from '@/components/base/listReachEnd';
8ceb900cdS猫头猫import SheetItem from '@/components/mediaItem/sheetItem';
92dda6be7S猫头猫import useOrientation from '@/hooks/useOrientation';
10ceb900cdS猫头猫
11ceb900cdS猫头猫interface ISheetListProps {
12ceb900cdS猫头猫    tag: ICommon.IUnique;
13ceb900cdS猫头猫    pluginHash: string;
14ceb900cdS猫头猫}
15ceb900cdS猫头猫
16ceb900cdS猫头猫function SheetList(props: ISheetListProps) {
17ceb900cdS猫头猫    const {tag, pluginHash} = props ?? {};
18ceb900cdS猫头猫
19ceb900cdS猫头猫    const [query, sheets, status] = useRecommendSheets(pluginHash, tag);
20ceb900cdS猫头猫
21ceb900cdS猫头猫    function renderItem({item}: {item: IMusic.IMusicSheetItemBase}) {
22ceb900cdS猫头猫        return <SheetItem sheetInfo={item} pluginHash={pluginHash} />;
23ceb900cdS猫头猫    }
242dda6be7S猫头猫    const orientation = useOrientation();
25ceb900cdS猫头猫
26*5500cea7S猫头猫    const keyExtractor = useCallback(
27*5500cea7S猫头猫        (item: any, i: number) => `${i}-${item.platform}-${item.id}`,
28*5500cea7S猫头猫        [],
29*5500cea7S猫头猫    );
30*5500cea7S猫头猫
31ceb900cdS猫头猫    return (
32ceb900cdS猫头猫        <FlashList
332dda6be7S猫头猫            ListEmptyComponent={status !== 'loading' ? Empty : null}
34ceb900cdS猫头猫            ListFooterComponent={
35ceb900cdS猫头猫                status === 'loading' ? (
36ceb900cdS猫头猫                    <ListLoading />
37ceb900cdS猫头猫                ) : status === 'done' ? (
38ceb900cdS猫头猫                    <ListReachEnd />
39ceb900cdS猫头猫                ) : (
40ceb900cdS猫头猫                    <></>
41ceb900cdS猫头猫                )
42ceb900cdS猫头猫            }
43ceb900cdS猫头猫            onEndReached={() => {
44ceb900cdS猫头猫                query();
45ceb900cdS猫头猫            }}
46ceb900cdS猫头猫            onEndReachedThreshold={0.1}
47ceb900cdS猫头猫            estimatedItemSize={rpx(306)}
482dda6be7S猫头猫            numColumns={orientation === 'vertical' ? 3 : 4}
49ceb900cdS猫头猫            renderItem={renderItem}
50ceb900cdS猫头猫            data={sheets}
51*5500cea7S猫头猫            keyExtractor={keyExtractor}
52ceb900cdS猫头猫        />
53ceb900cdS猫头猫    );
54ceb900cdS猫头猫}
55ceb900cdS猫头猫
56ceb900cdS猫头猫export default memo(
57ceb900cdS猫头猫    SheetList,
58ceb900cdS猫头猫    (prev, curr) =>
59ceb900cdS猫头猫        prev.tag.id === curr.tag.id && prev.pluginHash === curr.pluginHash,
60ceb900cdS猫头猫);
61