refactor: add fade in animation
This commit is contained in:
parent
8585ea4196
commit
35a6e20717
@ -12,6 +12,7 @@ interface VirtualListProps<T = any> {
|
|||||||
onFetchNextPage: () => void;
|
onFetchNextPage: () => void;
|
||||||
estimateSize: number;
|
estimateSize: number;
|
||||||
renderItem: (item: T) => React.ReactElement;
|
renderItem: (item: T) => React.ReactElement;
|
||||||
|
getItemKey?: (index: number) => string | number;
|
||||||
renderEmpty?: () => React.ReactElement;
|
renderEmpty?: () => React.ReactElement;
|
||||||
}
|
}
|
||||||
export const DynamicVirtualList: React.FC<VirtualListProps> = React.memo(
|
export const DynamicVirtualList: React.FC<VirtualListProps> = React.memo(
|
||||||
@ -22,6 +23,7 @@ export const DynamicVirtualList: React.FC<VirtualListProps> = React.memo(
|
|||||||
isFetchingNextPage,
|
isFetchingNextPage,
|
||||||
onFetchNextPage,
|
onFetchNextPage,
|
||||||
estimateSize,
|
estimateSize,
|
||||||
|
getItemKey,
|
||||||
renderItem,
|
renderItem,
|
||||||
renderEmpty,
|
renderEmpty,
|
||||||
} = props;
|
} = props;
|
||||||
@ -33,6 +35,7 @@ export const DynamicVirtualList: React.FC<VirtualListProps> = React.memo(
|
|||||||
getScrollElement: () => parentRef.current,
|
getScrollElement: () => parentRef.current,
|
||||||
estimateSize: () => estimateSize,
|
estimateSize: () => estimateSize,
|
||||||
overscan: 5,
|
overscan: 5,
|
||||||
|
getItemKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
const virtualItems = rowVirtualizer.getVirtualItems();
|
const virtualItems = rowVirtualizer.getVirtualItems();
|
||||||
|
@ -16,6 +16,7 @@ import { DialogWrapper } from '@/components/DialogWrapper';
|
|||||||
import { useSocketSubscribeList } from '@/api/socketio';
|
import { useSocketSubscribeList } from '@/api/socketio';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { DynamicVirtualList } from '@/components/DynamicVirtualList';
|
import { DynamicVirtualList } from '@/components/DynamicVirtualList';
|
||||||
|
import { reverse } from 'lodash-es';
|
||||||
|
|
||||||
export const Route = createFileRoute('/feed/$channelId/')({
|
export const Route = createFileRoute('/feed/$channelId/')({
|
||||||
beforeLoad: routeAuthBeforeLoad,
|
beforeLoad: routeAuthBeforeLoad,
|
||||||
@ -64,7 +65,10 @@ function PageComponent() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const fullEvents = useMemo(
|
const fullEvents = useMemo(
|
||||||
() => [...realtimeEvents, ...(data?.pages.flatMap((p) => p.items) ?? [])],
|
() => [
|
||||||
|
...reverse(realtimeEvents),
|
||||||
|
...(data?.pages.flatMap((p) => p.items) ?? []),
|
||||||
|
],
|
||||||
[realtimeEvents, data]
|
[realtimeEvents, data]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -118,7 +122,10 @@ function PageComponent() {
|
|||||||
hasNextPage={hasNextPage}
|
hasNextPage={hasNextPage}
|
||||||
isFetchingNextPage={isFetchingNextPage}
|
isFetchingNextPage={isFetchingNextPage}
|
||||||
onFetchNextPage={fetchNextPage}
|
onFetchNextPage={fetchNextPage}
|
||||||
renderItem={(item) => <FeedEventItem className="mb-2" event={item} />}
|
getItemKey={(index) => fullEvents[index].id}
|
||||||
|
renderItem={(item) => (
|
||||||
|
<FeedEventItem className="animate-fade-in mb-2" event={item} />
|
||||||
|
)}
|
||||||
renderEmpty={() => (
|
renderEmpty={() => (
|
||||||
<div className="w-full overflow-hidden p-4">
|
<div className="w-full overflow-hidden p-4">
|
||||||
<FeedApiGuide channelId={channelId} />
|
<FeedApiGuide channelId={channelId} />
|
||||||
|
@ -77,10 +77,15 @@ module.exports = {
|
|||||||
from: { height: 'var(--radix-accordion-content-height)' },
|
from: { height: 'var(--radix-accordion-content-height)' },
|
||||||
to: { height: '0' },
|
to: { height: '0' },
|
||||||
},
|
},
|
||||||
|
'fade-in': {
|
||||||
|
'0%': { opacity: '0' },
|
||||||
|
'100%': { opacity: '1' },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
animation: {
|
animation: {
|
||||||
'accordion-down': 'accordion-down 0.2s ease-out',
|
'accordion-down': 'accordion-down 0.2s ease-out',
|
||||||
'accordion-up': 'accordion-up 0.2s ease-out',
|
'accordion-up': 'accordion-up 0.2s ease-out',
|
||||||
|
'fade-in': 'fade-in 0.6s ease-in-out forwards',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user