diff --git a/src/client/components/DynamicVirtualList.tsx b/src/client/components/DynamicVirtualList.tsx index d7b0a4d..4bf87d9 100644 --- a/src/client/components/DynamicVirtualList.tsx +++ b/src/client/components/DynamicVirtualList.tsx @@ -12,6 +12,7 @@ interface VirtualListProps { onFetchNextPage: () => void; estimateSize: number; renderItem: (item: T) => React.ReactElement; + getItemKey?: (index: number) => string | number; renderEmpty?: () => React.ReactElement; } export const DynamicVirtualList: React.FC = React.memo( @@ -22,6 +23,7 @@ export const DynamicVirtualList: React.FC = React.memo( isFetchingNextPage, onFetchNextPage, estimateSize, + getItemKey, renderItem, renderEmpty, } = props; @@ -33,6 +35,7 @@ export const DynamicVirtualList: React.FC = React.memo( getScrollElement: () => parentRef.current, estimateSize: () => estimateSize, overscan: 5, + getItemKey, }); const virtualItems = rowVirtualizer.getVirtualItems(); diff --git a/src/client/routes/feed/$channelId/index.tsx b/src/client/routes/feed/$channelId/index.tsx index ceeb1b2..d416a9c 100644 --- a/src/client/routes/feed/$channelId/index.tsx +++ b/src/client/routes/feed/$channelId/index.tsx @@ -16,6 +16,7 @@ import { DialogWrapper } from '@/components/DialogWrapper'; import { useSocketSubscribeList } from '@/api/socketio'; import { useMemo } from 'react'; import { DynamicVirtualList } from '@/components/DynamicVirtualList'; +import { reverse } from 'lodash-es'; export const Route = createFileRoute('/feed/$channelId/')({ beforeLoad: routeAuthBeforeLoad, @@ -64,7 +65,10 @@ function PageComponent() { }); const fullEvents = useMemo( - () => [...realtimeEvents, ...(data?.pages.flatMap((p) => p.items) ?? [])], + () => [ + ...reverse(realtimeEvents), + ...(data?.pages.flatMap((p) => p.items) ?? []), + ], [realtimeEvents, data] ); @@ -118,7 +122,10 @@ function PageComponent() { hasNextPage={hasNextPage} isFetchingNextPage={isFetchingNextPage} onFetchNextPage={fetchNextPage} - renderItem={(item) => } + getItemKey={(index) => fullEvents[index].id} + renderItem={(item) => ( + + )} renderEmpty={() => (
diff --git a/src/client/tailwind.config.ts b/src/client/tailwind.config.ts index 448f776..aeea1e3 100644 --- a/src/client/tailwind.config.ts +++ b/src/client/tailwind.config.ts @@ -77,10 +77,15 @@ module.exports = { from: { height: 'var(--radix-accordion-content-height)' }, to: { height: '0' }, }, + 'fade-in': { + '0%': { opacity: '0' }, + '100%': { opacity: '1' }, + }, }, animation: { 'accordion-down': 'accordion-down 0.2s ease-out', 'accordion-up': 'accordion-up 0.2s ease-out', + 'fade-in': 'fade-in 0.6s ease-in-out forwards', }, }, },