Web:Client:Home: fix tags for table view after resize page

This commit is contained in:
TimofeyBoyko 2022-09-20 14:03:40 +03:00
parent edea9df880
commit 5d863d259b

View File

@ -144,33 +144,39 @@ const Table = ({
}, [sectionWidth]);
React.useEffect(() => {
if (!tagRef?.current) return;
onResize();
const elementResizeDetector = elementResizeDetectorMaker({
strategy: "scroll",
callOnAdd: false,
});
elementResizeDetector.listenTo(tagRef.current, onResize);
return () => {
if (!tagRef?.current) return;
elementResizeDetector.uninstall(tagRef.current);
};
}, [tagRef, filesList]);
}, []);
const onResize = React.useCallback(() => {
if (tagRef?.current) {
const { width } = tagRef.current.getBoundingClientRect();
const onResize = React.useCallback(
(node) => {
const element = tagRef?.current ? tagRef?.current : node;
const columns = Math.floor(width / 100);
if (element) {
const { width } = element.getBoundingClientRect();
if (columns != tagCount) setTagCount(columns);
const columns = Math.floor(width / 100);
if (columns != tagCount) setTagCount(columns);
}
},
[tagCount]
);
const onSetTagRef = React.useCallback((node) => {
if (node) {
onResize(node);
const elementResizeDetector = elementResizeDetectorMaker({
strategy: "scroll",
callOnAdd: false,
});
elementResizeDetector.listenTo(node, onResize);
}
}, [tagRef, tagCount]);
}, []);
const tableColumns = isRooms
? `${TABLE_ROOMS_COLUMNS}=${userId}`
@ -221,7 +227,7 @@ const Table = ({
tableColumns={tableColumns}
columnStorageName={columnStorageName}
columnInfoPanelStorageName={columnInfoPanelStorageName}
tagRef={tagRef}
tagRef={onSetTagRef}
tagCount={tagCount}
isRooms={isRooms}
/>