Skip to content

Commit 962e7ce

Browse files
committed
refactor: code cleanup
1 parent 4b26164 commit 962e7ce

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

packages/pluggableWidgets/gallery-web/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
### Fixed
1010

11-
- We fixed an issue where the configured column count wouldn't show up in the preview of the widget
11+
- We fixed an issue where the column count was not reflected properly in the preview mode.
1212

1313
### Added
1414

packages/pluggableWidgets/gallery-web/src/features/useGridPositionsPreview.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type GridPositionReturn = {
1212
numberOfItems: number;
1313
};
1414

15-
function useNumberOfRows(): [React.RefObject<HTMLDivElement>, number] {
15+
function useObservedColumns(): [React.RefObject<HTMLDivElement>, number] {
1616
const containerRef = useRef<HTMLDivElement>(null);
1717
const [numberOfColumns, setNumberOfColumns] = useState(12);
1818

@@ -31,8 +31,6 @@ function useNumberOfRows(): [React.RefObject<HTMLDivElement>, number] {
3131

3232
resizeObserver.observe(containerRef.current);
3333

34-
setNumberOfColumns(containerRef.current.offsetWidth);
35-
3634
return () => resizeObserver.disconnect();
3735
}, []);
3836

@@ -42,7 +40,7 @@ function useNumberOfRows(): [React.RefObject<HTMLDivElement>, number] {
4240
export function useGridPositionsPreview(
4341
config: GridPositionsProps
4442
): GridPositionReturn & { containerRef: React.RefObject<HTMLDivElement> } {
45-
const [containerRef, numberOfColumns] = useNumberOfRows();
43+
const [containerRef, numberOfColumns] = useObservedColumns();
4644
const maxItems = numberOfColumns * 3;
4745
const numberOfItems = Math.min(maxItems, config.totalItems);
4846
const numberOfRows = Math.ceil(numberOfItems / numberOfColumns);

0 commit comments

Comments
 (0)