cboard icon indicating copy to clipboard operation
cboard copied to clipboard

Fix FixedGrid `chunks` function to separate the tiles depending on order

Open tomivm opened this issue 7 months ago • 1 comments

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

tomivm avatar May 27 '25 12:05 tomivm

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.

tomivm avatar May 29 '25 22:05 tomivm