Skip to content

Commit

Permalink
Reset Carousel position on data refresh (#303)
Browse files Browse the repository at this point in the history
* Reset Carousel position on data refresh

* add refresh for all carousels
  • Loading branch information
kgarner7 authored Oct 18, 2023
1 parent 03e582f commit fe298d3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
15 changes: 14 additions & 1 deletion src/renderer/components/grid-carousel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { isValidElement, memo, ReactNode, useCallback, useMemo, useRef, useState } from 'react';
import {
isValidElement,
memo,
ReactNode,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { Group, Stack } from '@mantine/core';
import throttle from 'lodash/throttle';
import { RiArrowLeftSLine, RiArrowRightSLine } from 'react-icons/ri';
Expand Down Expand Up @@ -109,6 +118,10 @@ export const SwiperGridCarousel = ({
const playButtonBehavior = usePlayButtonBehavior();
const handlePlayQueueAdd = usePlayQueueAdd();

useEffect(() => {
swiperRef.current?.slideTo(0, 0);
}, [data]);

const [pagination, setPagination] = useState({
hasNextPage: (data?.length || 0) > Math.round(3),
hasPreviousPage: false,
Expand Down
67 changes: 40 additions & 27 deletions src/renderer/features/home/routes/home-route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,39 +103,18 @@ const HomeRoute = () => {
const carousels = [
{
data: random?.data?.items,
title: (
<Group>
<TextTitle
order={2}
weight={700}
>
Explore from your library
</TextTitle>

<ActionIcon
onClick={() =>
queryClient.invalidateQueries({
exact: false,
queryKey: queryKeys.albums.list(server?.id, {
limit: itemsPerPage,
sortBy: AlbumListSort.RANDOM,
sortOrder: SortOrder.ASC,
startIndex: 0,
}),
})
}
>
<RiRefreshLine />
</ActionIcon>
</Group>
),
sortBy: AlbumListSort.RANDOM,
sortOrder: SortOrder.ASC,
title: 'Explore from your library',
uniqueId: 'random',
},
{
data: recentlyPlayed?.data?.items,
pagination: {
itemsPerPage,
},
sortBy: AlbumListSort.RECENTLY_PLAYED,
sortOrder: SortOrder.DESC,
title: 'Recently played',
uniqueId: 'recentlyPlayed',
},
Expand All @@ -144,6 +123,8 @@ const HomeRoute = () => {
pagination: {
itemsPerPage,
},
sortBy: AlbumListSort.RECENTLY_ADDED,
sortOrder: SortOrder.DESC,
title: 'Newly added releases',
uniqueId: 'recentlyAdded',
},
Expand All @@ -152,6 +133,8 @@ const HomeRoute = () => {
pagination: {
itemsPerPage,
},
sortBy: AlbumListSort.PLAY_COUNT,
sortOrder: SortOrder.DESC,
title: 'Most played',
uniqueId: 'mostPlayed',
},
Expand Down Expand Up @@ -220,7 +203,37 @@ const HomeRoute = () => {
route: AppRoute.LIBRARY_ALBUMS_DETAIL,
slugs: [{ idProperty: 'id', slugProperty: 'albumId' }],
}}
title={{ label: carousel.title }}
title={{
label: (
<Group>
<TextTitle
order={2}
weight={700}
>
{carousel.title}
</TextTitle>

<ActionIcon
onClick={() =>
queryClient.invalidateQueries({
exact: false,
queryKey: queryKeys.albums.list(
server?.id,
{
limit: itemsPerPage,
sortBy: carousel.sortBy,
sortOrder: carousel.sortOrder,
startIndex: 0,
},
),
})
}
>
<RiRefreshLine />
</ActionIcon>
</Group>
),
}}
uniqueId={carousel.uniqueId}
/>
))}
Expand Down

1 comment on commit fe298d3

@vercel
Copy link

@vercel vercel bot commented on fe298d3 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

feishin – ./

feishin-git-development-jeffvli.vercel.app
feishin-jeffvli.vercel.app
feishin.vercel.app

Please sign in to comment.