cboard
cboard copied to clipboard
Fix FixedGrid `chunks` function to separate the tiles depending on order
Now the function is separating the latest tiles of the items using the itemsPerPages, but we need to separate by the order.
example: If we remove the last row, we should separate the elements that aren't in the new order.
https://github.com/cboard-org/cboard/blob/b8a35540099224609fe8109ec02052573b5005ab/src/components/FixedGrid/Grid.js#L8
Idealy We should implement. this function
export function chunks({ tileItems, order }:{
tileItems: Array<TileItem>;
order: GridOrder;
}) {
const firstPageItemsInOrder = order.map(row =>
row.map(id => tileItems.find(item => item.id === id))
);
const firstPage = lodash.flatten(firstPageItemsInOrder);
const size = firstPage.length;
const restOfItems = tileItems.filter(
item => !firstPage.find(firstItem => firstItem?.id === item.id)
);
const restOfPages = lodash.chunk(restOfItems, size);
return [firstPage, ...restOfPages];
}
But this causes differences between how the users see his boards now and with this function. For that I refactorized it to have a better chunk in pages but preserve the functionability of fill the board with remaining tiles.