Fix bug with Feed Carousel
This commit is contained in:
parent
189423b415
commit
0a4d113d50
1 changed files with 11 additions and 3 deletions
|
@ -98,13 +98,21 @@ const FeedCarousel = () => {
|
||||||
const [pinnedAvatar, setPinnedAvatar] = useState<Avatar | null>(null);
|
const [pinnedAvatar, setPinnedAvatar] = useState<Avatar | null>(null);
|
||||||
|
|
||||||
const avatarsToList = useMemo(() => {
|
const avatarsToList = useMemo(() => {
|
||||||
const list = avatars.filter((avatar) => avatar.account_id !== pinnedAvatar?.account_id);
|
let list: (Avatar | null)[] = avatars.filter((avatar) => avatar.account_id !== pinnedAvatar?.account_id);
|
||||||
|
|
||||||
|
// If we have an Avatar pinned, let's create a new array with "null"
|
||||||
|
// in the first position of each page.
|
||||||
if (pinnedAvatar) {
|
if (pinnedAvatar) {
|
||||||
return [null, ...list];
|
const index = (currentPage - 1) * pageSize;
|
||||||
|
list = [
|
||||||
|
...list.slice(0, index),
|
||||||
|
null,
|
||||||
|
...list.slice(index),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}, [avatars, pinnedAvatar]);
|
}, [avatars, pinnedAvatar, currentPage, pageSize]);
|
||||||
|
|
||||||
const numberOfPages = Math.ceil(avatars.length / pageSize);
|
const numberOfPages = Math.ceil(avatars.length / pageSize);
|
||||||
const widthPerAvatar = width / (Math.floor(width / 80));
|
const widthPerAvatar = width / (Math.floor(width / 80));
|
||||||
|
|
Loading…
Reference in a new issue