BC-12 feat: store accounts table columns resizing to local storage.

This commit is contained in:
a.bouhuolia
2021-09-08 15:58:29 +02:00
parent 97c3fd9e0c
commit 7b3d310eab
5 changed files with 99 additions and 16 deletions

View File

@@ -1,3 +1,5 @@
import { React } from 'react';
export const isCellLoading = (loading, cellsCoords, rowIndex, columnId) => {
if (!loading) {
return false;
@@ -8,3 +10,26 @@ export const isCellLoading = (loading, cellsCoords, rowIndex, columnId) => {
(cellCoord) => cellCoord[0] === rowIndex && cellCoord[1] === columnId,
);
};
export const useResizeObserver = (state, callback) => {
// This Ref will contain the id of the column being resized or undefined
const columnResizeRef = React.useRef();
React.useEffect(() => {
// We are interested in calling the resize event only when "state.columnResizing?.isResizingColumn" changes from
// a string to undefined, because it indicates that it WAS resizing but it no longer is.
if (
state.columnResizing &&
!state.columnResizing?.isResizingColumn &&
columnResizeRef.current
) {
// Trigger resize event
callback(
columnResizeRef.current,
state.columnResizing.columnWidths[columnResizeRef.current],
state.columnResizing,
);
}
columnResizeRef.current = state.columnResizing?.isResizingColumn;
}, [callback, state.columnResizing]);
};